1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/pages/settings/security-tab/security-tab.test.js
Howard Braham 9acd4b4ea1
feat(srp): add a quiz to the SRP reveal (#19283)
* feat(srp): add a quiz to the SRP reveal

* fixed the popover header centering

* lint fixes

* converted from `ui/components/ui/popover` to `ui/components/component-library/modal`

* responded to @darkwing review

* added unit tests

* renamed the folder to 'srp-quiz-modal'

* responded to Monte's review

* using i18n-helper in the test suite

* small improvement to JSXDict comments

* wrote a new webdriver.holdMouseDownOnElement() to assist with testing the "Hold to reveal SRP" button

* Updating layout and some storybook naming and migrating to tsx

* Apply suggestions from @georgewrmarshall

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Unit test searches by data-testid instead of by text

* new layout and copy for the Settings->Security page

* now with 100% test coverage for /ui/pages/settings/security-tab
fixes #16871
fixes #18140

* e2e tests to reveal SRP after quiz

* e2e- Fix lint, remove unneeded extras

* @coreyjanssen and @georgewrmarshall compromise

Co-authored-by: George Marshall <george.marshall@consensys.net>
Co-authored-by: Corey Janssen <corey.janssen@consensys.net>

* trying isRequired again

* transparent background on PNG

* [e2e] moving functions to helpers and adding testid for SRP reveal quiz (#19481)

* moving functions to helpers and adding testid

* fix lint error

* took out the IPFS gateway fixes

* lint fix

* translations of SRP Reveal Quiz

* new Spanish translation from Guto

* Update describe for e2e tests

* Apply suggestion from @georgewrmarshall

Co-authored-by: George Marshall <george.marshall@consensys.net>

* fixed the Tab key problem

---------

Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
Co-authored-by: Plasma Corral <32695229+plasmacorral@users.noreply.github.com>
Co-authored-by: Corey Janssen <corey.janssen@consensys.net>
2023-06-20 14:27:10 -04:00

95 lines
3.0 KiB
JavaScript

import { fireEvent, queryByRole, screen } from '@testing-library/react';
import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import mockState from '../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import SecurityTab from './security-tab.container';
jest.mock('../../../../app/scripts/lib/util', () => {
const originalModule = jest.requireActual('../../../../app/scripts/lib/util');
return {
...originalModule,
getEnvironmentType: jest.fn(),
};
});
describe('Security Tab', () => {
delete mockState.metamask.featureFlags; // Unset featureFlags in order to test the default value
mockState.appState.warning = 'warning'; // This tests an otherwise untested render branch
const mockStore = configureMockStore([thunk])(mockState);
function toggleCheckbox(testId, initialState) {
renderWithProvider(<SecurityTab />, mockStore);
const container = screen.getByTestId(testId);
const checkbox = queryByRole(container, 'checkbox');
expect(checkbox).toHaveAttribute('value', initialState ? 'true' : 'false');
fireEvent.click(checkbox); // This fires the onToggle method of the ToggleButton, but it doesn't change the value of the checkbox
fireEvent.change(checkbox, {
target: { value: !initialState }, // This changes the value of the checkbox
});
expect(checkbox).toHaveAttribute('value', initialState ? 'false' : 'true');
return true;
}
it('should match snapshot', () => {
const { container } = renderWithProvider(<SecurityTab />, mockStore);
expect(container).toMatchSnapshot();
});
it('toggles phishing detection', async () => {
expect(await toggleCheckbox('usePhishingDetection', true)).toBe(true);
});
it('toggles balance and token price checker', async () => {
expect(await toggleCheckbox('currencyRateCheckToggle', true)).toBe(true);
});
it('toggles incoming txs', async () => {
expect(await toggleCheckbox('showIncomingTransactions', false)).toBe(true);
});
it('should toggle token detection', async () => {
expect(await toggleCheckbox('autoDetectTokens', true)).toBe(true);
});
it('toggles batch balance checks', async () => {
expect(await toggleCheckbox('useMultiAccountBalanceChecker', false)).toBe(
true,
);
});
it('toggles metaMetrics', async () => {
expect(await toggleCheckbox('participateInMetaMetrics', false)).toBe(true);
});
it('toggles SRP Quiz', async () => {
renderWithProvider(<SecurityTab />, mockStore);
expect(
screen.queryByTestId(`srp_stage_introduction`),
).not.toBeInTheDocument();
fireEvent.click(screen.getByTestId('reveal-seed-words'));
expect(screen.getByTestId(`srp_stage_introduction`)).toBeInTheDocument();
const container = screen.getByTestId('srp-quiz-header');
const checkbox = queryByRole(container, 'button');
fireEvent.click(checkbox);
expect(
screen.queryByTestId(`srp_stage_introduction`),
).not.toBeInTheDocument();
});
});