@@ -11,13 +11,15 @@ import {
1111 ConnectionController ,
1212 CoreHelperUtil ,
1313 ModalController ,
14+ type RemoteFeatures ,
1415 SendController ,
1516 WcHelpersUtil
1617} from '@reown/appkit-controllers'
1718import { mockChainControllerState } from '@reown/appkit-controllers/testing'
1819import { ErrorUtil , TokenUtil } from '@reown/appkit-utils'
1920
2021import { AppKitBaseClient } from '../../src/client/appkit-base-client'
22+ import { ConfigUtil } from '../../src/utils/ConfigUtil'
2123import { mainnet } from '../mocks/Networks'
2224
2325describe ( 'AppKitBaseClient.checkAllowedOrigins' , ( ) => {
@@ -538,3 +540,106 @@ describe('AppKitBaseClient.getDisabledCaipNetworks', () => {
538540 expect ( result [ 0 ] ?. caipNetworkId ) . toBe ( 'eip155:56' )
539541 } )
540542} )
543+
544+ describe ( 'AppKitBaseClient initialization' , ( ) => {
545+ let fetchRemoteFeaturesSpy : MockInstance
546+
547+ beforeAll ( ( ) => {
548+ Object . defineProperty ( globalThis , 'document' , {
549+ value : {
550+ getElementsByTagName : vi . fn ( ) ,
551+ querySelector : vi . fn ( )
552+ } ,
553+ writable : true
554+ } )
555+
556+ Object . defineProperty ( globalThis , 'navigator' , {
557+ value : {
558+ clipboard : {
559+ readText : vi . fn ( ( ) => Promise . resolve ( '' ) )
560+ }
561+ } ,
562+ writable : true
563+ } )
564+
565+ Object . defineProperty ( globalThis , 'window' , {
566+ value : { location : { origin : '' } } ,
567+ writable : true
568+ } )
569+ } )
570+
571+ beforeEach ( ( ) => {
572+ vi . clearAllMocks ( )
573+ fetchRemoteFeaturesSpy = vi
574+ . spyOn ( ConfigUtil , 'fetchRemoteFeatures' )
575+ . mockResolvedValue ( { } as RemoteFeatures )
576+ } )
577+
578+ it ( 'should not fetch remote config if using basic mode' , async ( ) => {
579+ new ( class extends AppKitBaseClient {
580+ constructor ( ) {
581+ super ( {
582+ projectId : 'test-project-id' ,
583+ networks : [ mainnet ] ,
584+ adapters : [ ] ,
585+ sdkVersion : 'html-wagmi-1' ,
586+ basic : true
587+ } )
588+ }
589+
590+ async injectModalUi ( ) { }
591+ async syncIdentity ( ) { }
592+
593+ override async syncAdapterConnections ( ) {
594+ return Promise . resolve ( )
595+ }
596+ } ) ( )
597+
598+ await vi . waitFor ( ( ) => expect ( fetchRemoteFeaturesSpy ) . not . toHaveBeenCalled ( ) )
599+ } )
600+
601+ it ( 'should not fetch remote config if using manual WC control' , async ( ) => {
602+ new ( class extends AppKitBaseClient {
603+ constructor ( ) {
604+ super ( {
605+ projectId : 'test-project-id' ,
606+ networks : [ mainnet ] ,
607+ adapters : [ ] ,
608+ sdkVersion : 'html-wagmi-1' ,
609+ manualWCControl : true
610+ } )
611+ }
612+
613+ async injectModalUi ( ) { }
614+ async syncIdentity ( ) { }
615+
616+ override async syncAdapterConnections ( ) {
617+ return Promise . resolve ( )
618+ }
619+ } ) ( )
620+
621+ await vi . waitFor ( ( ) => expect ( fetchRemoteFeaturesSpy ) . not . toHaveBeenCalled ( ) )
622+ } )
623+
624+ it ( 'should fetch remote config if not using basic or manual WC control' , async ( ) => {
625+ new ( class extends AppKitBaseClient {
626+ constructor ( ) {
627+ super ( {
628+ projectId : 'test-project-id' ,
629+ networks : [ mainnet ] ,
630+ adapters : [ ] ,
631+ sdkVersion : 'html-wagmi-1'
632+ } )
633+ }
634+
635+ async injectModalUi ( ) { }
636+ async syncIdentity ( ) { }
637+
638+ override async syncAdapterConnections ( ) {
639+ return Promise . resolve ( )
640+ }
641+ } ) ( )
642+
643+ await vi . waitFor ( ( ) => expect ( fetchRemoteFeaturesSpy ) . toHaveBeenCalled ( ) )
644+ } )
645+ } )
0 commit comments