1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-03 22:54:29 +01:00
metamask-extension/ui/pages/settings/advanced-tab/advanced-tab.component.test.js
Erik Marks a8c1756816
Remove 3box feature and delete ThreeBoxController (#14571)
* Remove 3box feature and delete ThreeBoxController

Lint locale messages

lavamoat policy updates

* Restore 3Box user trait with value `false`

The 3Box user trait has been restored and hard-coded as `false`. This
ensures that users don't get stuck in our metrics as having this trait.

A deprecation comment has been left in various places for this trait.

* Remove unused state

* Remove additional 3box-related things

* Run `yarn-deduplicate`

* Restore migration that was lost while rebasing

* Remove obsolete override

* Remove additional unused resolutions/dependencies

* Update LavaMoat policies

* Remove obsolete security advisory ignore entries

* Remove 3Box fixture builder method

* Update unit tests

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2022-10-31 13:50:50 -02:30

181 lines
5.6 KiB
JavaScript

import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import TextField from '../../../components/ui/text-field';
import { LEDGER_TRANSPORT_TYPES } from '../../../../shared/constants/hardware-wallets';
import ToggleButton from '../../../components/ui/toggle-button';
import AdvancedTab from './advanced-tab.component';
describe('AdvancedTab Component', () => {
let component;
let setAutoLockTimeLimitSpy = sinon.spy();
const toggleTestnet = sinon.spy();
const toggleTokenDetection = sinon.spy();
beforeAll(() => {
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}
userHasALedgerAccount
backupUserData={() => undefined}
restoreUserData={() => undefined}
/>,
{
context: {
t: (s) => `_${s}`,
},
},
);
});
it('should render backup button', () => {
expect(component.find('.settings-page__content-row')).toHaveLength(15);
expect(
component
.find('.settings-page__content-row')
.at(10)
.find('.settings-page__content-item'),
).toHaveLength(2);
expect(
component
.find('.settings-page__content-row')
.at(10)
.find('.settings-page__content-item')
.at(0)
.find('.settings-page__content-description')
.props().children,
).toStrictEqual('_backupUserDataDescription');
expect(
component
.find('.settings-page__content-row')
.at(10)
.find('.settings-page__content-item')
.at(1)
.find('Button')
.props().children,
).toStrictEqual('_backup');
});
it('should render restore button', () => {
expect(component.find('.settings-page__content-row')).toHaveLength(15);
expect(
component
.find('.settings-page__content-row')
.at(11)
.find('.settings-page__content-item'),
).toHaveLength(2);
expect(
component
.find('.settings-page__content-row')
.at(11)
.find('.settings-page__content-item')
.at(0)
.find('.settings-page__content-description')
.props().children,
).toStrictEqual('_restoreUserDataDescription');
expect(
component
.find('.settings-page__content-row')
.at(11)
.find('.settings-page__content-item')
.at(1)
.find('label')
.props().children,
).toStrictEqual('_restore');
});
it('should update autoLockTimeLimit', () => {
setAutoLockTimeLimitSpy = sinon.spy();
component = shallow(
<AdvancedTab
ipfsGateway=""
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
setIpfsGateway={() => undefined}
setShowFiatConversionOnTestnetsPreference={() => undefined}
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
setLedgerTransportPreference={() => undefined}
setDismissSeedBackUpReminder={() => undefined}
dismissSeedBackUpReminder={false}
setShowTestNetworks={toggleTestnet}
useTokenDetection
setUseTokenDetection={toggleTokenDetection}
userHasALedgerAccount
backupUserData={() => undefined}
restoreUserData={() => undefined}
/>,
{
context: {
t: (s) => `_${s}`,
},
},
);
const autoTimeout = component.find('.settings-page__content-row').at(9);
const textField = autoTimeout.find(TextField);
textField.props().onChange({ target: { value: 1440 } });
expect(component.state().autoLockTimeLimit).toStrictEqual(1440);
autoTimeout.find('.settings-tab__rpc-save-button').simulate('click');
expect(setAutoLockTimeLimitSpy.args[0][0]).toStrictEqual(1440);
});
it('should toggle show test networks', () => {
const testNetworks = component.find('.settings-page__content-row').at(7);
const toggleButton = testNetworks.find(ToggleButton);
toggleButton.first().simulate('toggle');
expect(toggleTestnet.calledOnce).toStrictEqual(true);
});
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}
userHasALedgerAccount
backupUserData={() => undefined}
restoreUserData={() => undefined}
/>,
{
context: {
trackEvent: () => undefined,
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);
});
});