forked from JSKitty/scc-web3
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] Add unit tests for CreateWallet (#277)
* Add unit test for CreateWallet * run prettier
- Loading branch information
Showing
2 changed files
with
113 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { nextTick, ref } from 'vue'; | ||
import { expect } from 'vitest'; | ||
import CreateWallet from '../../scripts/dashboard/CreateWallet.vue'; | ||
import Modal from '../../scripts/Modal.vue'; | ||
import { vi, it, describe } from 'vitest'; | ||
import * as settings from '../../scripts/settings'; | ||
|
||
describe('create wallet tests', () => { | ||
afterEach(() => vi.clearAllMocks()); | ||
it('Generates wallet', async () => { | ||
// mock settings to disable advancedmode | ||
vi.spyOn(settings, 'fAdvancedMode', 'get').mockReturnValue(false); | ||
|
||
const wrapper = mount(CreateWallet); | ||
expect(wrapper.emitted('importWallet')).toBeUndefined(); | ||
// Modal with seedphrase is still hidden | ||
expect( | ||
wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]') | ||
).toHaveLength(0); | ||
const genWalletButton = wrapper.find('[data-testid=generateWallet]'); | ||
expect(genWalletButton.isVisible).toBeTruthy(); | ||
await genWalletButton.trigger('click'); | ||
|
||
// The click generated a seedphrase modal | ||
const seedphraseModals = wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]'); | ||
// But there is no passphrase | ||
expect( | ||
wrapper.findComponent(Modal).findAll('[data-testid=passPhrase]') | ||
).toHaveLength(0); | ||
expect(seedphraseModals).toHaveLength(1); | ||
const seedphrase = wrapper.findComponent(Modal).text(); | ||
// We must have 12 words in the seedphrase | ||
expect(seedphrase.split(' ')).toHaveLength(12); | ||
await seedphraseModals[0].trigger('click'); | ||
// Which now disappeared again | ||
expect( | ||
wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]') | ||
).toHaveLength(0); | ||
|
||
// Ok We emitted exactly one event importWallet | ||
expect(wrapper.emitted('importWallet')).toHaveLength(1); | ||
// We emitted exactly the seedphrase with empty passphrase | ||
expect(wrapper.emitted('importWallet')).toStrictEqual([ | ||
[seedphrase, ''], | ||
]); | ||
}); | ||
it('Generates wallet advanced mode', async () => { | ||
// mock settings to disable advancedmode | ||
vi.spyOn(settings, 'fAdvancedMode', 'get').mockReturnValue(true); | ||
|
||
const wrapper = mount(CreateWallet); | ||
expect(wrapper.emitted('importWallet')).toBeUndefined(); | ||
// Modal with seedphrase and passphrase is still hidden | ||
expect( | ||
wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]') | ||
).toHaveLength(0); | ||
expect( | ||
wrapper.findComponent(Modal).findAll('[data-testid=passPhrase]') | ||
).toHaveLength(0); | ||
const genWalletButton = wrapper.find('[data-testid=generateWallet]'); | ||
expect(genWalletButton.isVisible).toBeTruthy(); | ||
await genWalletButton.trigger('click'); | ||
|
||
// The click generated a modal with seedphrase and passphrase | ||
const seedphraseModals = wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]'); | ||
expect( | ||
wrapper.findComponent(Modal).findAll('[data-testid=passPhrase]') | ||
).toHaveLength(1); | ||
expect(seedphraseModals).toHaveLength(1); | ||
const seedphrase = wrapper.findComponent(Modal).text(); | ||
// We must have 12 words in the seedphrase | ||
expect(seedphrase.split(' ')).toHaveLength(12); | ||
// Select a pass phrase | ||
const passPhrase = wrapper | ||
.findComponent(Modal) | ||
.find('[data-testid=passPhrase]'); | ||
expect(passPhrase.element.value).toBe(''); | ||
passPhrase.element.value = 'panleone'; | ||
passPhrase.trigger('input'); | ||
await seedphraseModals[0].trigger('click'); | ||
// Which now disappeared again | ||
expect( | ||
wrapper | ||
.findComponent(Modal) | ||
.findAll('[data-testid=seedphraseModal]') | ||
).toHaveLength(0); | ||
|
||
// Ok We emitted exactly one event importWallet | ||
expect(wrapper.emitted('importWallet')).toHaveLength(1); | ||
// We emitted exactly the seedphrase with empty passphrase | ||
expect(wrapper.emitted('importWallet')).toStrictEqual([ | ||
[seedphrase, 'panleone'], | ||
]); | ||
}); | ||
}); |