1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/ui/components/app/srp-quiz-modal/SRPQuiz/SRPQuiz.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

96 lines
2.4 KiB
JavaScript

import { fireEvent, screen, waitFor } from '@testing-library/react';
import React from 'react';
import mockState from '../../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../../test/jest';
import ZENDESK_URLS from '../../../../helpers/constants/zendesk-url';
import configureStore from '../../../../store/store';
import { QuizStage } from '../types';
import SRPQuiz from './SRPQuiz';
const store = configureStore({
metamask: {
...mockState.metamask,
},
});
let openTabSpy;
jest.mock('react-router-dom', () => {
const original = jest.requireActual('react-router-dom');
return {
...original,
useHistory: () => ({
push: jest.fn(),
}),
};
});
async function waitForStage(stage) {
return await waitFor(() => {
expect(screen.getByTestId(`srp_stage_${stage}`)).toBeInTheDocument();
});
}
function clickButton(id) {
fireEvent.click(screen.getByTestId(id));
}
describe('srp-reveal-quiz', () => {
beforeAll(() => {
global.platform = { openTab: jest.fn() };
openTabSpy = jest.spyOn(global.platform, 'openTab');
});
it('should go through the full sequence of steps', async () => {
renderWithProvider(<SRPQuiz isOpen />, store);
expect(screen.queryByTestId('srp-quiz-get-started')).toBeInTheDocument();
expect(
screen.queryByTestId('srp-quiz-right-answer'),
).not.toBeInTheDocument();
clickButton('srp-quiz-learn-more');
await waitFor(() =>
expect(openTabSpy).toHaveBeenCalledWith({
url: expect.stringMatching(ZENDESK_URLS.PASSWORD_AND_SRP_ARTICLE),
}),
);
clickButton('srp-quiz-get-started');
await waitForStage(QuizStage.questionOne);
clickButton('srp-quiz-wrong-answer');
await waitForStage(QuizStage.wrongAnswerQuestionOne);
clickButton('srp-quiz-try-again');
await waitForStage(QuizStage.questionOne);
clickButton('srp-quiz-right-answer');
await waitForStage(QuizStage.rightAnswerQuestionOne);
clickButton('srp-quiz-continue');
await waitForStage(QuizStage.questionTwo);
clickButton('srp-quiz-wrong-answer');
await waitForStage(QuizStage.wrongAnswerQuestionTwo);
clickButton('srp-quiz-try-again');
await waitForStage(QuizStage.questionTwo);
clickButton('srp-quiz-right-answer');
await waitForStage(QuizStage.rightAnswerQuestionTwo);
clickButton('srp-quiz-continue');
});
});