2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
2021-03-16 22:00:08 +01:00
|
|
|
import ImportWithSeedPhrase from './import-with-seed-phrase.component';
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function shallowRender(props = {}, context = {}) {
|
2019-06-27 19:14:41 +02:00
|
|
|
return shallow(<ImportWithSeedPhrase {...props} />, {
|
|
|
|
context: {
|
2020-08-19 18:27:05 +02:00
|
|
|
t: (str) => `${str}_t`,
|
2019-06-27 19:14:41 +02:00
|
|
|
metricsEvent: sinon.spy(),
|
|
|
|
...context,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('ImportWithSeedPhrase Component', () => {
|
|
|
|
it('should render without error', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const textareaCount = root.find('.first-time-flow__textarea').length;
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(textareaCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('parseSeedPhrase', () => {
|
|
|
|
it('should handle a regular seed phrase', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase('foo bar baz')).toStrictEqual('foo bar baz');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should handle a mixed-case seed phrase', () => {
|
2020-03-30 14:51:04 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase('FOO bAr baZ')).toStrictEqual('foo bar baz');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should handle an upper-case seed phrase', () => {
|
2020-03-30 14:51:04 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase('FOO BAR BAZ')).toStrictEqual('foo bar baz');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should trim extraneous whitespace from the given seed phrase', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase(' foo bar baz ')).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'foo bar baz',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return an empty string when given a whitespace-only string', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase(' ')).toStrictEqual('');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return an empty string when given a string with only symbols', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase('$')).toStrictEqual('');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return an empty string for both null and undefined', () => {
|
2019-06-27 19:14:41 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { parseSeedPhrase } = root.instance();
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(parseSeedPhrase(undefined)).toStrictEqual('');
|
|
|
|
expect(parseSeedPhrase(null)).toStrictEqual('');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|