1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/pages/settings/advanced-tab/advanced-tab.component.test.js
Mark Stacey ba54a3d83b
Update ESLint config to v8 (#12886)
The ESLint config has been updated to v8. The breaking changes are:

* The Prettier rule `quoteProps` has been changed from `consistent` to
`as-needed`, meaning that if one key requires quoting, only that key is
quoted rather than all keys.
* The ESLint rule `no-shadow` has been made more strict. It now
prevents globals from being shadowed as well.

Most of these changes were applied with `yarn lint:fix`. Only the
shadowing changes required manual fixing (shadowing variable names were
either replaced with destructuring or renamed).

The dependency `globalThis` was added to the list of dynamic
dependencies in the build system, where it should have been already.
This was causing `depcheck` to fail because the new lint rules required
removing the one place where `globalThis` had been erroneously imported
previously.

A rule requiring a newline between multiline blocks and expressions has
been disabled temporarily to make this PR smaller and to avoid
introducing conflicts with other PRs.
2021-12-09 15:36:24 -03:30

84 lines
2.8 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();
beforeAll(() => {
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}
/>,
{
context: {
t: (s) => `_${s}`,
},
},
);
});
it('should render correctly when threeBoxFeatureFlag', () => {
expect(component.find('.settings-page__content-row')).toHaveLength(13);
});
it('should update autoLockTimeLimit', () => {
setAutoLockTimeLimitSpy = sinon.spy();
component = shallow(
<AdvancedTab
ipfsGateway=""
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
setIpfsGateway={() => undefined}
setShowFiatConversionOnTestnetsPreference={() => undefined}
setThreeBoxSyncingPermission={() => undefined}
threeBoxDisabled
threeBoxSyncingAllowed={false}
ledgerTransportType={LEDGER_TRANSPORT_TYPES.U2F}
setLedgerTransportPreference={() => undefined}
setDismissSeedBackUpReminder={() => undefined}
dismissSeedBackUpReminder={false}
setShowTestNetworks={toggleTestnet}
/>,
{
context: {
t: (s) => `_${s}`,
},
},
);
const autoTimeout = component.find('.settings-page__content-row').at(8);
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(6);
const toggleButton = testNetworks.find(ToggleButton);
toggleButton.first().simulate('toggle');
expect(toggleTestnet.calledOnce).toStrictEqual(true);
});
});