1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/pages/settings/networks-tab/networks-tab-content/networks-tab-content.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

99 lines
3.1 KiB
JavaScript

import React from 'react';
import configureMockStore from 'redux-mock-store';
import { fireEvent, screen } from '@testing-library/react';
import { renderWithProvider } from '../../../../../test/jest/rendering';
import { defaultNetworksData } from '../networks-tab.constants';
import NetworksTabContent from '.';
const mockState = {
metamask: {
provider: {
chainId: '0x539',
nickname: '',
rpcPrefs: {},
rpcUrl: 'http://localhost:8545',
ticker: 'ETH',
type: 'localhost',
},
},
};
const renderComponent = (props) => {
const store = configureMockStore([])(mockState);
return renderWithProvider(<NetworksTabContent {...props} />, store);
};
const defaultNetworks = defaultNetworksData.map((network) => ({
...network,
viewOnly: true,
isATestNetwork: true,
}));
const props = {
networkDefaultedToProvider: false,
networkIsSelected: true,
networksToRender: defaultNetworks,
selectedNetwork: {
rpcUrl: 'http://localhost:8545',
chainId: '1337',
ticker: 'ETH',
label: 'LocalHost',
blockExplorerUrl: '',
viewOnly: false,
rpcPrefs: {},
isATestNetwork: true,
},
shouldRenderNetworkForm: true,
};
describe('NetworksTabContent Component', () => {
it('should render networks tab content correctly', async () => {
const { queryByText, getByDisplayValue, getAllByText } =
renderComponent(props);
expect(queryByText('Ethereum Mainnet')).toBeInTheDocument();
expect(queryByText('Goerli test network')).toBeInTheDocument();
expect(queryByText('Sepolia test network')).toBeInTheDocument();
expect(queryByText('Network name')).toBeInTheDocument();
expect(queryByText('New RPC URL')).toBeInTheDocument();
expect(queryByText('Chain ID')).toBeInTheDocument();
expect(queryByText('Currency symbol')).toBeInTheDocument();
expect(queryByText('Block explorer URL')).toBeInTheDocument();
expect(queryByText('Cancel')).toBeInTheDocument();
expect(queryByText('Save')).toBeInTheDocument();
expect(getByDisplayValue(props.selectedNetwork.label)).toBeInTheDocument();
expect(getByDisplayValue(props.selectedNetwork.rpcUrl)).toBeInTheDocument();
expect(
getByDisplayValue(props.selectedNetwork.chainId),
).toBeInTheDocument();
expect(getByDisplayValue(props.selectedNetwork.ticker)).toBeInTheDocument();
expect(getAllByText(props.selectedNetwork.blockExplorerUrl)).toBeDefined();
fireEvent.change(getByDisplayValue(props.selectedNetwork.label), {
target: { value: 'LocalHost 8545' },
});
expect(await getByDisplayValue('LocalHost 8545')).toBeInTheDocument();
fireEvent.change(getByDisplayValue(props.selectedNetwork.rpcUrl), {
target: { value: 'test' },
});
expect(
await screen.findByText(
'URLs require the appropriate HTTP/HTTPS prefix.',
),
).toBeInTheDocument();
fireEvent.change(getByDisplayValue(props.selectedNetwork.chainId), {
target: { value: '1' },
});
expect(
await screen.findByText(
'Could not fetch chain ID. Is your RPC URL correct?',
),
).toBeInTheDocument();
});
});