You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
4.4 KiB
169 lines
4.4 KiB
4 years ago
|
import React from 'react';
|
||
4 years ago
|
|
||
4 years ago
|
import sinon from 'sinon';
|
||
|
import thunk from 'redux-thunk';
|
||
4 years ago
|
|
||
4 years ago
|
import { fireEvent } from '@testing-library/react';
|
||
|
import configureMockStore from 'redux-mock-store';
|
||
4 years ago
|
|
||
4 years ago
|
import { tick } from '../../../../../test/lib/tick';
|
||
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
||
4 years ago
|
|
||
4 years ago
|
import * as actions from '../../../../store/actions';
|
||
4 years ago
|
import { KOVAN_CHAIN_ID } from '../../../../../shared/constants/network';
|
||
4 years ago
|
import UnconnectedAccountAlert from '.';
|
||
4 years ago
|
|
||
4 years ago
|
describe('Unconnected Account Alert', () => {
|
||
4 years ago
|
const selectedAddress = '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b';
|
||
4 years ago
|
|
||
|
const identities = {
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
||
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
name: 'Account 1',
|
||
|
},
|
||
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': {
|
||
|
address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
||
|
name: 'Account 2',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
|
const accounts = {
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
|
||
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
balance: '0x0',
|
||
|
},
|
||
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': {
|
||
|
address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
||
|
balance: '0x0',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
|
const cachedBalances = {
|
||
4 years ago
|
[KOVAN_CHAIN_ID]: {
|
||
4 years ago
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': '0x0',
|
||
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': '0x0',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
|
const keyrings = [
|
||
|
{
|
||
|
type: 'HD Key Tree',
|
||
|
accounts: [
|
||
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||
|
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
||
|
],
|
||
|
},
|
||
4 years ago
|
];
|
||
4 years ago
|
|
||
|
const mockState = {
|
||
|
metamask: {
|
||
|
selectedAddress,
|
||
|
identities,
|
||
|
accounts,
|
||
|
cachedBalances,
|
||
|
keyrings,
|
||
4 years ago
|
provider: {
|
||
|
chainId: KOVAN_CHAIN_ID,
|
||
|
},
|
||
4 years ago
|
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',
|
||
4 years ago
|
value: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||
4 years ago
|
},
|
||
|
],
|
||
|
invoker: 'https://test.dapp',
|
||
|
parentCapability: 'eth_accounts',
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
activeTab: {
|
||
|
origin: 'https://test.dapp',
|
||
|
},
|
||
|
unconnectedAccount: {
|
||
|
state: 'OPEN',
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('checks that checkbox is checked', () => {
|
||
4 years ago
|
const store = configureMockStore()(mockState);
|
||
4 years ago
|
|
||
4 years ago
|
const { getByRole } = renderWithProvider(
|
||
|
<UnconnectedAccountAlert />,
|
||
|
store,
|
||
|
);
|
||
4 years ago
|
|
||
4 years ago
|
const dontShowCheckbox = getByRole('checkbox');
|
||
4 years ago
|
|
||
4 years ago
|
expect(dontShowCheckbox.checked).toStrictEqual(false);
|
||
4 years ago
|
fireEvent.click(dontShowCheckbox);
|
||
4 years ago
|
expect(dontShowCheckbox.checked).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('clicks dismiss button and calls dismissAlert action', () => {
|
||
4 years ago
|
const store = configureMockStore()(mockState);
|
||
4 years ago
|
|
||
4 years ago
|
const { getByText } = renderWithProvider(
|
||
|
<UnconnectedAccountAlert />,
|
||
|
store,
|
||
|
);
|
||
4 years ago
|
|
||
4 years ago
|
const dismissButton = getByText(/Dismiss/u);
|
||
4 years ago
|
fireEvent.click(dismissButton);
|
||
4 years ago
|
|
||
4 years ago
|
expect(store.getActions()[0].type).toStrictEqual(
|
||
4 years ago
|
'unconnectedAccount/dismissAlert',
|
||
4 years ago
|
);
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('clicks Dont Show checkbox and dismiss to call disable alert request action', async () => {
|
||
4 years ago
|
sinon.stub(actions, 'setAlertEnabledness').returns(() => Promise.resolve());
|
||
4 years ago
|
|
||
4 years ago
|
const store = configureMockStore([thunk])(mockState);
|
||
4 years ago
|
|
||
4 years ago
|
const { getByText, getByRole } = renderWithProvider(
|
||
|
<UnconnectedAccountAlert />,
|
||
|
store,
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
4 years ago
|
const dismissButton = getByText(/Dismiss/u);
|
||
4 years ago
|
const dontShowCheckbox = getByRole('checkbox');
|
||
4 years ago
|
|
||
4 years ago
|
fireEvent.click(dontShowCheckbox);
|
||
|
fireEvent.click(dismissButton);
|
||
4 years ago
|
|
||
4 years ago
|
await tick();
|
||
|
|
||
|
expect(store.getActions()[0].type).toStrictEqual(
|
||
|
'unconnectedAccount/disableAlertRequested',
|
||
|
);
|
||
|
expect(store.getActions()[1].type).toStrictEqual(
|
||
|
'unconnectedAccount/disableAlertSucceeded',
|
||
|
);
|
||
4 years ago
|
});
|
||
|
});
|