@@ -2,18 +2,46 @@ import { AddressResolution } from '@metamask/snaps-sdk';
22
33import mockState from '../../../../../test/data/mock-state.json' ;
44import { renderHookWithProvider } from '../../../../../test/lib/render-helpers' ;
5+ import { lookupDomainName } from '../../../../ducks/domains' ;
56// eslint-disable-next-line import/no-namespace
67import * as SnapNameResolution from '../../../../hooks/snaps/useSnapNameResolution' ;
78// eslint-disable-next-line import/no-namespace
89import * as SendValidationUtils from '../../utils/sendValidations' ;
910import { useNameValidation } from './useNameValidation' ;
11+ import { useSendType } from './useSendType' ;
12+
13+ jest . mock ( 'react-redux' , ( ) => ( {
14+ ...jest . requireActual ( 'react-redux' ) ,
15+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16+ useDispatch : jest . fn ( ) . mockReturnValue ( ( callback : any ) => callback ?.( ) ) ,
17+ } ) ) ;
1018
1119jest . mock ( '@metamask/bridge-controller' , ( ) => ( {
1220 ...jest . requireActual ( '@metamask/bridge-controller' ) ,
1321 formatChainIdToCaip : jest . fn ( ) ,
1422} ) ) ;
1523
24+ jest . mock ( '../../../../ducks/domains' , ( ) => ( {
25+ lookupDomainName : jest . fn ( ) ,
26+ } ) ) ;
27+
28+ jest . mock ( './useSendType' , ( ) => ( {
29+ useSendType : jest . fn ( ) . mockReturnValue ( {
30+ isEvmSendType : false ,
31+ } ) ,
32+ } ) ) ;
33+
1634describe ( 'useNameValidation' , ( ) => {
35+ const lookupDomainNameMock = jest . mocked ( lookupDomainName ) ;
36+ const useSendTypeMock = jest . mocked ( useSendType ) ;
37+
38+ beforeEach ( ( ) => {
39+ jest . clearAllMocks ( ) ;
40+ useSendTypeMock . mockReturnValue ( {
41+ isEvmSendType : false ,
42+ } as unknown as ReturnType < typeof useSendType > ) ;
43+ } ) ;
44+
1745 it ( 'return function to validate name' , ( ) => {
1846 const { result } = renderHookWithProvider (
1947 ( ) => useNameValidation ( ) ,
@@ -47,6 +75,38 @@ describe('useNameValidation', () => {
4775 } ) ;
4876 } ) ;
4977
78+ it ( 'dispatch lookupDomainName when name is resolved' , async ( ) => {
79+ useSendTypeMock . mockReturnValue ( {
80+ isEvmSendType : true ,
81+ } as unknown as ReturnType < typeof useSendType > ) ;
82+ jest . spyOn ( SnapNameResolution , 'useSnapNameResolution' ) . mockReturnValue ( {
83+ fetchResolutions : ( ) =>
84+ Promise . resolve ( [
85+ {
86+ resolvedAddress : 'dummy_address' ,
87+ protocol : 'dummy_protocol' ,
88+ } as unknown as AddressResolution ,
89+ ] ) ,
90+ } ) ;
91+ const { result } = renderHookWithProvider (
92+ ( ) => useNameValidation ( ) ,
93+ mockState ,
94+ ) ;
95+ expect (
96+ await result . current . validateName (
97+ '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' ,
98+ 'test.eth' ,
99+ ) ,
100+ ) . toStrictEqual ( {
101+ protocol : 'dummy_protocol' ,
102+ resolvedLookup : 'dummy_address' ,
103+ } ) ;
104+ expect ( lookupDomainNameMock ) . toHaveBeenCalledWith (
105+ 'test.eth' ,
106+ '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' ,
107+ ) ;
108+ } ) ;
109+
50110 it ( 'return confusable error and warning as name is resolved' , async ( ) => {
51111 jest
52112 . spyOn ( SendValidationUtils , 'findConfusablesInRecipient' )
0 commit comments