mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
0306422bbf
Co-authored-by: George Marshall <george.marshall@consensys.net> Co-authored-by: Brad Decker <bhdecker84@gmail.com> Co-authored-by: David Walsh <davidwalsh83@gmail.com> Co-authored-by: Howard Braham <howrad@gmail.com> * change js to tsx * update to typescript * add labels to circle animation * add willHide prop to hold to reveal modal * add test * convert to design system * fix lint * fix type * bump coverage * rename * remove comments * remove ts comment and add fix exhuastive dep check * update coverage * add hide modal test * use banneralert * update label * remove unused * fix text * update aria label messages * change exportAccountAndGetPrivateKey to be async * fix lint * update coverage target * update coverage * update input component * update coverage * update coverage * fix blank line * use && * move plainKey to under !privateKeyInput * update hold modal to display srp and private key message * fix styling * fix lint and test * fix unused locales * remove redundent check * update storybook * fix text alignment * fix lint * update snapshot * fix test * update coverage * fix merge conflict * refactor * fix variant * update snapshot * fix test after merge * fix test after merge conflict * fix label text * update to use label component
123 lines
3.8 KiB
JavaScript
123 lines
3.8 KiB
JavaScript
import React from 'react';
|
|
import { render, fireEvent, waitFor } from '@testing-library/react';
|
|
import configureMockState from 'redux-mock-store';
|
|
import thunk from 'redux-thunk';
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
import {
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventKeyType,
|
|
MetaMetricsEventName,
|
|
} from '../../../../shared/constants/metametrics';
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
import HoldToRevealButton from './hold-to-reveal-button';
|
|
|
|
const mockTrackEvent = jest.fn();
|
|
|
|
describe('HoldToRevealButton', () => {
|
|
const mockStore = configureMockState([thunk])(mockState);
|
|
let props = {};
|
|
|
|
beforeEach(() => {
|
|
const mockOnLongPressed = jest.fn();
|
|
|
|
props = {
|
|
onLongPressed: mockOnLongPressed,
|
|
buttonText: 'Hold to reveal SRP',
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should render a button with label', () => {
|
|
const { getByText } = render(<HoldToRevealButton {...props} />);
|
|
|
|
expect(getByText('Hold to reveal SRP')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render a button when mouse is down and up', () => {
|
|
const { getByText } = render(<HoldToRevealButton {...props} />);
|
|
|
|
const button = getByText('Hold to reveal SRP');
|
|
|
|
fireEvent.mouseDown(button);
|
|
|
|
expect(button).toBeDefined();
|
|
|
|
fireEvent.mouseUp(button);
|
|
|
|
expect(button).toBeDefined();
|
|
});
|
|
|
|
it('should show the locked padlock when a button is long pressed and then should show it after it was lifted off before the animation concludes', async () => {
|
|
const { getByText, queryByLabelText } = renderWithProvider(
|
|
<MetaMetricsContext.Provider value={mockTrackEvent}>
|
|
<HoldToRevealButton {...props} />
|
|
</MetaMetricsContext.Provider>,
|
|
mockStore,
|
|
);
|
|
|
|
const button = getByText('Hold to reveal SRP');
|
|
|
|
fireEvent.mouseDown(button);
|
|
const circleLocked = queryByLabelText('hold to reveal circle locked');
|
|
|
|
await waitFor(() => {
|
|
expect(circleLocked).toBeInTheDocument();
|
|
});
|
|
|
|
fireEvent.mouseUp(button);
|
|
const circleUnlocked = queryByLabelText('hold to reveal circle unlocked');
|
|
|
|
await waitFor(() => {
|
|
expect(circleUnlocked).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should show the unlocked padlock when a button is long pressed for the duration of the animation', async () => {
|
|
const { getByText, queryByLabelText, getByLabelText } = renderWithProvider(
|
|
<MetaMetricsContext.Provider value={mockTrackEvent}>
|
|
<HoldToRevealButton {...props} />
|
|
</MetaMetricsContext.Provider>,
|
|
mockStore,
|
|
);
|
|
|
|
const button = getByText('Hold to reveal SRP');
|
|
|
|
fireEvent.mouseDown(button);
|
|
|
|
const circleLocked = getByLabelText('hold to reveal circle locked');
|
|
fireEvent.transitionEnd(circleLocked);
|
|
|
|
const circleUnlocked = queryByLabelText('hold to reveal circle unlocked');
|
|
fireEvent.animationEnd(circleUnlocked);
|
|
|
|
await waitFor(() => {
|
|
expect(circleUnlocked).toBeInTheDocument();
|
|
expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
|
|
category: MetaMetricsEventCategory.Keys,
|
|
event: MetaMetricsEventName.SrpHoldToRevealClickStarted,
|
|
properties: {
|
|
key_type: MetaMetricsEventKeyType.Srp,
|
|
},
|
|
});
|
|
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
|
|
category: MetaMetricsEventCategory.Keys,
|
|
event: MetaMetricsEventName.SrpHoldToRevealCompleted,
|
|
properties: {
|
|
key_type: MetaMetricsEventKeyType.Srp,
|
|
},
|
|
});
|
|
expect(mockTrackEvent).toHaveBeenNthCalledWith(3, {
|
|
category: MetaMetricsEventCategory.Keys,
|
|
event: MetaMetricsEventName.SrpRevealViewed,
|
|
properties: {
|
|
key_type: MetaMetricsEventKeyType.Srp,
|
|
},
|
|
});
|
|
});
|
|
});
|
|
});
|