mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 07:16:36 +01:00
0306422bbf
Co-authored-by: George Marshall <george.marshall@consensys.net> Co-authored-by: Brad Decker <bhdecker84@gmail.com> Co-authored-by: David Walsh <davidwalsh83@gmail.com> Co-authored-by: Howard Braham <howrad@gmail.com> * change js to tsx * update to typescript * add labels to circle animation * add willHide prop to hold to reveal modal * add test * convert to design system * fix lint * fix type * bump coverage * rename * remove comments * remove ts comment and add fix exhuastive dep check * update coverage * add hide modal test * use banneralert * update label * remove unused * fix text * update aria label messages * change exportAccountAndGetPrivateKey to be async * fix lint * update coverage target * update coverage * update input component * update coverage * update coverage * fix blank line * use && * move plainKey to under !privateKeyInput * update hold modal to display srp and private key message * fix styling * fix lint and test * fix unused locales * remove redundent check * update storybook * fix text alignment * fix lint * update snapshot * fix test * update coverage * fix merge conflict * refactor * fix variant * update snapshot * fix test after merge * fix test after merge conflict * fix label text * update to use label component
83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
import React from 'react';
|
|
import { fireEvent } from '@testing-library/react';
|
|
import configureMockStore from 'redux-mock-store';
|
|
import thunk from 'redux-thunk';
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
|
import mockState from '../../../../../test/data/mock-state.json';
|
|
import * as actions from '../../../../store/actions';
|
|
import ExportPrivateKeyModal from '.';
|
|
|
|
jest.mock('../../../../store/actions.ts', () => ({
|
|
...jest.requireActual('../../../../store/actions.ts'),
|
|
exportAccount: jest.fn().mockReturnValue(jest.fn().mockResolvedValueOnce()),
|
|
hideWarning: () => jest.fn(),
|
|
showModal: () => jest.fn(),
|
|
hideModal: () => jest.fn(),
|
|
clearAccountDetails: () => jest.fn(),
|
|
}));
|
|
|
|
describe('Export PrivateKey Modal', () => {
|
|
const password = 'a-password';
|
|
|
|
const privKeyModalState = {
|
|
...mockState,
|
|
appState: {
|
|
...mockState.appState,
|
|
accountDetail: {
|
|
privateKey: '0xPrivKey',
|
|
},
|
|
},
|
|
};
|
|
const mockStore = configureMockStore([thunk])(privKeyModalState);
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should match snapshot', () => {
|
|
const { container } = renderWithProvider(
|
|
<ExportPrivateKeyModal />,
|
|
mockStore,
|
|
);
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it('should disable confirm button by default', () => {
|
|
const { queryByText } = renderWithProvider(
|
|
<ExportPrivateKeyModal />,
|
|
mockStore,
|
|
);
|
|
|
|
const confirmButton = queryByText('Confirm');
|
|
|
|
expect(confirmButton).toBeDisabled();
|
|
});
|
|
|
|
it('should call export account with password and selected address', () => {
|
|
const { queryByTestId, queryByText } = renderWithProvider(
|
|
<ExportPrivateKeyModal />,
|
|
mockStore,
|
|
);
|
|
|
|
const passwordInput =
|
|
queryByTestId('password-input').querySelector('input');
|
|
|
|
const passwordInputEvent = {
|
|
target: {
|
|
value: password,
|
|
},
|
|
};
|
|
|
|
fireEvent.change(passwordInput, passwordInputEvent);
|
|
|
|
const confirmButton = queryByText('Confirm');
|
|
|
|
fireEvent.click(confirmButton);
|
|
|
|
expect(actions.exportAccount).toHaveBeenCalledWith(
|
|
password,
|
|
mockState.metamask.selectedAddress,
|
|
);
|
|
});
|
|
});
|