@@ -10,12 +10,14 @@ import {
1010 useAccountProps ,
1111 useNotificationAccountListProps ,
1212 useNotificationWalletAccountGroups ,
13+ useWalletActivityAccountSelection ,
1314} from './AccountsList.hooks' ;
1415import { selectInternalAccountsById } from '../../../../selectors/accountsController' ;
1516import { InternalAccount } from '@metamask/keyring-internal-api' ;
1617import { selectAccountGroupsByWallet } from '../../../../selectors/multichainAccounts/accountTreeController' ;
1718import { AccountGroupType , AccountWalletType } from '@metamask/account-api' ;
1819import { KeyringTypes } from '@metamask/keyring-controller' ;
20+ import { toFormattedAddress } from '../../../../util/address' ;
1921
2022jest . mock ( '../../../../selectors/notifications' , ( ) => ( {
2123 getValidNotificationAccounts : jest . fn ( ) ,
@@ -35,6 +37,15 @@ jest.mock(
3537) ;
3638
3739const MOCK_KEYRING_TYPE = 'HD Key Tree' as KeyringTypes ;
40+ const EVM_ADDRESSES = [
41+ '0xb2B92547A92C1aC55EAe3F6632Fa1aF87dc05a29' ,
42+ '0x700CcD8172BC3807D893883a730A1E0E6630F8EC' ,
43+ '0xb2B92547A92C1aC55EAe3F6632Fa1aF87dc05a20' ,
44+ '0x700CcD8172BC3807D893883a730A1E0E6630F8E0' ,
45+ ] ;
46+ const FORMATTED_EVM_ADDRESSES = EVM_ADDRESSES . map ( ( address ) =>
47+ toFormattedAddress ( address ) ,
48+ ) ;
3849
3950const createNotificationAccountsMap = ( ) =>
4051 ( {
@@ -431,3 +442,77 @@ describe('useAccountProps', () => {
431442 ) ;
432443 } ) ;
433444} ) ;
445+
446+ describe ( 'useWalletActivityAccountSelection' , ( ) => {
447+ const arrangeMocks = ( notificationData : Record < string , boolean > ) => {
448+ arrangeMockUseAccounts ( ) ;
449+ jest
450+ . mocked ( selectInternalAccountsById )
451+ . mockReturnValue ( createNotificationAccountsMap ( ) ) ;
452+ jest . mocked ( getValidNotificationAccounts ) . mockReturnValue ( EVM_ADDRESSES ) ;
453+
454+ const mockUpdate = jest . fn ( ) ;
455+ jest
456+ . spyOn ( UseSwitchNotificationsModule , 'useFetchAccountNotifications' )
457+ . mockReturnValue ( {
458+ accountsBeingUpdated : [ ] ,
459+ data : notificationData ,
460+ error : null ,
461+ initialLoading : false ,
462+ update : mockUpdate ,
463+ } ) ;
464+
465+ const mockOnToggle = jest . fn ( ) ;
466+ jest
467+ . spyOn ( UseSwitchNotificationsModule , 'useAccountNotificationsToggle' )
468+ . mockReturnValue ( {
469+ onToggle : mockOnToggle ,
470+ error : null ,
471+ loading : false ,
472+ } ) ;
473+
474+ return {
475+ mockOnToggle,
476+ mockUpdate,
477+ } ;
478+ } ;
479+
480+ beforeEach ( ( ) => jest . clearAllMocks ( ) ) ;
481+
482+ it ( 'deselects all visible EVM accounts when any account is enabled' , async ( ) => {
483+ const mocks = arrangeMocks ( {
484+ [ FORMATTED_EVM_ADDRESSES [ 0 ] ] : true ,
485+ } ) ;
486+
487+ const { result } = renderHookWithProvider ( ( ) =>
488+ useWalletActivityAccountSelection ( ) ,
489+ ) ;
490+
491+ expect ( result . current . hasEnabledAccount ) . toBe ( true ) ;
492+
493+ await act ( async ( ) => result . current . toggleAllAccounts ( ) ) ;
494+
495+ expect ( mocks . mockOnToggle ) . toHaveBeenCalledWith (
496+ FORMATTED_EVM_ADDRESSES ,
497+ false ,
498+ ) ;
499+ expect ( mocks . mockUpdate ) . toHaveBeenCalledWith ( EVM_ADDRESSES ) ;
500+ } ) ;
501+
502+ it ( 'selects all visible EVM accounts when every account is disabled' , async ( ) => {
503+ const mocks = arrangeMocks ( { } ) ;
504+
505+ const { result } = renderHookWithProvider ( ( ) =>
506+ useWalletActivityAccountSelection ( ) ,
507+ ) ;
508+
509+ expect ( result . current . hasEnabledAccount ) . toBe ( false ) ;
510+
511+ await act ( async ( ) => result . current . toggleAllAccounts ( ) ) ;
512+
513+ expect ( mocks . mockOnToggle ) . toHaveBeenCalledWith (
514+ FORMATTED_EVM_ADDRESSES ,
515+ true ,
516+ ) ;
517+ } ) ;
518+ } ) ;
0 commit comments