|
| 1 | +import { passphraseToAppNetwork } from '@/config/networkManifest' |
| 2 | +import { |
| 3 | + computeNetworkMismatch, |
| 4 | + isReadOnlyWalletInteractionPath, |
| 5 | + stripLocalePrefix, |
| 6 | +} from '@/features/wallet/utils/networkMismatch' |
| 7 | + |
| 8 | +describe('stripLocalePrefix', () => { |
| 9 | + it('removes optional locale segment', () => { |
| 10 | + expect(stripLocalePrefix('/es/quote')).toBe('/quote') |
| 11 | + expect(stripLocalePrefix('/en/docs/voting')).toBe('/docs/voting') |
| 12 | + expect(stripLocalePrefix('/es')).toBe('/') |
| 13 | + }) |
| 14 | + |
| 15 | + it('leaves default-locale paths unchanged', () => { |
| 16 | + expect(stripLocalePrefix('/quote')).toBe('/quote') |
| 17 | + expect(stripLocalePrefix('/')).toBe('/') |
| 18 | + }) |
| 19 | +}) |
| 20 | + |
| 21 | +describe('isReadOnlyWalletInteractionPath', () => { |
| 22 | + it('treats landing, docs, privacy, support as read-only', () => { |
| 23 | + expect(isReadOnlyWalletInteractionPath('/')).toBe(true) |
| 24 | + expect(isReadOnlyWalletInteractionPath('/docs')).toBe(true) |
| 25 | + expect(isReadOnlyWalletInteractionPath('/docs/voting')).toBe(true) |
| 26 | + expect(isReadOnlyWalletInteractionPath('/privacy')).toBe(true) |
| 27 | + expect(isReadOnlyWalletInteractionPath('/support')).toBe(true) |
| 28 | + }) |
| 29 | + |
| 30 | + it('treats wallet-interaction routes as not read-only', () => { |
| 31 | + expect(isReadOnlyWalletInteractionPath('/quote')).toBe(false) |
| 32 | + expect(isReadOnlyWalletInteractionPath('/settings')).toBe(false) |
| 33 | + expect(isReadOnlyWalletInteractionPath('/dashboard')).toBe(false) |
| 34 | + }) |
| 35 | + |
| 36 | + it('respects locale prefix', () => { |
| 37 | + expect(isReadOnlyWalletInteractionPath('/es')).toBe(true) |
| 38 | + expect(isReadOnlyWalletInteractionPath('/es/docs/contracts')).toBe(true) |
| 39 | + expect(isReadOnlyWalletInteractionPath('/es/quote')).toBe(false) |
| 40 | + }) |
| 41 | +}) |
| 42 | + |
| 43 | +describe('computeNetworkMismatch', () => { |
| 44 | + it('is false when disconnected or resolution not ok', () => { |
| 45 | + expect( |
| 46 | + computeNetworkMismatch('disconnected', 'mainnet', { status: 'ok', mappedNetwork: 'testnet' }), |
| 47 | + ).toBe(false) |
| 48 | + expect( |
| 49 | + computeNetworkMismatch('connected', 'mainnet', { status: 'idle' }), |
| 50 | + ).toBe(false) |
| 51 | + expect( |
| 52 | + computeNetworkMismatch('connected', 'mainnet', { status: 'error' }), |
| 53 | + ).toBe(false) |
| 54 | + }) |
| 55 | + |
| 56 | + it('is true when mapped network differs from app network', () => { |
| 57 | + expect( |
| 58 | + computeNetworkMismatch('connected', 'mainnet', { status: 'ok', mappedNetwork: 'testnet' }), |
| 59 | + ).toBe(true) |
| 60 | + }) |
| 61 | + |
| 62 | + it('is false when networks match', () => { |
| 63 | + expect( |
| 64 | + computeNetworkMismatch('connected', 'testnet', { status: 'ok', mappedNetwork: 'testnet' }), |
| 65 | + ).toBe(false) |
| 66 | + }) |
| 67 | + |
| 68 | + it('is true when passphrase is unknown (unmapped)', () => { |
| 69 | + expect( |
| 70 | + computeNetworkMismatch('connected', 'mainnet', { status: 'ok', mappedNetwork: null }), |
| 71 | + ).toBe(true) |
| 72 | + }) |
| 73 | +}) |
| 74 | + |
| 75 | +describe('passphraseToAppNetwork', () => { |
| 76 | + it('maps known Stellar passphrases', () => { |
| 77 | + expect(passphraseToAppNetwork('Test SDF Network ; September 2015')).toBe('testnet') |
| 78 | + expect( |
| 79 | + passphraseToAppNetwork('Public Global Stellar Network ; September 2015'), |
| 80 | + ).toBe('mainnet') |
| 81 | + }) |
| 82 | + |
| 83 | + it('returns null for unknown passphrases', () => { |
| 84 | + expect(passphraseToAppNetwork('Private Custom Network')).toBeNull() |
| 85 | + }) |
| 86 | +}) |
0 commit comments