mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import configureMockStore from 'redux-mock-store';
|
|
import { fireEvent } from '@testing-library/react';
|
|
import thunk from 'redux-thunk';
|
|
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
|
import UnlockPage from '.';
|
|
|
|
const mockMarkPasswordForgotten = jest.fn();
|
|
|
|
jest.mock('../../store/actions.js', () => ({
|
|
markPasswordForgotten: () => mockMarkPasswordForgotten,
|
|
}));
|
|
|
|
const mockElement = document.createElement('svg');
|
|
|
|
jest.mock('@metamask/logo', () => () => {
|
|
return {
|
|
container: mockElement,
|
|
setFollowMouse: jest.fn(),
|
|
stopAnimation: jest.fn(),
|
|
lookAt: jest.fn(),
|
|
};
|
|
});
|
|
|
|
describe('Unlock Page', () => {
|
|
const mockState = {
|
|
metamask: {},
|
|
};
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
it('should match snapshot', () => {
|
|
const { container } = renderWithProvider(<UnlockPage />, mockStore);
|
|
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it('changes password and submits', () => {
|
|
const props = {
|
|
onSubmit: jest.fn(),
|
|
};
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
<UnlockPage {...props} />,
|
|
mockStore,
|
|
);
|
|
|
|
const passwordField = queryByTestId('unlock-password');
|
|
const loginButton = queryByTestId('unlock-submit');
|
|
|
|
fireEvent.change(passwordField, { target: { value: 'a-password' } });
|
|
expect(passwordField).toHaveAttribute('value', 'a-password');
|
|
|
|
fireEvent.click(loginButton);
|
|
|
|
expect(props.onSubmit).toHaveBeenCalled();
|
|
});
|
|
|
|
it('clicks imports seed button', () => {
|
|
const { getByText } = renderWithProvider(<UnlockPage />, mockStore);
|
|
|
|
fireEvent.click(getByText('Forgot password?'));
|
|
|
|
expect(mockMarkPasswordForgotten).toHaveBeenCalled();
|
|
});
|
|
});
|