mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
28137798b6
* UX: Multichain: Move Add Account and Import Account into Account Menu Popover * Create a new CreateAccount component for the Account Menu * Add actions for import form * Use separate actions for cancel vs. submit * Fix jest tests * Remove commented route navigation * Accommodate for failing import * Fix tests * Remove routes for new account and import * Remove old create account page * Move import-account files to multichain directory * Fix paths on the import files * Remove deprecated component library variables * Fix error property of add form * Fix user-actions-benchmark
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
/* eslint-disable jest/require-top-level-describe */
|
|
import React from 'react';
|
|
import { fireEvent, renderWithProvider, waitFor } from '../../../../test/jest';
|
|
import configureStore from '../../../store/store';
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
import { CreateAccount } from '.';
|
|
|
|
const render = (props = { onActionComplete: () => jest.fn() }) => {
|
|
const store = configureStore(mockState);
|
|
return renderWithProvider(<CreateAccount {...props} />, store);
|
|
};
|
|
|
|
const mockAddNewAccount = jest.fn().mockReturnValue({ type: 'TYPE' });
|
|
const mockSetAccountLabel = jest.fn().mockReturnValue({ type: 'TYPE' });
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
addNewAccount: (...args) => mockAddNewAccount(...args),
|
|
setAccountLabel: (...args) => mockSetAccountLabel(...args),
|
|
}));
|
|
|
|
describe('CreateAccount', () => {
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('displays account name input and suggests name', () => {
|
|
const { getByPlaceholderText } = render();
|
|
|
|
expect(getByPlaceholderText('Account 5')).toBeInTheDocument();
|
|
});
|
|
|
|
it('fires onActionComplete when clicked', async () => {
|
|
const onActionComplete = jest.fn();
|
|
const { getByText, getByPlaceholderText } = render({ onActionComplete });
|
|
|
|
const input = getByPlaceholderText('Account 5');
|
|
const newAccountName = 'New Account Name';
|
|
|
|
fireEvent.change(input, {
|
|
target: { value: newAccountName },
|
|
});
|
|
fireEvent.click(getByText('Create'));
|
|
|
|
await waitFor(() => expect(mockAddNewAccount).toHaveBeenCalled());
|
|
await waitFor(() =>
|
|
expect(mockSetAccountLabel).toHaveBeenCalledWith(
|
|
{ type: 'TYPE' },
|
|
newAccountName,
|
|
),
|
|
);
|
|
await waitFor(() => expect(onActionComplete).toHaveBeenCalled());
|
|
});
|
|
|
|
it(`doesn't allow duplicate account names`, async () => {
|
|
const { getByText, getByPlaceholderText } = render();
|
|
|
|
const input = getByPlaceholderText('Account 5');
|
|
const usedAccountName = 'Account 4';
|
|
|
|
fireEvent.change(input, {
|
|
target: { value: usedAccountName },
|
|
});
|
|
|
|
const submitButton = getByText('Create');
|
|
expect(submitButton).toHaveAttribute('disabled');
|
|
});
|
|
});
|