1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00
metamask-extension/ui/components/app/modals/account-details-modal/account-details-modal.test.js
David Walsh a5494fc637
UX: Multichain: Account Details Fixes (#18999)
* Fix account details editable label

* Fix font-weight of the password label

* Remove duplicate error

* Hide password warning on first screen after bad password, autofocus password field

* Fix jest failure

* Restore className
2023-05-08 09:03:34 -05:00

107 lines
2.9 KiB
JavaScript

import React from 'react';
import configureMockState from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
import mockState from '../../../../../test/data/mock-state.json';
import {
etherscanViewOn,
exportPrivateKey,
} from '../../../../../app/_locales/en/messages.json';
import AccountDetailsModal from '.';
const mockShowModal = jest.fn();
jest.mock('../../../../store/actions.ts', () => {
return {
showModal: () => mockShowModal,
};
});
describe('Account Details Modal', () => {
const mockStore = configureMockState([thunk])(mockState);
global.platform = { openTab: jest.fn() };
it('should set account label when changing default account label', () => {
const { queryByTestId, getByPlaceholderText } = renderWithProvider(
<AccountDetailsModal />,
mockStore,
);
const editButton = queryByTestId('editable-label-button');
expect(queryByTestId('editable-input')).not.toBeInTheDocument();
fireEvent.click(editButton);
expect(queryByTestId('editable-input')).toBeInTheDocument();
const editableInput = getByPlaceholderText('Account name');
const newAccountLabel = 'New Label';
fireEvent.change(editableInput, {
target: { value: newAccountLabel },
});
expect(editableInput).toHaveAttribute('value', newAccountLabel);
});
it('opens new tab when view block explorer is clicked', () => {
const { queryByText } = renderWithProvider(
<AccountDetailsModal />,
mockStore,
);
const viewOnEtherscan = queryByText(etherscanViewOn.message);
fireEvent.click(viewOnEtherscan);
expect(global.platform.openTab).toHaveBeenCalled();
});
it('shows export private key modal when clicked', () => {
const { queryByText } = renderWithProvider(
<AccountDetailsModal />,
mockStore,
);
const exportPrivButton = queryByText(exportPrivateKey.message);
fireEvent.click(exportPrivButton);
expect(mockShowModal).toHaveBeenCalled();
});
it('sets blockexplorerview text when block explorer url in rpcPrefs exists', () => {
const blockExplorerUrl = 'https://block.explorer';
const customProviderMockState = {
...mockState,
metamask: {
...mockState.metamask,
networkConfigurations: {
networkConfigurationId: {
chainId: '0x99',
rpcPrefs: {
blockExplorerUrl,
},
},
},
providerConfig: {
chainId: '0x99',
},
},
};
const customProviderMockStore = configureMockState([thunk])(
customProviderMockState,
);
const { queryByText } = renderWithProvider(
<AccountDetailsModal />,
customProviderMockStore,
);
expect(queryByText(/block.explorer/u)).toBeInTheDocument();
});
});