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}
|
2021-10-28 21:31:05 +02:00
|
|
|
setShowTestNetworks={toggleTestnet}
|
|
|
|
showTestNetworks={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
|
2022-08-09 20:36:32 +02:00
|
|
|
backupUserData={() => undefined}
|
|
|
|
restoreUserData={() => undefined}
|
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
|
|
|
|
2022-08-09 20:36:32 +02:00
|
|
|
it('should render backup button', () => {
|
2022-10-31 17:20:50 +01:00
|
|
|
expect(component.find('.settings-page__content-row')).toHaveLength(15);
|
2022-08-09 20:36:32 +02:00
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(10)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item'),
|
|
|
|
).toHaveLength(2);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(10)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item')
|
|
|
|
.at(0)
|
|
|
|
.find('.settings-page__content-description')
|
|
|
|
.props().children,
|
|
|
|
).toStrictEqual('_backupUserDataDescription');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(10)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item')
|
|
|
|
.at(1)
|
|
|
|
.find('Button')
|
|
|
|
.props().children,
|
|
|
|
).toStrictEqual('_backup');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render restore button', () => {
|
2022-10-31 17:20:50 +01:00
|
|
|
expect(component.find('.settings-page__content-row')).toHaveLength(15);
|
2022-08-09 20:36:32 +02:00
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(11)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item'),
|
|
|
|
).toHaveLength(2);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(11)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item')
|
|
|
|
.at(0)
|
|
|
|
.find('.settings-page__content-description')
|
|
|
|
.props().children,
|
|
|
|
).toStrictEqual('_restoreUserDataDescription');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('.settings-page__content-row')
|
2022-08-10 03:26:25 +02:00
|
|
|
.at(11)
|
2022-08-09 20:36:32 +02:00
|
|
|
.find('.settings-page__content-item')
|
|
|
|
.at(1)
|
|
|
|
.find('label')
|
|
|
|
.props().children,
|
|
|
|
).toStrictEqual('_restore');
|
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}
|
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
|
2022-08-09 20:36:32 +02:00
|
|
|
backupUserData={() => undefined}
|
|
|
|
restoreUserData={() => undefined}
|
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
|
|
|
|
2022-08-10 03:26:25 +02:00
|
|
|
const autoTimeout = component.find('.settings-page__content-row').at(9);
|
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', () => {
|
2022-08-10 03:26:25 +02:00
|
|
|
const testNetworks = component.find('.settings-page__content-row').at(7);
|
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', () => {
|
|
|
|
component = shallow(
|
|
|
|
<AdvancedTab
|
|
|
|
ipfsGateway=""
|
|
|
|
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
|
|
|
|
setIpfsGateway={() => undefined}
|
|
|
|
setShowFiatConversionOnTestnetsPreference={() => undefined}
|
|
|
|
setShowTestNetworks={toggleTestnet}
|
|
|
|
showTestNetworks={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-08-09 20:36:32 +02:00
|
|
|
backupUserData={() => undefined}
|
|
|
|
restoreUserData={() => undefined}
|
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);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|