Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Aug 30, 2023
1 parent 9fe24f8 commit 458fbb8
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BigNumber } from 'ethers'
import SafeTokenWidget from '..'
import { hexZeroPad } from 'ethers/lib/utils'
import { AppRoutes } from '@/config/routes'
import useSafeTokenAllocation from '@/hooks/useSafeTokenAllocation'
import useSafeTokenAllocation, { useSafeTokenBalance } from '@/hooks/useSafeTokenAllocation'

const MOCK_GOVERNANCE_APP_URL = 'https://mock.governance.safe.global'

Expand Down Expand Up @@ -52,21 +52,24 @@ describe('SafeTokenWidget', () => {

it('Should render nothing for unsupported chains', () => {
;(useChainId as jest.Mock).mockImplementationOnce(jest.fn(() => '100'))
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [BigNumber.from(0), false])
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [[], , false])
;(useSafeTokenBalance as jest.Mock).mockImplementation(() => [BigNumber.from(0), , false])

const result = render(<SafeTokenWidget />)
expect(result.baseElement).toContainHTML('<body><div /></body>')
})

it('Should display 0 if Safe has no SAFE token', async () => {
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [BigNumber.from(0), false])
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [[], , false])
;(useSafeTokenBalance as jest.Mock).mockImplementation(() => [BigNumber.from(0), , false])

const result = render(<SafeTokenWidget />)
await waitFor(() => expect(result.baseElement).toHaveTextContent('0'))
})

it('Should display the value formatted correctly', async () => {
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [BigNumber.from('472238796133701648384'), false])
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [[], , false])
;(useSafeTokenBalance as jest.Mock).mockImplementation(() => [BigNumber.from('472238796133701648384'), , false])

// to avoid failing tests in some environments
const NumberFormat = Intl.NumberFormat
Expand All @@ -82,7 +85,8 @@ describe('SafeTokenWidget', () => {
})

it('Should render a link to the governance app', async () => {
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [BigNumber.from(420000), false])
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [[], , false])
;(useSafeTokenBalance as jest.Mock).mockImplementation(() => [BigNumber.from(420000), , false])

const result = render(<SafeTokenWidget />)
await waitFor(() => {
Expand All @@ -91,4 +95,14 @@ describe('SafeTokenWidget', () => {
)
})
})

it('Should render a claim button for SEP5 qualification', async () => {
;(useSafeTokenAllocation as jest.Mock).mockImplementation(() => [[{ tag: 'user_v2' }], , false])
;(useSafeTokenBalance as jest.Mock).mockImplementation(() => [BigNumber.from(420000), , false])

const result = render(<SafeTokenWidget />)
await waitFor(() => {
expect(result.baseElement).toContainHTML('New allocation')
})
})
})

0 comments on commit 458fbb8

Please sign in to comment.