@@ -57,6 +57,13 @@ const mockBitcoinNetwork = {
5757 chainNamespace : ConstantsUtil . CHAIN . BITCOIN
5858} as unknown as CaipNetwork
5959
60+ const mockTonNetwork = {
61+ id : 'ton:-239' ,
62+ name : 'TON' ,
63+ namespace : ConstantsUtil . CHAIN . TON ,
64+ chainNamespace : ConstantsUtil . CHAIN . TON
65+ } as unknown as CaipNetwork
66+
6067const mockMetaMaskConnector = {
6168 id : 'metamask' ,
6269 name : 'MetaMask' ,
@@ -260,6 +267,115 @@ describe('W3mProfileWalletsView - Tabs Rendering', () => {
260267 expect ( tabs ) . not . toBeNull ( )
261268 } )
262269
270+ it ( 'should respect user-configured network order: A Order' , async ( ) => {
271+ vi . spyOn ( ChainController , 'state' , 'get' ) . mockReturnValue ( {
272+ activeChain : ConstantsUtil . CHAIN . TON ,
273+ activeCaipNetwork : mockTonNetwork ,
274+ chains : new Map ( [
275+ [
276+ ConstantsUtil . CHAIN . TON ,
277+ { namespace : ConstantsUtil . CHAIN . TON , caipNetworks : [ mockTonNetwork ] }
278+ ] ,
279+ [
280+ ConstantsUtil . CHAIN . SOLANA ,
281+ { namespace : ConstantsUtil . CHAIN . SOLANA , caipNetworks : [ mockSolanaNetwork ] }
282+ ] ,
283+ [
284+ ConstantsUtil . CHAIN . EVM ,
285+ { namespace : ConstantsUtil . CHAIN . EVM , caipNetworks : [ mockEthereumNetwork ] }
286+ ]
287+ ] )
288+ } as unknown as ChainControllerState )
289+
290+ vi . spyOn ( ConnectorController , 'state' , 'get' ) . mockReturnValue ( {
291+ ...ConnectorController . state ,
292+ activeConnectorIds : {
293+ ton : 'ton-wallet'
294+ } as unknown as Record < ChainNamespace , string | undefined > ,
295+ connectors : [ ]
296+ } )
297+
298+ vi . spyOn ( ChainController , 'getAccountData' ) . mockReturnValue ( undefined )
299+ vi . spyOn ( ConnectionControllerUtil , 'getConnectionsData' ) . mockReturnValue ( {
300+ connections : [ ] ,
301+ recentConnections : [ ]
302+ } )
303+
304+ const element : W3mProfileWalletsView = await fixture (
305+ html `< w3m-profile-wallets-view > </ w3m-profile-wallets-view > `
306+ )
307+
308+ const tabs = element . shadowRoot ?. querySelector ( TABS_COMPONENT ) as any
309+ expect ( tabs ) . not . toBeNull ( )
310+
311+ const tabsArray = tabs . tabs
312+ expect ( tabsArray ) . toBeDefined ( )
313+ expect ( tabsArray . length ) . toBe ( 3 )
314+
315+ expect ( tabsArray [ 0 ] . namespace ) . toBe ( 'ton' )
316+ expect ( tabsArray [ 1 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . SOLANA )
317+ expect ( tabsArray [ 2 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . EVM )
318+ } )
319+
320+ /**
321+ * We use two test cases with two different orders
322+ * in case the order of the hardcoded value in the tabs array changes.
323+ */
324+ it ( 'should respect user-configured network order: B Order' , async ( ) => {
325+ vi . spyOn ( ChainController , 'state' , 'get' ) . mockReturnValue ( {
326+ activeChain : ConstantsUtil . CHAIN . BITCOIN ,
327+ activeCaipNetwork : mockBitcoinNetwork ,
328+ chains : new Map ( [
329+ [
330+ ConstantsUtil . CHAIN . BITCOIN ,
331+ { namespace : ConstantsUtil . CHAIN . BITCOIN , caipNetworks : [ mockBitcoinNetwork ] }
332+ ] ,
333+ [
334+ ConstantsUtil . CHAIN . SOLANA ,
335+ { namespace : ConstantsUtil . CHAIN . SOLANA , caipNetworks : [ mockSolanaNetwork ] }
336+ ] ,
337+ [
338+ ConstantsUtil . CHAIN . EVM ,
339+ { namespace : ConstantsUtil . CHAIN . EVM , caipNetworks : [ mockEthereumNetwork ] }
340+ ] ,
341+ [
342+ ConstantsUtil . CHAIN . TON ,
343+ { namespace : ConstantsUtil . CHAIN . TON , caipNetworks : [ mockTonNetwork ] }
344+ ]
345+ ] )
346+ } as unknown as ChainControllerState )
347+
348+ vi . spyOn ( ConnectorController , 'state' , 'get' ) . mockReturnValue ( {
349+ ...ConnectorController . state ,
350+ activeConnectorIds : {
351+ bip122 : 'bitcoin-wallet'
352+ } as unknown as Record < ChainNamespace , string | undefined > ,
353+ connectors : [ ]
354+ } )
355+
356+ vi . spyOn ( ChainController , 'getAccountData' ) . mockReturnValue ( undefined )
357+ vi . spyOn ( ConnectionControllerUtil , 'getConnectionsData' ) . mockReturnValue ( {
358+ connections : [ ] ,
359+ recentConnections : [ ]
360+ } )
361+
362+ const element : W3mProfileWalletsView = await fixture (
363+ html `< w3m-profile-wallets-view > </ w3m-profile-wallets-view > `
364+ )
365+
366+ const tabs = element . shadowRoot ?. querySelector ( TABS_COMPONENT ) as any
367+ expect ( tabs ) . not . toBeNull ( )
368+
369+ const tabsArray = tabs . tabs
370+ expect ( tabsArray ) . toBeDefined ( )
371+ expect ( tabsArray . length ) . toBe ( 4 )
372+ // Tabs should render in user's configured order: Bitcoin, Solana, EVM, TON
373+ expect ( tabsArray [ 0 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . BITCOIN )
374+ expect ( tabsArray [ 1 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . SOLANA )
375+ expect ( tabsArray [ 2 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . EVM )
376+ expect ( tabsArray [ 3 ] . namespace ) . toBe ( ConstantsUtil . CHAIN . TON )
377+ } )
378+
263379 it ( 'should not render tabs when only one namespace is available' , async ( ) => {
264380 vi . spyOn ( ChainController , 'state' , 'get' ) . mockReturnValue ( {
265381 activeChain : ConstantsUtil . CHAIN . EVM ,
0 commit comments