-
Notifications
You must be signed in to change notification settings - Fork 118
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
83ca62b
commit 39ee99d
Showing
31 changed files
with
1,235 additions
and
355 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
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
58 changes: 58 additions & 0 deletions
58
...ents/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/ExpirySection.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,58 @@ | ||
import { render, screen, userEvent, waitFor } from '@app/test-utils' | ||
import { GRACE_PERIOD } from '@app/utils/constants' | ||
import { ExpirySection } from './ExpirySection'; | ||
|
||
|
||
jest.mock('./hooks/useExpiryDetails', () => ({ | ||
useExpiryDetails: ({name}: any) => { | ||
if (name === 'test.eth') return { | ||
data: [{type: 'expiry', date: new Date(3255803954000)}, {type: 'grace-period', date: new Date(3255803954000 + GRACE_PERIOD)}, {type: 'registration', date: new Date(3255803954000)}], | ||
isLoading: false | ||
}} | ||
})) | ||
|
||
const mockShowInput = jest.fn() | ||
jest.mock('./hooks/useExpiryActions', () => ({ | ||
useExpiryActions: ({name}: any) => { | ||
if (name === 'test.eth') return [ { | ||
label: 'action.setReminder', | ||
type: 'set-reminder', | ||
icon: <div >ICON</div>, | ||
primary: false, | ||
expiryDate: new Date() | ||
}, | ||
{ | ||
label: 'action.extend', | ||
type: 'extend', | ||
icon: <div>ICON</div>, | ||
primary: true, | ||
onClick: () => { | ||
mockShowInput() | ||
}, | ||
}]}}) | ||
) | ||
|
||
describe('ExpirySection', () => { | ||
it('should be able to open earnify button modal', async () => { | ||
render(<ExpirySection name="test.eth" details={{} as any}/>) | ||
expect(screen.getByText('action.setReminder')).toBeVisible() | ||
expect(screen.getByText('action.extend')).toBeVisible() | ||
await userEvent.click(screen.getByText('action.setReminder')) | ||
await waitFor(async () => { | ||
expect(screen.getByText('tabs.more.misc.reminderOptions.earnifi')).toBeVisible() | ||
await userEvent.click(screen.getByText('tabs.more.misc.reminderOptions.earnifi')) | ||
}) | ||
await waitFor(() => { | ||
expect(screen.getByText('tabs.more.misc.earnfi.title')).toBeVisible() | ||
}) | ||
}) | ||
|
||
it('should be able to call show extend modal', async () => { | ||
render(<ExpirySection name="test.eth" details={{} as any}/>) | ||
expect(screen.getByText('action.extend')).toBeVisible() | ||
await userEvent.click(screen.getByText('action.extend')) | ||
await waitFor(() => { | ||
expect(mockShowInput).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
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
24 changes: 24 additions & 0 deletions
24
...s/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions.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,24 @@ | ||
import { renderHook } from "@app/test-utils" | ||
import { useExpiryActions } from "./useExpiryActions" | ||
|
||
describe('useExpiryActions', () => { | ||
it('should render if expiryDetails contains a expiry type data with a valid expiry date', () => { | ||
const { result} = renderHook(() => useExpiryActions({ name: 'test.eth', expiryDetails: [{ type: 'expiry', date: new Date('3255803954000') }]})) | ||
expect(result.current).toEqual(expect.arrayContaining([expect.objectContaining({type: 'extend'})])) | ||
}) | ||
|
||
it('should render null if name is subname and if expiryDetails contains a expiry type data with a valid expiry date', () => { | ||
const { result} = renderHook(() => useExpiryActions({ name: 'sub.test.eth', expiryDetails: [{ type: 'expiry', date: new Date('3255803954000') }]})) | ||
expect(result.current).toEqual(null) | ||
}) | ||
|
||
it('should return null if expiryDetails contains a expiry type data but an invalid expiry date', () => { | ||
const { result} = renderHook(() => useExpiryActions({ name: 'test.eth', expiryDetails: [{ type: 'expiry', date: undefined }]})) | ||
expect(result.current).toEqual(null) | ||
}) | ||
|
||
it('should return null if expiryDetails does not contain a expiry type data', () => { | ||
const { result} = renderHook(() => useExpiryActions({ name: 'test.eth', expiryDetails: [{ type: 'expiry', date: undefined }]})) | ||
expect(result.current).toEqual(null) | ||
}) | ||
}) |
109 changes: 109 additions & 0 deletions
109
...es/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryDetails.test.ts
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,109 @@ | ||
import { renderHook } from "@testing-library/react-hooks" | ||
import { useExpiryDetails } from "./useExpiryDetails" | ||
import { checkETH2LDFromName } from "@app/utils/utils" | ||
|
||
const mockUseNameType = jest.fn() | ||
jest.mock('@app/hooks/useNameType', () => ({ | ||
useNameType: () => mockUseNameType() | ||
})) | ||
|
||
const mockUseBasicName = jest.fn() | ||
jest.mock('@app/hooks/useBasicName', () => ({ | ||
useBasicName: (_: string, {enabled}: any) => { | ||
return enabled ? mockUseBasicName() : {isLoading: false} } | ||
})) | ||
|
||
const mockUseRegistrationData = jest.fn().mockReturnValue({ | ||
data: { | ||
registrationDate: new Date(3255803954000), | ||
transactionHash: '0xhash' | ||
} , | ||
isLoading: false | ||
}) | ||
jest.mock('@app/hooks/useRegistrationData', () => (name: string, {enabled}: any) => enabled && checkETH2LDFromName(name) ? mockUseRegistrationData() : { isLoading: false}) | ||
|
||
jest.mock('@app/hooks/useChainName', () => ({ | ||
useChainName: () => 'goerli' | ||
})) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('useExpiryDetails', () => { | ||
describe('eth 2lds', () => { | ||
['eth-unwrapped-2ld', 'eth-emancipated-2ld', 'eth-locked-2ld'].forEach((nameType) => { | ||
it(`should return expiry, grace-period and `, () => { | ||
mockUseNameType.mockReturnValue({ | ||
data: nameType, | ||
isLoading: false | ||
}) | ||
const { result } = renderHook(() => useExpiryDetails({name: 'test.eth', details: { | ||
expiryDate: new Date(3255803954000), | ||
isLoading: false | ||
} as any})) | ||
|
||
expect(mockUseRegistrationData).toHaveBeenCalled() | ||
expect(mockUseBasicName).not.toHaveBeenCalled() | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'expiry'})])) | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'grace-period'})])) | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'registration'})])) | ||
|
||
}) | ||
}) | ||
}) | ||
|
||
describe('pcc burned eth subnamess', () => { | ||
['eth-emancipated-subname', 'eth-locked-subname'].forEach((nameType) => { | ||
it(`should return expiry, grace-period and `, () => { | ||
mockUseNameType.mockReturnValue({ | ||
data: nameType, | ||
isLoading: false | ||
}) | ||
mockUseBasicName.mockReturnValue({ | ||
wrapperData: { | ||
expiryDate: new Date(3255803954000) | ||
}, | ||
isLoading: false | ||
}) | ||
|
||
const { result } = renderHook(() => useExpiryDetails({name: 'sub.test.eth', details: { | ||
wrapperData: { | ||
expiryDate: new Date(3255803954000) | ||
}, | ||
isLoading: false | ||
} as any})) | ||
|
||
expect(mockUseRegistrationData).not.toHaveBeenCalled() | ||
expect(mockUseBasicName).toHaveBeenCalled() | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'expiry'})])) | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'parent-expiry'})])) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('pcc not burned eth subnamess', () => { | ||
['eth-unwrapped-subname', 'eth-wrapped-subname', 'eth-pcc-expired-subname'].forEach((nameType) => { | ||
it(`should return expiry, grace-period and `, () => { | ||
mockUseNameType.mockReturnValue({ | ||
data: nameType, | ||
isLoading: false | ||
}) | ||
mockUseBasicName.mockReturnValue({ | ||
expiryDate: new Date(3255803954000), | ||
isLoading: false | ||
}) | ||
|
||
const { result } = renderHook(() => useExpiryDetails({name: 'sub.test.eth', details: { | ||
expiryDate: new Date(3255803954000), | ||
isLoading: false | ||
} as any})) | ||
|
||
expect(mockUseRegistrationData).not.toHaveBeenCalled() | ||
expect(mockUseBasicName).toHaveBeenCalled() | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'parent-grace-period'})])) | ||
expect(result.current.data).toEqual(expect.arrayContaining([expect.objectContaining({type: 'parent-expiry'})])) | ||
}) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.