Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / onboarding / useOnboarding.test.ts
blob79407762aac47e86686224db899c6ea9f908b24d
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;
15     };
16     return useDebouncedRequest;
17 });
18 jest.mock('@proton/shared/lib/api/drive/invitation');
20 describe('useOnboarding', () => {
21     let checklistMock: { isLoading: boolean };
22     let queryListPendingExternalInvitationsMock: ListDrivePendingExternalInvitationsPayload;
24     beforeEach(() => {
25         checklistMock = { isLoading: false };
26         queryListPendingExternalInvitationsMock = {
27             ExternalInvitations: [
28                 {
29                     VolumeID: 'volumeId',
30                     ShareID: 'shareId',
31                     ExternalInvitationID: 'externalInvitationId',
32                 },
33             ],
34             More: false,
35             AnchorID: null,
36         };
38         mockedUseCheckList.mockReturnValue(checklistMock as ReturnType<typeof mockedUseCheckList>);
39         mockedDebouncedRequest.mockResolvedValue(queryListPendingExternalInvitationsMock);
40     });
42     afterEach(() => {
43         jest.clearAllMocks();
44     });
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 () => {
53             await waitFor(() =>
54                 expect(mockedDebouncedRequest).toHaveBeenCalledWith(queryListPendingExternalInvitations())
55             );
56             expect(result.current.hasPendingExternalInvitations).toBe(true);
57             expect(result.current.isLoading).toBe(false);
58         });
59     });
60 });