Skip to content

Commit

Permalink
test: use describe and it
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Apr 15, 2024
1 parent 837a33d commit 79e78ba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ module.exports = {
customExportConditions: ['node', 'node-addons'],
},
globalSetup: './jest.setup.cjs',
setTimeout: 10000,
}
86 changes: 44 additions & 42 deletions src/components/endpoints/__tests__/Permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,59 @@ window.erc725Account = {
},
} as Contract

beforeEach(() => {
jest.resetAllMocks()
})
describe('Setting Permissions tests', () => {
beforeEach(() => {
jest.resetAllMocks()
})

test('can update permissions for given address', async () => {
setState('address', '0x02f02b27eDFcBBDE762Ff2a7FC20a4Aebd495214')
it('can update permissions for given address', async () => {
setState('address', '0x02f02b27eDFcBBDE762Ff2a7FC20a4Aebd495214')

mockSend.mockImplementation(() => ({
on: () => ({
once: () => jest.fn().mockImplementation(() => {}),
}),
}))
mockSend.mockImplementation(() => ({
on: () => ({
once: () => jest.fn().mockImplementation(() => {}),
}),
}))

render(Permissions)
render(Permissions)

fireEvent.click(screen.getByTestId('CHANGEOWNER'))
fireEvent.click(screen.getByTestId('setPermissions'))
fireEvent.click(screen.getByTestId('CHANGEOWNER'))
fireEvent.click(screen.getByTestId('setPermissions'))

await waitFor(() =>
expect(screen.getByTestId('notification')).toHaveTextContent(
'Permissions set'
await waitFor(() =>
expect(screen.getByTestId('notification')).toHaveTextContent(
'Permissions set'
)
)
)
expect(mockSend).toBeCalledWith(
[
'0x4b80742de2bf82acb3630000af3bf2ffb025098b79caddfbdd113b3681817744',
'0xdf30dba06db6a30e65354d9a64c609861f089545ca58c6b4dbe31a5f338cb0e3',
'0xdf30dba06db6a30e65354d9a64c6098600000000000000000000000000000007',
],
[
'0x0000000000000000000000000000000000000000000000000000000000000001',
'0x00000000000000000000000000000008',
'0xaf3bf2ffb025098b79caddfbdd113b3681817744',
]
)
})
expect(mockSend).toBeCalledWith(
[
'0x4b80742de2bf82acb3630000af3bf2ffb025098b79caddfbdd113b3681817744',
'0xdf30dba06db6a30e65354d9a64c609861f089545ca58c6b4dbe31a5f338cb0e3',
'0xdf30dba06db6a30e65354d9a64c6098600000000000000000000000000000007',
],
[
'0x0000000000000000000000000000000000000000000000000000000000000001',
'0x00000000000000000000000000000008',
'0xaf3bf2ffb025098b79caddfbdd113b3681817744',
]
)
})

test('can see set permission error from send function', async () => {
setState('address', '0x02f02b27eDFcBBDE762Ff2a7FC20a4Aebd495214')
it('can see set permission error from send function', async () => {
setState('address', '0x02f02b27eDFcBBDE762Ff2a7FC20a4Aebd495214')

mockSend.mockImplementation(() =>
jest.fn().mockImplementation(() => {
throw new Error('Send error')
})()
)
mockSend.mockImplementation(() =>
jest.fn().mockImplementation(() => {
throw new Error('Send error')
})()
)

render(Permissions)
render(Permissions)

fireEvent.click(screen.getByTestId('setPermissions'))
fireEvent.click(screen.getByTestId('setPermissions'))

await waitFor(() =>
expect(screen.getByTestId('notification')).toHaveTextContent('Send error')
)
await waitFor(() =>
expect(screen.getByTestId('notification')).toHaveTextContent('Send error')
)
})
})

0 comments on commit 79e78ba

Please sign in to comment.