-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baf26f6
commit 254bebd
Showing
7 changed files
with
220 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 0 additions & 128 deletions
128
packages/dapp-kit-react/src/hooks/useVechainDomain/useVechainDomain.test.ts
This file was deleted.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
packages/dapp-kit-react/src/hooks/useVechainDomain/useVechainDomain.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { useVechainDomain } from './useVechainDomain'; | ||
import { wrapper } from '../../../test'; | ||
|
||
vi.mock('./api/getDomain', () => ({ | ||
getDomain: vi.fn().mockImplementation(({ address }) => { | ||
if (address === '0x1234567890123456789012345678901234567890') { | ||
return Promise.resolve('test.vet'); | ||
} | ||
if (address === '0xERROR') { | ||
return Promise.reject(new Error('Network error')); | ||
} | ||
if (address === '0x0000000000000000000000000000000000000000') { | ||
return Promise.reject(new Error('Network error')); | ||
} | ||
return Promise.resolve(null); | ||
}), | ||
})); | ||
|
||
vi.mock('./api/getAddress', () => ({ | ||
getAddress: vi.fn().mockImplementation(({ domain }) => { | ||
if (domain === 'test.vet') { | ||
return Promise.resolve( | ||
'0x1234567890123456789012345678901234567890', | ||
); | ||
} | ||
if (domain === 'invalid.vet') { | ||
return Promise.resolve( | ||
'0x0000000000000000000000000000000000000000', | ||
); | ||
} | ||
if (domain === 'error.vet' || domain === '0xERROR') { | ||
return Promise.reject(new Error('Network error')); | ||
} | ||
return Promise.resolve(null); | ||
}), | ||
})); | ||
|
||
describe('useVechainDomain', () => { | ||
it('should return initial state', () => { | ||
const { result } = renderHook( | ||
() => useVechainDomain({ addressOrDomain: null }), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
address: undefined, | ||
domain: undefined, | ||
isLoading: false, | ||
isValidAddressOrDomain: false, | ||
}); | ||
}); | ||
|
||
it('should handle valid address input', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useVechainDomain({ | ||
addressOrDomain: | ||
'0x1234567890123456789012345678901234567890', | ||
}), | ||
{ wrapper }, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: '0x1234567890123456789012345678901234567890', | ||
domain: 'test.vet', | ||
isLoading: false, | ||
isValidAddressOrDomain: true, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should handle valid domain input', async () => { | ||
const { result } = renderHook( | ||
() => useVechainDomain({ addressOrDomain: 'test.vet' }), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: '0x1234567890123456789012345678901234567890', | ||
domain: 'test.vet', | ||
isLoading: false, | ||
isValidAddressOrDomain: true, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should handle invalid domain input', async () => { | ||
const { result } = renderHook( | ||
() => useVechainDomain({ addressOrDomain: 'invalid.vet' }), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: undefined, | ||
domain: undefined, | ||
isLoading: false, | ||
isValidAddressOrDomain: false, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should handle error when getting domain', async () => { | ||
const { result } = renderHook( | ||
() => useVechainDomain({ addressOrDomain: '0xERROR' }), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: undefined, | ||
domain: undefined, | ||
isLoading: false, | ||
isValidAddressOrDomain: false, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should handle error when getting address', async () => { | ||
const { result } = renderHook( | ||
() => useVechainDomain({ addressOrDomain: 'error.vet' }), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: undefined, | ||
domain: undefined, | ||
isLoading: false, | ||
isValidAddressOrDomain: false, | ||
}); | ||
}); | ||
}); | ||
it('should handle error when getting zero address', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useVechainDomain({ | ||
addressOrDomain: | ||
'0x0000000000000000000000000000000000000000', | ||
}), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toEqual({ | ||
address: '0x0000000000000000000000000000000000000000', | ||
domain: undefined, | ||
isLoading: false, | ||
isValidAddressOrDomain: true, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.