Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write unit tests for the 'makeSortedPhrase' util
- Loading branch information
Showing
2 changed files
with
44 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @flow | ||
|
||
import { makeSortedPhrase } from './recoveryPhrase'; | ||
|
||
describe('makeSortedPhrase()', () => { | ||
test('sort recovery phrase with unique words', () => { | ||
const phraseWithUniqueWords = ['w_3', 'w_2', 'w_1']; | ||
const sorted = makeSortedPhrase(phraseWithUniqueWords); | ||
|
||
const [first, second, third] = sorted; | ||
expect(first.id).toBe(0); | ||
expect(first.word).toBe('w_1'); | ||
expect(first.originalIdx).toBe(2); | ||
|
||
expect(second.id).toBe(1); | ||
expect(second.word).toBe('w_2'); | ||
expect(second.originalIdx).toBe(1); | ||
|
||
expect(third.id).toBe(2); | ||
expect(third.word).toBe('w_3'); | ||
expect(third.originalIdx).toBe(0); | ||
}); | ||
|
||
test('sort recovery phrase with duplicates', () => { | ||
const recoveryPhraseWithDuplicates = ['abandon', 'address', 'abandon']; | ||
const sorted = makeSortedPhrase(recoveryPhraseWithDuplicates); | ||
|
||
const [first, second, third] = sorted; | ||
expect(first.id).toBe(0); | ||
expect(first.word).toBe('abandon'); | ||
expect(first.originalIdx).toBe(0); | ||
|
||
expect(second.id).toBe(1); | ||
expect(second.word).toBe('abandon'); | ||
expect(second.originalIdx).toBe(2); | ||
|
||
expect(third.id).toBe(2); | ||
expect(third.word).toBe('address'); | ||
expect(third.originalIdx).toBe(1); | ||
}) | ||
}); |