1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 15:14:29 +01:00
metamask-extension/ui/pages/first-time-flow/create-password/import-with-seed-phrase/import-with-seed-phrase.component.test.js
Mark Stacey ba54a3d83b
Update ESLint config to v8 (#12886)
The ESLint config has been updated to v8. The breaking changes are:

* The Prettier rule `quoteProps` has been changed from `consistent` to
`as-needed`, meaning that if one key requires quoting, only that key is
quoted rather than all keys.
* The ESLint rule `no-shadow` has been made more strict. It now
prevents globals from being shadowed as well.

Most of these changes were applied with `yarn lint:fix`. Only the
shadowing changes required manual fixing (shadowing variable names were
either replaced with destructuring or renamed).

The dependency `globalThis` was added to the list of dynamic
dependencies in the build system, where it should have been already.
This was causing `depcheck` to fail because the new lint rules required
removing the one place where `globalThis` had been erroneously imported
previously.

A rule requiring a newline between multiline blocks and expressions has
been disabled temporarily to make this PR smaller and to avoid
introducing conflicts with other PRs.
2021-12-09 15:36:24 -03:30

100 lines
2.8 KiB
JavaScript

import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import ImportWithSeedPhrase from './import-with-seed-phrase.component';
function shallowRender(props = {}, context = {}) {
return shallow(<ImportWithSeedPhrase {...props} />, {
context: {
t: (str) => `${str}_t`,
metricsEvent: sinon.spy(),
...context,
},
});
}
describe('ImportWithSeedPhrase Component', () => {
it('should render without error', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const textareaCount = component.find('.first-time-flow__textarea').length;
expect(textareaCount).toStrictEqual(1);
});
describe('parseSeedPhrase', () => {
it('should handle a regular Secret Recovery Phrase', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase('foo bar baz')).toStrictEqual('foo bar baz');
});
it('should handle a mixed-case Secret Recovery Phrase', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase('FOO bAr baZ')).toStrictEqual('foo bar baz');
});
it('should handle an upper-case Secret Recovery Phrase', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase('FOO BAR BAZ')).toStrictEqual('foo bar baz');
});
it('should trim extraneous whitespace from the given Secret Recovery Phrase', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase(' foo bar baz ')).toStrictEqual(
'foo bar baz',
);
});
it('should return an empty string when given a whitespace-only string', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase(' ')).toStrictEqual('');
});
it('should return an empty string when given a string with only symbols', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase('$')).toStrictEqual('');
});
it('should return an empty string for both null and undefined', () => {
const component = shallowRender({
onSubmit: sinon.spy(),
});
const { parseSeedPhrase } = component.instance();
expect(parseSeedPhrase(undefined)).toStrictEqual('');
expect(parseSeedPhrase(null)).toStrictEqual('');
});
});
});