2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { shallow } from 'enzyme';
|
2021-03-16 22:00:08 +01:00
|
|
|
import MetaFoxLogo from '../../ui/metafox-logo';
|
|
|
|
import NetworkDisplay from '../network-display';
|
|
|
|
import AppHeader from './app-header.container';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('App Header', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
hideNetworkDropdown: sinon.spy(),
|
|
|
|
showNetworkDropdown: sinon.spy(),
|
|
|
|
toggleAccountMenu: sinon.spy(),
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
|
|
|
network: 'test',
|
|
|
|
provider: {},
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
disabled: false,
|
|
|
|
hideNetworkIndicator: false,
|
|
|
|
networkDropdownOpen: false,
|
|
|
|
isAccountMenuOpen: false,
|
|
|
|
isUnlocked: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(<AppHeader.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: () => undefined,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
props.toggleAccountMenu.resetHistory();
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('App Header Logo', () => {
|
|
|
|
it('routes to default route when logo is clicked', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const appLogo = wrapper.find(MetaFoxLogo);
|
|
|
|
appLogo.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.history.push.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual('/');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Network', () => {
|
|
|
|
it('shows network dropdown when networkDropdownOpen is false', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const network = wrapper.find(NetworkDisplay);
|
2020-01-30 20:34:45 +01:00
|
|
|
network.simulate('click', {
|
2020-08-14 13:47:02 +02:00
|
|
|
preventDefault: () => undefined,
|
|
|
|
stopPropagation: () => undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.showNetworkDropdown.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('hides network dropdown when networkDropdownOpen is true', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ networkDropdownOpen: true });
|
|
|
|
const network = wrapper.find(NetworkDisplay);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
network.simulate('click', {
|
2020-08-14 13:47:02 +02:00
|
|
|
preventDefault: () => undefined,
|
|
|
|
stopPropagation: () => undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.hideNetworkDropdown.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('hides network indicator', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ hideNetworkIndicator: true });
|
2021-04-15 20:01:46 +02:00
|
|
|
const network = wrapper.find(NetworkDisplay);
|
|
|
|
expect(network).toHaveLength(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Account Menu', () => {
|
|
|
|
it('toggles account menu', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const accountMenu = wrapper.find('.account-menu__icon');
|
|
|
|
accountMenu.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('does not toggle account menu when disabled', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ disabled: true });
|
|
|
|
const accountMenu = wrapper.find('.account-menu__icon');
|
|
|
|
accountMenu.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.notCalled).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|