1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/multichain/account-details/account-details.test.js
David Walsh ab4843f06b
UX: Multichain: Implement Account Details Popover (#18811)
* UX: Multichain: Implement Account Details Popover

* Styling account details popover

* using ButtonSecondary with variant, removing Text

* adding account-details jest test

* Close popover when outside area clicked

* Move all export functionality into the popover

* Improve jest tests

* Implement new design for export key screens

* Hide warning when popover is closed

* Vertically align the copy button

* Move AccountDetailsDisplay to its own file

* Move authentication to its own file

* Move private key to its own component

* Fix misalignment of avatar on display screen

* Move private key to its own component

* Update ui/components/multichain/account-details/account-details-authenticate.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/multichain/account-details/account-details.test.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Prevent account name overflow, update text size

* Use FormTextField

* Add analytics

* Move location of accountDetailsAddress

* Ensure passsword input is used

---------

Co-authored-by: Victor Thomas <10986371+vthomas13@users.noreply.github.com>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
2023-05-03 12:09:13 -05:00

92 lines
3.1 KiB
JavaScript

import React from 'react';
import { screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithProvider } from '../../../../test/jest';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import { showPrivateKey } from '../../../../app/_locales/en/messages.json';
import {
setAccountDetailsAddress,
exportAccount,
hideWarning,
} from '../../../store/actions';
import { AccountDetails } from '.';
jest.mock('../../../store/actions.ts');
describe('AccountDetails', () => {
const address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
const mockSetAccountDetailsAddress = jest.fn();
const mockExportAccount = jest.fn().mockResolvedValue(true);
const mockHideWarning = jest.fn();
beforeEach(() => {
setAccountDetailsAddress.mockReturnValue(mockSetAccountDetailsAddress);
exportAccount.mockReturnValue(mockExportAccount);
hideWarning.mockReturnValue(mockHideWarning);
});
afterEach(() => jest.clearAllMocks());
function render(props = {}, storeModifications = {}) {
const store = configureStore({
metamask: {
...mockState.metamask,
},
...storeModifications,
});
const allProps = { address, ...props };
return renderWithProvider(<AccountDetails {...allProps} />, store);
}
it('should set account label when changing default account label', () => {
render();
const editButton = screen.getByTestId('editable-label-button');
fireEvent.click(editButton);
const editableInput = screen.getByTestId('editable-input');
const newAccountLabel = 'New Label';
fireEvent.change(editableInput, { target: { value: newAccountLabel } });
expect(editableInput).toHaveAttribute('value', newAccountLabel);
});
it('shows export private key contents and password field when clicked', () => {
const { queryByText, queryByPlaceholderText } = render();
const exportPrivateKeyButton = queryByText(showPrivateKey.message);
fireEvent.click(exportPrivateKeyButton);
expect(queryByText('Show private key')).toBeInTheDocument();
expect(queryByPlaceholderText('Password')).toBeInTheDocument();
});
it('attempts to validate password when submitted', async () => {
const password = 'password';
const { queryByPlaceholderText, queryByText } = render();
const exportPrivateKeyButton = queryByText(showPrivateKey.message);
fireEvent.click(exportPrivateKeyButton);
queryByPlaceholderText('Password').focus();
await userEvent.keyboard(password);
fireEvent.click(queryByText('Confirm'));
expect(exportAccount).toHaveBeenCalledWith(password, address);
});
it('displays the private key when exposed in state', () => {
const samplePrivateKey = '8675309';
const { queryByText } = render(
{},
{ appState: { accountDetail: { privateKey: samplePrivateKey } } },
);
const exportPrivateKeyButton = queryByText(showPrivateKey.message);
fireEvent.click(exportPrivateKeyButton);
expect(queryByText(samplePrivateKey)).toBeInTheDocument();
});
});