1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 04:37:13 +01:00
metamask-extension/ui/components/app/dropdowns/network-dropdown.test.js

113 lines
3.7 KiB
JavaScript
Raw Normal View History

import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { mountWithRouter } from '../../../../test/lib/render-helpers';
import ColorIndicator from '../../ui/color-indicator';
import NetworkDropdown from './network-dropdown';
import { DropdownMenuItem } from './dropdown';
2018-09-24 18:28:04 +02:00
describe('Network Dropdown', () => {
let wrapper;
const createMockStore = configureMockStore([thunk]);
2018-09-24 18:28:04 +02:00
describe('NetworkDropdown in appState in false', () => {
2018-09-24 18:28:04 +02:00
const mockState = {
metamask: {
network: '1',
2018-09-24 18:28:04 +02:00
provider: {
type: 'test',
},
},
appState: {
networkDropdownOpen: false,
2018-09-24 18:28:04 +02:00
},
};
2018-09-24 18:28:04 +02:00
const store = createMockStore(mockState);
2018-09-24 18:28:04 +02:00
beforeEach(() => {
wrapper = mountWithRouter(<NetworkDropdown store={store} />);
});
2018-09-24 18:28:04 +02:00
it('checks for network droppo class', () => {
expect(wrapper.find('.network-droppo')).toHaveLength(1);
});
2018-09-24 18:28:04 +02:00
it('renders only one child when networkDropdown is false in state', () => {
expect(wrapper.children()).toHaveLength(1);
});
});
2018-09-24 18:28:04 +02:00
describe('NetworkDropdown in appState is true', () => {
2018-09-24 18:28:04 +02:00
const mockState = {
metamask: {
network: '1',
2018-09-24 18:28:04 +02:00
provider: {
2020-11-03 00:41:28 +01:00
type: 'test',
2018-09-24 18:28:04 +02:00
},
frequentRpcListDetail: [
{ chainId: '0x1a', rpcUrl: 'http://localhost:7545' },
{ rpcUrl: 'http://localhost:7546' },
2018-09-24 18:28:04 +02:00
],
},
appState: {
2020-11-03 00:41:28 +01:00
networkDropdownOpen: true,
2018-09-24 18:28:04 +02:00
},
};
const store = createMockStore(mockState);
2018-09-24 18:28:04 +02:00
beforeEach(() => {
wrapper = mountWithRouter(<NetworkDropdown store={store} />);
});
2018-09-24 18:28:04 +02:00
it('renders 8 DropDownMenuItems', () => {
expect(wrapper.find(DropdownMenuItem)).toHaveLength(8);
});
2018-09-24 18:28:04 +02:00
it('checks background color for first ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(0);
expect(colorIndicator.prop('color')).toStrictEqual('mainnet');
expect(colorIndicator.prop('borderColor')).toStrictEqual('mainnet');
});
2018-09-24 18:28:04 +02:00
it('checks background color for second ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(1);
expect(colorIndicator.prop('color')).toStrictEqual('ropsten');
expect(colorIndicator.prop('borderColor')).toStrictEqual('ropsten');
});
2018-09-24 18:28:04 +02:00
it('checks background color for third ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(2);
expect(colorIndicator.prop('color')).toStrictEqual('kovan');
expect(colorIndicator.prop('borderColor')).toStrictEqual('kovan');
});
2018-09-24 18:28:04 +02:00
it('checks background color for fourth ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(3);
expect(colorIndicator.prop('color')).toStrictEqual('rinkeby');
expect(colorIndicator.prop('borderColor')).toStrictEqual('rinkeby');
});
2018-09-24 18:28:04 +02:00
it('checks background color for fifth ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(4);
expect(colorIndicator.prop('color')).toStrictEqual('goerli');
expect(colorIndicator.prop('borderColor')).toStrictEqual('goerli');
});
2019-04-17 19:34:49 +02:00
it('checks background color for sixth ColorIndicator', () => {
const colorIndicator = wrapper.find(ColorIndicator).at(5);
const customNetworkGray = 'ui-2';
expect(colorIndicator.prop('color')).toStrictEqual(customNetworkGray);
expect(colorIndicator.prop('borderColor')).toStrictEqual(
customNetworkGray,
);
});
2018-09-24 18:28:04 +02:00
it('checks dropdown for frequestRPCList from state', () => {
expect(wrapper.find(DropdownMenuItem).at(6).text()).toStrictEqual(
2020-11-03 00:41:28 +01:00
'✓http://localhost:7545',
);
});
});
});