2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { mount } from 'enzyme';
|
2021-03-16 22:00:08 +01:00
|
|
|
import UnlockPage from './unlock-page.container';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Unlock Page', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
|
|
|
isUnlocked: false,
|
|
|
|
onRestore: sinon.spy(),
|
|
|
|
onSubmit: sinon.spy(),
|
|
|
|
forceUpdateMetamaskState: sinon.spy(),
|
|
|
|
showOptInModal: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = mount(<UnlockPage.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterAll(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders', () => {
|
|
|
|
expect(wrapper).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('changes password and submits', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const passwordField = wrapper.find({ type: 'password', id: 'password' });
|
|
|
|
const loginButton = wrapper.find({ type: 'submit' }).last();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const event = { target: { value: 'password' } };
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.instance().state.password).toStrictEqual('');
|
2021-02-04 19:15:23 +01:00
|
|
|
passwordField.last().simulate('change', event);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.instance().state.password).toStrictEqual('password');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
loginButton.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.onSubmit.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|