-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set createcontract isAllowed option and unit tests
- Loading branch information
1 parent
d01250d
commit dac771b
Showing
5 changed files
with
121 additions
and
6 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
1 change: 0 additions & 1 deletion
1
packages/apps/rwa-demo/src/hooks/__tests__/batchTransferTokens.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
98 changes: 98 additions & 0 deletions
98
packages/apps/rwa-demo/src/hooks/__tests__/createContract.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,98 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useCreateContract } from '../createContract'; | ||
|
||
describe('createContract hook', () => { | ||
const mocksHook = vi.hoisted(() => { | ||
return { | ||
useAccount: vi.fn().mockReturnValue({ | ||
account: { | ||
address: 'k:he-man', | ||
}, | ||
sign: vi.fn(), | ||
isMounted: true, | ||
isGasPayable: false, | ||
}), | ||
|
||
useTransactions: vi.fn().mockReturnValue({ | ||
addTransaction: vi.fn(), | ||
}), | ||
useNotifications: vi.fn().mockReturnValue({ | ||
addNotification: vi.fn(), | ||
}), | ||
}; | ||
}); | ||
|
||
beforeEach(async () => { | ||
vi.mock('./../account', async () => { | ||
const actual = await vi.importActual('./../account'); | ||
return { | ||
...actual, | ||
useAccount: mocksHook.useAccount, | ||
}; | ||
}); | ||
|
||
vi.mock('./../transactions', async () => { | ||
const actual = await vi.importActual('./../transactions'); | ||
return { | ||
...actual, | ||
useTransactions: mocksHook.useTransactions, | ||
}; | ||
}); | ||
|
||
vi.mock('@kadena/kode-ui/patterns', async () => { | ||
const actual = await vi.importActual('@kadena/kode-ui/patterns'); | ||
return { | ||
...actual, | ||
useNotifications: mocksHook.useNotifications, | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should return the correct properties', async () => { | ||
const { result } = renderHook(() => useCreateContract()); | ||
expect(result.current.hasOwnProperty('isAllowed')).toBe(true); | ||
expect(result.current.hasOwnProperty('submit')).toBe(true); | ||
}); | ||
|
||
describe('isAllowed', () => { | ||
it('should return true, when account is Mounted, when gasisPayable', () => { | ||
mocksHook.useAccount.mockImplementation(() => ({ | ||
...mocksHook.useAccount.getMockImplementation(), | ||
isMounted: true, | ||
isGasPayable: true, | ||
})); | ||
|
||
const { result } = renderHook(() => useCreateContract()); | ||
|
||
expect(result.current.isAllowed).toBe(true); | ||
}); | ||
|
||
it('should return false, when account is NOT Mounted, when gasisPayable', () => { | ||
mocksHook.useAccount.mockImplementation(() => ({ | ||
...mocksHook.useAccount.getMockImplementation(), | ||
isMounted: false, | ||
isGasPayable: true, | ||
})); | ||
|
||
const { result } = renderHook(() => useCreateContract()); | ||
|
||
expect(result.current.isAllowed).toBe(false); | ||
}); | ||
|
||
it('should return false, when account is Mounted, when NOT gasisPayable', () => { | ||
mocksHook.useAccount.mockImplementation(() => ({ | ||
...mocksHook.useAccount.getMockImplementation(), | ||
isMounted: true, | ||
isGasPayable: false, | ||
})); | ||
|
||
const { result } = renderHook(() => useCreateContract()); | ||
|
||
expect(result.current.isAllowed).toBe(false); | ||
}); | ||
}); | ||
}); |
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