Remove payments API routing initialization
[ProtonMail-WebClient.git] / packages / components / containers / recovery / RecoveryCardSentinel.test.tsx
blob821f497264c17b2a10888fe3b6fc2620a543ad70
1 import { render } from '@testing-library/react';
3 import RecoveryCard from './RecoveryCard';
5 jest.mock('../../hooks/useIsSentinelUser', () => jest.fn());
6 jest.mock('@proton/account/user/hooks', () => ({
7     __esModule: true,
8     useUser: jest.fn(() => [{ MnemonicStatus: 3, Flags: { sso: false } }, false]),
9     useGetUser: jest.fn(() => [{ MnemonicStatus: 3, Flags: { sso: false } }, false]),
10 }));
11 jest.mock('@proton/account/userSettings/hooks', () => ({
12     __esModule: true,
13     useUserSettings: jest.fn(() => []),
14 }));
15 jest.mock('../../hooks/useRecoveryStatus', () => jest.fn());
16 jest.mock('@proton/components/hooks/recoveryFile/useIsRecoveryFileAvailable', () => jest.fn());
17 jest.mock('../../hooks/useIsMnemonicAvailable', () => jest.fn());
18 jest.mock('../../hooks/useIsDataRecoveryAvailable', () => jest.fn());
19 jest.mock('../../hooks/useHasOutdatedRecoveryFile', () => jest.fn());
20 jest.mock('../../hooks/useRecoverySecrets', () => jest.fn());
21 jest.mock('../../hooks/useConfig', () => jest.fn());
23 jest.mock('./RecoveryCardStatus', () => {
24     return jest.fn(() => <div data-testid="mocked-recovery-card-status"></div>);
25 });
27 jest.mock('@proton/account/userSettings/hooks', () => ({
28     __esModule: true,
29     useUserSettings: jest.fn(() => [
30         { Email: { Value: '', Status: 0, Notify: 0, Reset: 0 }, Phone: { Value: '', Status: 0, Notify: 0, Reset: 0 } },
31         false,
32     ]),
33 }));
35 const canDisplayNewSentinelSettings = true; //for feature flag
37 const setupMocks = (isSentinelUser: boolean) => {
38     require('../../hooks/useIsSentinelUser').mockReturnValue([{ isSentinelUser }, false]);
39     require('../../hooks/useRecoveryStatus').mockReturnValue([
40         { accountRecoveryStatus: 'complete', dataRecoveryStatus: 'complete' },
41         false,
42     ]);
43     require('../../hooks/recoveryFile/useIsRecoveryFileAvailable').mockReturnValue([
44         { isRecoveryFileAvailable: true },
45         false,
46     ]);
47     require('../../hooks/useIsMnemonicAvailable').mockReturnValue([{ isMnemonicAvailable: true }, false]);
48     require('../../hooks/useIsDataRecoveryAvailable').mockReturnValue([{ isDataRecoveryAvailable: true }, false]);
49     require('../../hooks/useHasOutdatedRecoveryFile').mockReturnValue(false);
50     require('../../hooks/useRecoverySecrets').mockReturnValue(['key']);
51     require('../../hooks/useConfig').mockReturnValue({ APP_NAME: 'proton-account' });
54 beforeEach(() => {
55     jest.clearAllMocks();
56 });
58 describe('RecoveryCard component', () => {
59     test('renders one RecoveryCardStatus when isSentinelUser is true', () => {
60         setupMocks(true);
62         const { getAllByTestId } = render(
63             <RecoveryCard
64                 ids={{ data: 'someData', account: `someAccount` }}
65                 canDisplayNewSentinelSettings={canDisplayNewSentinelSettings}
66             />
67         );
68         const recoveryCardStatusComponents = getAllByTestId('mocked-recovery-card-status');
69         expect(recoveryCardStatusComponents).toHaveLength(1);
70         expect(require('./RecoveryCardStatus')).toHaveBeenCalledTimes(1);
71     });
73     test('renders two RecoveryCardStatus when isSentinelUser is false', () => {
74         setupMocks(false);
76         const { getAllByTestId } = render(<RecoveryCard ids={{ data: 'someData', account: `someAccount` }} />);
77         const recoveryCardStatusComponents = getAllByTestId('mocked-recovery-card-status');
78         expect(recoveryCardStatusComponents).toHaveLength(2);
79         expect(require('./RecoveryCardStatus')).toHaveBeenCalledTimes(2);
80     });
81 });