Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Jan 18, 2024
1 parent 600240a commit b759f64
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/script/hooks/useAppSoftLock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ import {renderHook, waitFor} from '@testing-library/react';
import {useAppSoftLock} from './useAppSoftLock';

import {CallingRepository} from '../calling/CallingRepository';
import {E2EIHandler, isE2EIEnabled} from '../E2EIdentity';
import {E2EIHandler} from '../E2EIdentity';
import {isFreshMLSSelfClient} from '../E2EIdentity/E2EIdentityVerification';
import {NotificationRepository} from '../notification/NotificationRepository';

const isFreshMLSSelfClientMock = isFreshMLSSelfClient as jest.MockedFn<typeof isFreshMLSSelfClient>;
const isE2EIEnabledMock = isE2EIEnabled as jest.MockedFn<typeof isE2EIEnabled>;
const E2EIHandlerMock = E2EIHandler as jest.Mocked<typeof E2EIHandler>;

jest.mock('../E2EIdentity/E2EIdentityVerification', () => ({
isFreshMLSSelfClient: jest.fn(),
}));

jest.mock('../E2EIdentity', () => ({
isE2EIEnabled: jest.fn(),
E2EIHandler: {
getInstance: jest.fn(),
},
Expand All @@ -50,15 +48,18 @@ describe('useAppSoftLock', () => {
});

it('should not do anything if e2ei is not enabled', () => {
E2EIHandlerMock.getInstance.mockReturnValue({
isE2EIEnabled: jest.fn(() => false),
} as any);
const {result} = renderHook(() => useAppSoftLock(callingRepository, notificationRepository));
expect(result.current).toEqual({softLockEnabled: false});
expect(callingRepository.setSoftLock).not.toHaveBeenCalledWith(true);
expect(notificationRepository.setSoftLock).not.toHaveBeenCalledWith(true);
});

it('should set soft lock to true if the user has used up the entire grace period', async () => {
isE2EIEnabledMock.mockReturnValue(true);
E2EIHandlerMock.getInstance.mockReturnValue({
isE2EIEnabled: jest.fn(() => true),
on: jest.fn((eventName, callback) => callback({enrollmentConfig: {timer: {isSnoozeTimeAvailable: () => false}}})),
off: jest.fn(),
} as any);
Expand All @@ -73,9 +74,9 @@ describe('useAppSoftLock', () => {
});

it('should set softLock if the device is a fresh new device', async () => {
isE2EIEnabledMock.mockReturnValue(true);
isFreshMLSSelfClientMock.mockResolvedValue(true);
E2EIHandlerMock.getInstance.mockReturnValue({
isE2EIEnabled: jest.fn(() => true),
on: jest.fn((eventName, callback) => callback({enrollmentConfig: {timer: {isSnoozeTimeAvailable: () => true}}})),
off: jest.fn(),
} as any);
Expand All @@ -90,8 +91,8 @@ describe('useAppSoftLock', () => {
});

it('should not set softLock if the device is an old device and the grace period is not expireds', async () => {
isE2EIEnabledMock.mockReturnValue(true);
E2EIHandlerMock.getInstance.mockReturnValue({
isE2EIEnabled: jest.fn(() => true),
on: jest.fn((eventName, callback) =>
callback({enrollmentConfig: {timer: {isSnoozeTimeAvailable: () => true}, isFreshMLSSelfClient: false}}),
),
Expand Down

0 comments on commit b759f64

Please sign in to comment.