2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import thunk from 'redux-thunk';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
import { tick } from '../../../../../test/lib/tick';
|
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
import * as actions from '../../../../store/actions';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { KOVAN_CHAIN_ID } from '../../../../../shared/constants/network';
|
2021-03-16 22:00:08 +01:00
|
|
|
import UnconnectedAccountAlert from '.';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Unconnected Account Alert', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedAddress = '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b';
|
2020-08-20 06:13:59 +02:00
|
|
|
|
|
|
|
const identities = {
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
|
|
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
name: 'Account 1',
|
|
|
|
},
|
|
|
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': {
|
|
|
|
address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
|
|
|
name: 'Account 2',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-20 06:13:59 +02:00
|
|
|
|
|
|
|
const accounts = {
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
|
|
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': {
|
|
|
|
address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-20 06:13:59 +02:00
|
|
|
|
|
|
|
const cachedBalances = {
|
2021-03-02 23:53:07 +01:00
|
|
|
[KOVAN_CHAIN_ID]: {
|
2020-08-20 06:13:59 +02:00
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': '0x0',
|
|
|
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': '0x0',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-20 06:13:59 +02:00
|
|
|
|
|
|
|
const keyrings = [
|
|
|
|
{
|
|
|
|
type: 'HD Key Tree',
|
|
|
|
accounts: [
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
|
|
|
],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-08-20 06:13:59 +02:00
|
|
|
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
|
|
|
selectedAddress,
|
|
|
|
identities,
|
|
|
|
accounts,
|
|
|
|
cachedBalances,
|
|
|
|
keyrings,
|
2021-03-02 23:53:07 +01:00
|
|
|
provider: {
|
|
|
|
chainId: KOVAN_CHAIN_ID,
|
|
|
|
},
|
2020-08-20 06:13:59 +02:00
|
|
|
permissionsHistory: {
|
|
|
|
'https://test.dapp': {
|
|
|
|
eth_accounts: {
|
|
|
|
accounts: {
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': 1596681857076,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
domains: {
|
|
|
|
'https://test.dapp': {
|
|
|
|
permissions: [
|
|
|
|
{
|
|
|
|
caveats: [
|
|
|
|
{
|
|
|
|
name: 'primaryAccountOnly',
|
|
|
|
type: 'limitResponseLength',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'exposedAccounts',
|
|
|
|
type: 'filterResponse',
|
2020-11-03 00:41:28 +01:00
|
|
|
value: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
2020-08-20 06:13:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
invoker: 'https://test.dapp',
|
|
|
|
parentCapability: 'eth_accounts',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeTab: {
|
|
|
|
origin: 'https://test.dapp',
|
|
|
|
},
|
|
|
|
unconnectedAccount: {
|
|
|
|
state: 'OPEN',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('checks that checkbox is checked', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = configureMockStore()(mockState);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { getByRole } = renderWithProvider(
|
|
|
|
<UnconnectedAccountAlert />,
|
|
|
|
store,
|
|
|
|
);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const dontShowCheckbox = getByRole('checkbox');
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dontShowCheckbox.checked).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
fireEvent.click(dontShowCheckbox);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dontShowCheckbox.checked).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('clicks dismiss button and calls dismissAlert action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = configureMockStore()(mockState);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<UnconnectedAccountAlert />,
|
|
|
|
store,
|
|
|
|
);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-23 00:31:13 +02:00
|
|
|
const dismissButton = getByText(/Dismiss/u);
|
2021-02-04 19:15:23 +01:00
|
|
|
fireEvent.click(dismissButton);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()[0].type).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'unconnectedAccount/dismissAlert',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('clicks Dont Show checkbox and dismiss to call disable alert request action', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.stub(actions, 'setAlertEnabledness').returns(() => Promise.resolve());
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = configureMockStore([thunk])(mockState);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const { getByText, getByRole } = renderWithProvider(
|
|
|
|
<UnconnectedAccountAlert />,
|
|
|
|
store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-23 00:31:13 +02:00
|
|
|
const dismissButton = getByText(/Dismiss/u);
|
2021-02-04 19:15:23 +01:00
|
|
|
const dontShowCheckbox = getByRole('checkbox');
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
fireEvent.click(dontShowCheckbox);
|
|
|
|
fireEvent.click(dismissButton);
|
2020-08-20 06:13:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await tick();
|
|
|
|
|
|
|
|
expect(store.getActions()[0].type).toStrictEqual(
|
|
|
|
'unconnectedAccount/disableAlertRequested',
|
|
|
|
);
|
|
|
|
expect(store.getActions()[1].type).toStrictEqual(
|
|
|
|
'unconnectedAccount/disableAlertSucceeded',
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|