2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { Provider } from 'react-redux';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { mountWithRouter } from '../../../../test/lib/render-helpers';
|
2021-03-16 22:00:08 +01:00
|
|
|
import AccountMenu from '.';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Account Menu', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const mockStore = {
|
|
|
|
metamask: {
|
|
|
|
provider: {
|
|
|
|
type: 'test',
|
|
|
|
},
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = configureMockStore()(mockStore);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
isAccountMenuOpen: true,
|
|
|
|
addressConnectedDomainMap: {},
|
|
|
|
accounts: [
|
|
|
|
{
|
2021-04-16 17:05:13 +02:00
|
|
|
address: '0x00',
|
2020-01-30 20:34:45 +01:00
|
|
|
name: 'Account 1',
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
{
|
2021-04-16 17:05:13 +02:00
|
|
|
address: '0x1',
|
2020-01-30 20:34:45 +01:00
|
|
|
name: 'Imported Account 1',
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
keyrings: [
|
|
|
|
{
|
|
|
|
type: 'HD Key Tree',
|
2020-11-03 00:41:28 +01:00
|
|
|
accounts: ['0xAdress'],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Simple Key Pair',
|
2021-04-16 17:05:13 +02:00
|
|
|
accounts: ['0x1'],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
prevIsAccountMenuOpen: false,
|
|
|
|
lockMetamask: sinon.spy(),
|
|
|
|
showAccountDetail: sinon.spy(),
|
|
|
|
showRemoveAccountConfirmationModal: sinon.spy(),
|
|
|
|
toggleAccountMenu: sinon.spy(),
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeAll(() => {
|
2020-01-30 20:34:45 +01:00
|
|
|
wrapper = mountWithRouter(
|
|
|
|
<Provider store={store}>
|
|
|
|
<AccountMenu.WrappedComponent {...props} />
|
2020-11-03 00:41:28 +01:00
|
|
|
</Provider>,
|
|
|
|
store,
|
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();
|
|
|
|
props.history.push.resetHistory();
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Render Content', () => {
|
|
|
|
it('returns account name from identities', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const accountName = wrapper.find('.account-menu__name');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(accountName).toHaveLength(2);
|
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('renders user preference currency display balance from account balance', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const accountBalance = wrapper.find(
|
|
|
|
'.currency-display-component.account-menu__balance',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(accountBalance).toHaveLength(2);
|
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('simulate click', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const click = wrapper.find(
|
|
|
|
'.account-menu__account.account-menu__item--clickable',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
click.first().simulate('click');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.showAccountDetail.calledOnce).toStrictEqual(true);
|
2021-04-16 17:05:13 +02:00
|
|
|
expect(props.showAccountDetail.getCall(0).args[0]).toStrictEqual('0x00');
|
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('render imported account label', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const importedAccount = wrapper.find('.keyring-label.allcaps');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(importedAccount.text()).toStrictEqual('imported');
|
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('Log Out', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let logout;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('logout', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
logout = wrapper.find('.account-menu__lock-button');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(logout).toHaveLength(1);
|
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('simulate click', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
logout.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.lockMetamask.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('Create Account', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let createAccount;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders create account item', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
createAccount = wrapper.find({ text: 'createAccount' });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(createAccount).toHaveLength(1);
|
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('calls toggle menu and push new-account route to history', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
createAccount.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual(
|
|
|
|
'/new-account',
|
|
|
|
);
|
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('Import Account', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let importAccount;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders import account item', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
importAccount = wrapper.find({ text: 'importAccount' });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(importAccount).toHaveLength(1);
|
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('calls toggle menu and push /new-account/import route to history', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
importAccount.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual(
|
|
|
|
'/new-account/import',
|
|
|
|
);
|
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('Connect Hardware Wallet', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let connectHardwareWallet;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders import account item', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
connectHardwareWallet = wrapper.find({ text: 'connectHardwareWallet' });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(connectHardwareWallet).toHaveLength(1);
|
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('calls toggle menu and push /new-account/connect route to history', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
connectHardwareWallet.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'/new-account/connect',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-23 00:31:13 +02:00
|
|
|
describe('Support', () => {
|
|
|
|
let support;
|
|
|
|
global.platform = { openTab: sinon.spy() };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders import account item', () => {
|
2021-04-23 00:31:13 +02:00
|
|
|
support = wrapper.find({ text: 'support' });
|
|
|
|
expect(support).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-23 00:31:13 +02:00
|
|
|
it('opens support link when clicked', () => {
|
|
|
|
support = wrapper.find({ text: 'support' });
|
|
|
|
support.simulate('click');
|
|
|
|
expect(global.platform.openTab.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
|
|
|
describe('Settings', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let settings;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders import account item', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
settings = wrapper.find({ text: 'settings' });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(settings).toHaveLength(1);
|
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('calls toggle menu and push /new-account/connect route to history', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
settings.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.toggleAccountMenu.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual('/settings');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|