2023-03-28 21:59:18 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { renderWithProvider, fireEvent, waitFor } from '../../../../test/jest';
|
|
|
|
import configureStore from '../../../store/store';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
|
|
import { GlobalMenu } from '.';
|
|
|
|
|
2023-06-14 20:49:14 +02:00
|
|
|
const render = (metamaskStateChanges = {}) => {
|
2023-03-28 21:59:18 +02:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
2023-06-14 20:49:14 +02:00
|
|
|
...metamaskStateChanges,
|
2023-03-28 21:59:18 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return renderWithProvider(
|
|
|
|
<GlobalMenu anchorElement={document.body} closeMenu={() => undefined} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockLockMetaMask = jest.fn();
|
2023-07-19 00:01:07 +02:00
|
|
|
const mockSetAccountDetailsAddress = jest.fn();
|
2023-03-28 21:59:18 +02:00
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
lockMetamask: () => mockLockMetaMask,
|
2023-07-19 00:01:07 +02:00
|
|
|
setAccountDetailsAddress: () => mockSetAccountDetailsAddress,
|
2023-03-28 21:59:18 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('AccountListItem', () => {
|
|
|
|
it('locks MetaMask when item is clicked', async () => {
|
|
|
|
render();
|
|
|
|
fireEvent.click(document.querySelector('[data-testid="global-menu-lock"]'));
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(mockLockMetaMask).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens the portfolio site when item is clicked', async () => {
|
|
|
|
global.platform = { openTab: jest.fn() };
|
|
|
|
|
|
|
|
const { getByTestId } = render();
|
|
|
|
fireEvent.click(getByTestId('global-menu-portfolio'));
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openTab).toHaveBeenCalledWith({
|
2023-04-27 16:28:08 +02:00
|
|
|
url: `/?metamaskEntry=ext&metametricsId=`,
|
2023-03-28 21:59:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens the support site when item is clicked', async () => {
|
|
|
|
global.platform = { openTab: jest.fn() };
|
|
|
|
|
|
|
|
const { getByTestId } = render();
|
|
|
|
fireEvent.click(getByTestId('global-menu-support'));
|
|
|
|
await waitFor(() => {
|
2023-06-06 18:02:00 +02:00
|
|
|
expect(global.platform.openTab).toHaveBeenCalled();
|
2023-03-28 21:59:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-14 20:49:14 +02:00
|
|
|
it('disables the settings item when there is an active transaction', async () => {
|
|
|
|
const { getByTestId } = render();
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(getByTestId('global-menu-settings')).toBeDisabled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables the settings item when there is no active transaction', async () => {
|
|
|
|
const { getByTestId } = render({ unapprovedTxs: {} });
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(getByTestId('global-menu-settings')).toBeEnabled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-15 15:36:28 +02:00
|
|
|
it('disables the connected sites item when there is an active transaction', async () => {
|
|
|
|
const { getByTestId } = render();
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(getByTestId('global-menu-connected-sites')).toBeDisabled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables the connected sites item when there is no active transaction', async () => {
|
|
|
|
const { getByTestId } = render({ unapprovedTxs: {} });
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(getByTestId('global-menu-connected-sites')).toBeEnabled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-28 21:59:18 +02:00
|
|
|
it('expands metamask to tab when item is clicked', async () => {
|
|
|
|
global.platform = { openExtensionInBrowser: jest.fn() };
|
|
|
|
|
|
|
|
render();
|
|
|
|
fireEvent.click(
|
|
|
|
document.querySelector('[data-testid="global-menu-expand"]'),
|
|
|
|
);
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(global.platform.openExtensionInBrowser).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|