1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/components/app/dropdowns/network-dropdown.test.js
ryanml 0bc1eeaf37
Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989)
* Deprecating Rinkeby, setting default debug network to Goerli

* Deprecating Ropsten and Kovan

* Conflict fix

* Remove unused localization, test fixes

* Add migration for moving used deprecated testnets to custom networks

* Fix migrator test

* Add more unit tests

* Migration updates provider type to rpc if deprecated network is selected

* Migration fully and correctly updates the provider if selected network is a deprecated testnet

* Continue to show deprecation warning on each of rinkeby, ropsten and kovan

* Add rpcUrl deprecation message to loading screen

* Removing mayBeFauceting prop

Co-authored-by: Dan Miller <danjm.com@gmail.com>
2022-09-28 20:26:01 -07:00

160 lines
4.7 KiB
JavaScript

import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { screen } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { LOCALHOST_RPC_URL } from '../../../../shared/constants/network';
import NetworkDropdown from './network-dropdown';
describe('Network Dropdown', () => {
const createMockStore = configureMockStore([thunk]);
describe('NetworkDropdown in appState in false', () => {
const mockState = {
metamask: {
network: '1',
provider: {
type: 'test',
},
showTestnetMessageInDropdown: false,
preferences: {
showTestNetworks: true,
},
},
appState: {
networkDropdownOpen: false,
},
};
const store = createMockStore(mockState);
beforeEach(() => {
renderWithProvider(<NetworkDropdown />, store);
});
it('should not render menu dropdown when network dropdown is in false state', () => {
const menuDropdown = screen.queryByTestId('menu-dropdown');
expect(menuDropdown).not.toBeInTheDocument();
});
it('checks for network droppo class', () => {
const networkDropdown = screen.queryByTestId('network-droppo');
expect(networkDropdown).toBeInTheDocument();
});
});
describe('NetworkDropdown in appState is true and show test networks is true', () => {
const mockState = {
metamask: {
network: '1',
provider: {
type: 'test',
},
showTestnetMessageInDropdown: false,
preferences: {
showTestNetworks: true,
},
frequentRpcListDetail: [
{ chainId: '0x1a', rpcUrl: 'http://localhost:7545' },
{ rpcUrl: 'http://localhost:7546' },
{ rpcUrl: LOCALHOST_RPC_URL, nickname: 'localhost' },
],
},
appState: {
networkDropdownOpen: true,
},
};
global.platform = {
openExtensionInBrowser: jest.fn(),
};
const store = createMockStore(mockState);
beforeEach(() => {
renderWithProvider(<NetworkDropdown />, store);
});
it('checks background color for first ColorIndicator', () => {
const mainnetColorIndicator = screen.queryByTestId('color-icon-mainnet');
expect(mainnetColorIndicator).toBeInTheDocument();
});
it('checks background color for fourth ColorIndicator', () => {
const goerliColorIndicator = screen.queryByTestId('color-icon-goerli');
expect(goerliColorIndicator).toBeInTheDocument();
});
it('checks background color for fifth ColorIndicator', () => {
const sepoliaColorIndicator = screen.queryByTestId('color-icon-sepolia');
expect(sepoliaColorIndicator).toBeInTheDocument();
});
it('checks background color for sixth ColorIndicator', () => {
const localhostColorIndicator = screen.queryByTestId(
'color-icon-localhost',
);
expect(localhostColorIndicator).toBeInTheDocument();
});
it('checks that Add Network button is rendered', () => {
const addNetworkButton = screen.queryByText('Add network');
expect(addNetworkButton).toBeInTheDocument();
});
it('shows test networks in the dropdown', () => {
const networkItems = screen.queryAllByTestId(/network-item/u);
expect(networkItems).toHaveLength(6);
});
});
describe('NetworkDropdown in appState is true and show test networks is false', () => {
const mockState = {
metamask: {
network: '1',
provider: {
type: 'test',
},
showTestnetMessageInDropdown: false,
preferences: {
showTestNetworks: false,
},
frequentRpcListDetail: [
{ chainId: '0x1a', rpcUrl: 'http://localhost:7545' },
{ rpcUrl: 'http://localhost:7546' },
],
},
appState: {
networkDropdownOpen: true,
},
};
global.platform = {
openExtensionInBrowser: jest.fn(),
};
const store = createMockStore(mockState);
beforeEach(() => {
renderWithProvider(<NetworkDropdown />, store);
});
it('checks background color for first ColorIndicator', () => {
const mainnetColorIndicator = screen.queryByTestId('color-icon-mainnet');
expect(mainnetColorIndicator).toBeInTheDocument();
});
it('checks that Add Network button is rendered', () => {
const addNetworkButton = screen.queryByText('Add network');
expect(addNetworkButton).toBeInTheDocument();
});
it('does not show test networks in the dropdown', () => {
const networkItems = screen.queryAllByTestId(/network-item/u);
expect(networkItems).toHaveLength(3);
});
});
});