1 import { act, renderHook } from '@testing-library/react-hooks';
3 import { queryListPendingExternalInvitations } from '@proton/shared/lib/api/drive/invitation';
4 import type { ListDrivePendingExternalInvitationsPayload } from '@proton/shared/lib/interfaces/drive/sharing';
6 import useChecklist from './useChecklist';
7 import { useOnboarding } from './useOnboarding';
9 jest.mock('./useChecklist');
10 const mockedUseCheckList = jest.mocked(useChecklist);
11 const mockedDebouncedRequest = jest.fn();
12 jest.mock('../../store/_api/useDebouncedRequest', () => {
13 const useDebouncedRequest = () => {
14 return mockedDebouncedRequest;
16 return useDebouncedRequest;
18 jest.mock('@proton/shared/lib/api/drive/invitation');
20 describe('useOnboarding', () => {
21 let checklistMock: { isLoading: boolean };
22 let queryListPendingExternalInvitationsMock: ListDrivePendingExternalInvitationsPayload;
25 checklistMock = { isLoading: false };
26 queryListPendingExternalInvitationsMock = {
27 ExternalInvitations: [
31 ExternalInvitationID: 'externalInvitationId',
38 mockedUseCheckList.mockReturnValue(checklistMock as ReturnType<typeof mockedUseCheckList>);
39 mockedDebouncedRequest.mockResolvedValue(queryListPendingExternalInvitationsMock);
46 it('should initialize with default values and fetch pending invitations', async () => {
47 const { result, waitFor } = renderHook(() => useOnboarding());
49 expect(result.current.isLoading).toBe(true);
50 expect(result.current.checklist).toBe(checklistMock);
51 expect(result.current.hasPendingExternalInvitations).toBe(false);
52 await act(async () => {
54 expect(mockedDebouncedRequest).toHaveBeenCalledWith(queryListPendingExternalInvitations())
56 expect(result.current.hasPendingExternalInvitations).toBe(true);
57 expect(result.current.isLoading).toBe(false);