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 TextField from '../../../components/ui/text-field';
|
2021-10-21 21:17:03 +02:00
|
|
|
import { LEDGER_TRANSPORT_TYPES } from '../../../../shared/constants/hardware-wallets';
|
2021-10-28 21:31:05 +02:00
|
|
|
import ToggleButton from '../../../components/ui/toggle-button';
|
2021-03-16 22:00:08 +01:00
|
|
|
import AdvancedTab from './advanced-tab.component';
|
2019-05-08 20:57:21 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('AdvancedTab Component', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
let component;
|
2021-10-28 21:31:05 +02:00
|
|
|
let setAutoLockTimeLimitSpy = sinon.spy();
|
|
|
|
const toggleTestnet = sinon.spy();
|
2022-03-22 20:14:59 +01:00
|
|
|
const toggleTokenDetection = sinon.spy();
|
2021-10-28 21:31:05 +02:00
|
|
|
|
|
|
|
beforeAll(() => {
|
2021-12-09 20:06:24 +01:00
|
|
|
component = shallow(
|
2020-01-14 22:15:54 +01:00
|
|
|
<AdvancedTab
|
|
|
|
ipfsGateway=""
|
2021-10-28 21:31:05 +02:00
|
|
|
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
|
2020-08-14 13:47:02 +02:00
|
|
|
setIpfsGateway={() => undefined}
|
|
|
|
setShowFiatConversionOnTestnetsPreference={() => undefined}
|
|
|
|
setThreeBoxSyncingPermission={() => undefined}
|
2021-10-28 21:31:05 +02:00
|
|
|
setShowTestNetworks={toggleTestnet}
|
|
|
|
showTestNetworks={false}
|
2020-01-14 22:15:54 +01:00
|
|
|
threeBoxDisabled
|
|
|
|
threeBoxSyncingAllowed={false}
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
|
2021-11-08 16:28:40 +01:00
|
|
|
setLedgerTransportPreference={() => undefined}
|
2021-05-20 20:28:25 +02:00
|
|
|
setDismissSeedBackUpReminder={() => undefined}
|
|
|
|
dismissSeedBackUpReminder={false}
|
2022-03-22 20:14:59 +01:00
|
|
|
useTokenDetection
|
|
|
|
setUseTokenDetection={toggleTokenDetection}
|
2022-06-07 04:30:07 +02:00
|
|
|
userHasALedgerAccount
|
2020-01-14 22:15:54 +01:00
|
|
|
/>,
|
2019-05-08 20:57:21 +02:00
|
|
|
{
|
|
|
|
context: {
|
2020-02-15 21:34:12 +01:00
|
|
|
t: (s) => `_${s}`,
|
2019-05-08 20:57:21 +02:00
|
|
|
},
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-10-28 21:31:05 +02:00
|
|
|
});
|
2019-05-08 20:57:21 +02:00
|
|
|
|
2021-10-28 21:31:05 +02:00
|
|
|
it('should render correctly when threeBoxFeatureFlag', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
expect(component.find('.settings-page__content-row')).toHaveLength(13);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-16 19:11:01 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should update autoLockTimeLimit', () => {
|
2021-10-28 21:31:05 +02:00
|
|
|
setAutoLockTimeLimitSpy = sinon.spy();
|
2021-12-09 20:06:24 +01:00
|
|
|
component = shallow(
|
2019-05-08 20:57:21 +02:00
|
|
|
<AdvancedTab
|
2020-01-14 22:15:54 +01:00
|
|
|
ipfsGateway=""
|
2020-01-21 23:09:53 +01:00
|
|
|
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
|
2020-08-14 13:47:02 +02:00
|
|
|
setIpfsGateway={() => undefined}
|
|
|
|
setShowFiatConversionOnTestnetsPreference={() => undefined}
|
|
|
|
setThreeBoxSyncingPermission={() => undefined}
|
2020-01-14 22:15:54 +01:00
|
|
|
threeBoxDisabled
|
|
|
|
threeBoxSyncingAllowed={false}
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
|
2021-11-08 16:28:40 +01:00
|
|
|
setLedgerTransportPreference={() => undefined}
|
2021-05-20 20:28:25 +02:00
|
|
|
setDismissSeedBackUpReminder={() => undefined}
|
|
|
|
dismissSeedBackUpReminder={false}
|
2021-10-28 21:31:05 +02:00
|
|
|
setShowTestNetworks={toggleTestnet}
|
2022-06-07 04:30:07 +02:00
|
|
|
useTokenDetection
|
|
|
|
setUseTokenDetection={toggleTokenDetection}
|
|
|
|
userHasALedgerAccount
|
2019-05-08 20:57:21 +02:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
context: {
|
2020-02-15 21:34:12 +01:00
|
|
|
t: (s) => `_${s}`,
|
2019-05-08 20:57:21 +02:00
|
|
|
},
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-05-08 20:57:21 +02:00
|
|
|
|
2021-12-09 20:06:24 +01:00
|
|
|
const autoTimeout = component.find('.settings-page__content-row').at(8);
|
2021-02-04 19:15:23 +01:00
|
|
|
const textField = autoTimeout.find(TextField);
|
2019-05-08 20:57:21 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
textField.props().onChange({ target: { value: 1440 } });
|
2021-12-09 20:06:24 +01:00
|
|
|
expect(component.state().autoLockTimeLimit).toStrictEqual(1440);
|
2019-05-08 20:57:21 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
autoTimeout.find('.settings-tab__rpc-save-button').simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setAutoLockTimeLimitSpy.args[0][0]).toStrictEqual(1440);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-10-28 21:31:05 +02:00
|
|
|
|
|
|
|
it('should toggle show test networks', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const testNetworks = component.find('.settings-page__content-row').at(6);
|
2021-10-28 21:31:05 +02:00
|
|
|
const toggleButton = testNetworks.find(ToggleButton);
|
|
|
|
toggleButton.first().simulate('toggle');
|
|
|
|
expect(toggleTestnet.calledOnce).toStrictEqual(true);
|
|
|
|
});
|
2022-03-22 20:14:59 +01:00
|
|
|
|
|
|
|
it('should toggle token detection', () => {
|
|
|
|
process.env.TOKEN_DETECTION_V2 = true;
|
|
|
|
component = shallow(
|
|
|
|
<AdvancedTab
|
|
|
|
ipfsGateway=""
|
|
|
|
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
|
|
|
|
setIpfsGateway={() => undefined}
|
|
|
|
setShowFiatConversionOnTestnetsPreference={() => undefined}
|
|
|
|
setThreeBoxSyncingPermission={() => undefined}
|
|
|
|
setShowTestNetworks={toggleTestnet}
|
|
|
|
showTestNetworks={false}
|
|
|
|
threeBoxDisabled
|
|
|
|
threeBoxSyncingAllowed={false}
|
|
|
|
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
|
|
|
|
setLedgerTransportPreference={() => undefined}
|
|
|
|
setDismissSeedBackUpReminder={() => undefined}
|
|
|
|
dismissSeedBackUpReminder={false}
|
|
|
|
useTokenDetection
|
|
|
|
setUseTokenDetection={toggleTokenDetection}
|
2022-06-07 04:30:07 +02:00
|
|
|
userHasALedgerAccount
|
2022-03-22 20:14:59 +01:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
context: {
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: () => undefined,
|
2022-03-22 20:14:59 +01:00
|
|
|
t: (s) => `_${s}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
const useTokenDetection = component
|
|
|
|
.find('.settings-page__content-row')
|
|
|
|
.at(4);
|
|
|
|
const toggleButton = useTokenDetection.find(ToggleButton);
|
|
|
|
toggleButton.first().simulate('toggle');
|
|
|
|
expect(toggleTokenDetection.calledOnce).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
/** TODO: Remove during TOKEN_DETECTION_V2 feature flag clean up */
|
|
|
|
it('should not show token detection toggle', () => {
|
|
|
|
process.env.TOKEN_DETECTION_V2 = false;
|
|
|
|
component = shallow(
|
|
|
|
<AdvancedTab
|
|
|
|
ipfsGateway=""
|
|
|
|
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
|
|
|
|
setIpfsGateway={() => undefined}
|
|
|
|
setShowFiatConversionOnTestnetsPreference={() => undefined}
|
|
|
|
setThreeBoxSyncingPermission={() => undefined}
|
|
|
|
setShowTestNetworks={toggleTestnet}
|
|
|
|
showTestNetworks={false}
|
|
|
|
threeBoxDisabled
|
|
|
|
threeBoxSyncingAllowed={false}
|
|
|
|
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
|
|
|
|
setLedgerTransportPreference={() => undefined}
|
|
|
|
setDismissSeedBackUpReminder={() => undefined}
|
|
|
|
dismissSeedBackUpReminder={false}
|
|
|
|
useTokenDetection
|
|
|
|
setUseTokenDetection={toggleTokenDetection}
|
2022-06-07 04:30:07 +02:00
|
|
|
userHasALedgerAccount
|
2022-03-22 20:14:59 +01:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
context: {
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: () => undefined,
|
2022-03-22 20:14:59 +01:00
|
|
|
t: (s) => `_${s}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
const tokenDetectionText = component.find({ text: 'Token detection' });
|
|
|
|
expect(tokenDetectionText).toHaveLength(0);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|