-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified jest config, added test for wallet effect
- Loading branch information
Showing
10 changed files
with
118 additions
and
38 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
8 changes: 4 additions & 4 deletions
8
__tests__/Checkbox.tsx → src/components/checkbox/Checkbox.spec.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
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
77 changes: 77 additions & 0 deletions
77
src/store/wallet/effects/create/getDecryptPassword.spec.js
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,77 @@ | ||
import React from 'react'; | ||
import {getDecryptPassword} from './create'; | ||
import configureTestStore from '@test/store'; | ||
import { | ||
dismissDecryptPasswordModal, | ||
showDecryptPasswordModal, | ||
} from '../../../app/app.actions'; | ||
import {checkEncryptPassword} from '../../utils/wallet'; | ||
|
||
/** | ||
* Mock showDecryptPasswordModal and Spy on dismissDecryptPasswordModal | ||
*/ | ||
jest.mock('../../../app/app.actions', () => ({ | ||
...jest.requireActual('../../../app/app.actions'), | ||
showDecryptPasswordModal: jest.fn().mockImplementation(() => { | ||
return {type: 'MOCK'}; | ||
}), | ||
dismissDecryptPasswordModal: jest.fn().mockImplementation(() => { | ||
return {type: 'MOCK'}; | ||
}), | ||
})); | ||
|
||
/** | ||
* Mock checkEncryptPassword | ||
*/ | ||
jest.mock('../../utils/wallet', () => ({ | ||
...jest.requireActual('../../utils/wallet'), | ||
checkEncryptPassword: jest | ||
.fn() | ||
.mockImplementation((key, pass) => key === 'unlocked'), | ||
})); | ||
|
||
/** | ||
* getDecryptPassword Tests | ||
*/ | ||
describe('getDecryptPassword', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('calls showDecryptPasswordModal with onSubmitHandler config', () => { | ||
const store = configureTestStore({}); | ||
store.dispatch(getDecryptPassword('test')); | ||
const argument = showDecryptPasswordModal.mock.calls[0][0]; | ||
expect(showDecryptPasswordModal).toHaveBeenCalledTimes(1); | ||
expect(typeof argument.onSubmitHandler).toEqual('function'); | ||
}); | ||
|
||
it('calls dismissDecryptPasswordModal when submit handler is called', () => { | ||
const store = configureTestStore({}); | ||
store.dispatch(getDecryptPassword('test')); | ||
|
||
const argument = showDecryptPasswordModal.mock.calls[0][0]; | ||
argument.onSubmitHandler(); | ||
expect(dismissDecryptPasswordModal).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('will resolve the promise as we expect', async () => { | ||
const store = configureTestStore({}); | ||
const promiseSuccessResult = store.dispatch(getDecryptPassword('unlocked')); | ||
const successArgument = showDecryptPasswordModal.mock.calls[0][0]; | ||
await successArgument.onSubmitHandler('privatekey'); | ||
await expect(promiseSuccessResult).resolves.toEqual('privatekey'); | ||
expect(checkEncryptPassword).toHaveBeenCalledWith('unlocked', 'privatekey'); | ||
}); | ||
|
||
it('will reject the promise as we expect', async () => { | ||
const store = configureTestStore({}); | ||
const promiseFailedResult = store.dispatch(getDecryptPassword('test')); | ||
const failedArgument = showDecryptPasswordModal.mock.calls[0][0]; | ||
await failedArgument.onSubmitHandler('privatekey'); | ||
await expect(promiseFailedResult).rejects.toEqual({ | ||
message: 'invalid password', | ||
}); | ||
expect(checkEncryptPassword).toHaveBeenCalledWith('test', 'privatekey'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import {configureTestStore} from '../src/store'; | ||
export default configureTestStore; |