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', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-12-09 20:06:24 +01:00
|
|
|
const textareaCount = component.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', () => {
|
2021-05-07 15:07:43 +02:00
|
|
|
it('should handle a regular Secret Recovery Phrase', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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-05-07 15:07:43 +02:00
|
|
|
it('should handle a mixed-case Secret Recovery Phrase', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2020-03-30 14:51:04 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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-05-07 15:07:43 +02:00
|
|
|
it('should handle an upper-case Secret Recovery Phrase', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2020-03-30 14:51:04 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-30 14:51:04 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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-05-07 15:07:43 +02:00
|
|
|
it('should trim extraneous whitespace from the given Secret Recovery Phrase', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const component = shallowRender({
|
2019-06-27 19:14:41 +02:00
|
|
|
onSubmit: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 19:14:41 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const { parseSeedPhrase } = component.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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|