1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/components/multichain/network-list-menu/network-list-menu.test.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-03-31 19:58:25 +02:00
/* eslint-disable jest/require-top-level-describe */
import React from 'react';
import { fireEvent, renderWithProvider } from '../../../../test/jest';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import {
MAINNET_DISPLAY_NAME,
SEPOLIA_DISPLAY_NAME,
} from '../../../../shared/constants/network';
import { NetworkListMenu } from '.';
const mockSetShowTestNetworks = jest.fn();
const mockSetProviderType = jest.fn();
const mockToggleNetworkMenu = jest.fn();
2023-03-31 19:58:25 +02:00
jest.mock('../../../store/actions.ts', () => ({
setShowTestNetworks: () => mockSetShowTestNetworks,
setProviderType: () => mockSetProviderType,
toggleNetworkMenu: () => mockToggleNetworkMenu,
2023-03-31 19:58:25 +02:00
}));
const render = (showTestNetworks = false) => {
const store = configureStore({
metamask: {
...mockState.metamask,
preferences: {
showTestNetworks,
},
},
});
return renderWithProvider(<NetworkListMenu onClose={jest.fn()} />, store);
2023-03-31 19:58:25 +02:00
};
describe('NetworkListMenu', () => {
it('displays important controls', () => {
const { getByText } = render();
expect(getByText('Add network')).toBeInTheDocument();
expect(getByText('Show test networks')).toBeInTheDocument();
});
it('renders mainnet item', () => {
const { getByText } = render();
expect(getByText(MAINNET_DISPLAY_NAME)).toBeInTheDocument();
});
it('renders test networks when it should', () => {
const { getByText } = render(true);
expect(getByText(SEPOLIA_DISPLAY_NAME)).toBeInTheDocument();
});
it('toggles showTestNetworks when toggle is clicked', () => {
const { queryAllByRole } = render();
const [testNetworkToggle] = queryAllByRole('checkbox');
fireEvent.click(testNetworkToggle);
expect(mockSetShowTestNetworks).toHaveBeenCalled();
});
it('switches networks when an item is clicked', () => {
const { getByText } = render();
fireEvent.click(getByText(MAINNET_DISPLAY_NAME));
expect(mockToggleNetworkMenu).toHaveBeenCalled();
2023-03-31 19:58:25 +02:00
expect(mockSetProviderType).toHaveBeenCalled();
});
});