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', () => ({
8 useUser: jest.fn(() => [{ MnemonicStatus: 3, Flags: { sso: false } }, false]),
9 useGetUser: jest.fn(() => [{ MnemonicStatus: 3, Flags: { sso: false } }, false]),
11 jest.mock('@proton/account/userSettings/hooks', () => ({
13 useUserSettings: jest.fn(() => []),
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>);
27 jest.mock('@proton/account/userSettings/hooks', () => ({
29 useUserSettings: jest.fn(() => [
30 { Email: { Value: '', Status: 0, Notify: 0, Reset: 0 }, Phone: { Value: '', Status: 0, Notify: 0, Reset: 0 } },
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' },
43 require('../../hooks/recoveryFile/useIsRecoveryFileAvailable').mockReturnValue([
44 { isRecoveryFileAvailable: true },
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' });
58 describe('RecoveryCard component', () => {
59 test('renders one RecoveryCardStatus when isSentinelUser is true', () => {
62 const { getAllByTestId } = render(
64 ids={{ data: 'someData', account: `someAccount` }}
65 canDisplayNewSentinelSettings={canDisplayNewSentinelSettings}
68 const recoveryCardStatusComponents = getAllByTestId('mocked-recovery-card-status');
69 expect(recoveryCardStatusComponents).toHaveLength(1);
70 expect(require('./RecoveryCardStatus')).toHaveBeenCalledTimes(1);
73 test('renders two RecoveryCardStatus when isSentinelUser is 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);