2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import configureStore from 'redux-mock-store';
|
2022-08-08 22:28:49 +02:00
|
|
|
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
2023-01-20 16:14:40 +01:00
|
|
|
import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
2021-03-16 22:00:08 +01:00
|
|
|
import MenuBar from './menu-bar';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-04-01 18:35:07 +02:00
|
|
|
const initState = {
|
2020-07-10 17:46:54 +02:00
|
|
|
activeTab: {},
|
2020-04-01 18:35:07 +02:00
|
|
|
metamask: {
|
2021-03-10 18:21:52 +01:00
|
|
|
provider: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: CHAIN_IDS.GOERLI,
|
2021-03-10 18:21:52 +01:00
|
|
|
},
|
2020-04-01 18:35:07 +02:00
|
|
|
selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
identities: {
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
|
|
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
name: 'Account 1',
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
},
|
2020-04-01 18:35:07 +02:00
|
|
|
keyrings: [
|
|
|
|
{
|
2023-01-20 16:14:40 +01:00
|
|
|
type: HardwareKeyringTypes.hdKeyTree,
|
2020-11-03 00:41:28 +01:00
|
|
|
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2020-04-01 18:35:07 +02:00
|
|
|
],
|
2023-03-09 22:00:28 +01:00
|
|
|
networkConfigurations: {},
|
2020-04-01 18:35:07 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const mockStore = configureStore();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('MenuBar', () => {
|
2021-05-20 20:28:25 +02:00
|
|
|
it('opens account detail menu when account options is clicked', async () => {
|
2022-08-08 22:28:49 +02:00
|
|
|
let accountOptionsMenu;
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore(initState);
|
2022-08-08 22:28:49 +02:00
|
|
|
renderWithProvider(<MenuBar />, store);
|
|
|
|
|
|
|
|
accountOptionsMenu = screen.queryByTestId('account-options-menu');
|
|
|
|
expect(accountOptionsMenu).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
const accountOptions = screen.queryByTestId('account-options-menu-button');
|
|
|
|
fireEvent.click(accountOptions);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
accountOptionsMenu = screen.queryByTestId('account-options-menu');
|
|
|
|
expect(accountOptionsMenu).toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-08-08 22:28:49 +02:00
|
|
|
it('shouldnt open the account options menu when clicked twice', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore(initState);
|
2022-08-08 22:28:49 +02:00
|
|
|
renderWithProvider(<MenuBar />, store);
|
|
|
|
|
|
|
|
const accountOptionsMenu = screen.queryByTestId('account-options-menu');
|
|
|
|
expect(accountOptionsMenu).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
const accountOptionsButton = screen.queryByTestId(
|
|
|
|
'account-options-menu-button',
|
2021-05-20 20:28:25 +02:00
|
|
|
);
|
2022-08-08 22:28:49 +02:00
|
|
|
// Couldnt fireEvent multiple/seperate times, this is the workaround.
|
|
|
|
fireEvent.doubleClick(accountOptionsButton);
|
|
|
|
|
|
|
|
expect(accountOptionsMenu).not.toBeInTheDocument();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|