|
| 1 | +export const createMockProps = () => ({ |
| 2 | + origin: '', |
| 3 | + email: 'test@example.com', |
| 4 | + encryptionSecret: 'mockEncryptionSecret', |
| 5 | + UUID: 'mockUUID', |
| 6 | + isLoading: false, |
| 7 | + setIsLoading: jest.fn(), |
| 8 | +}); |
| 9 | + |
| 10 | +export const mockTasks = [ |
| 11 | + ...Array.from({ length: 12 }, (_, i) => ({ |
| 12 | + id: i + 1, |
| 13 | + description: `Task ${i + 1}`, |
| 14 | + status: 'pending', |
| 15 | + project: i % 2 === 0 ? 'ProjectA' : 'ProjectB', |
| 16 | + tags: i % 3 === 0 ? ['tag1'] : ['tag2'], |
| 17 | + uuid: `uuid-${i + 1}`, |
| 18 | + due: i === 0 ? '20200101T120000Z' : undefined, |
| 19 | + })), |
| 20 | + { |
| 21 | + id: 13, |
| 22 | + description: |
| 23 | + 'Task 13: Prepare quarterly financial analysis report for review', |
| 24 | + status: 'pending', |
| 25 | + project: 'Finance', |
| 26 | + tags: ['report', 'analysis'], |
| 27 | + uuid: 'uuid-corp-1', |
| 28 | + }, |
| 29 | + { |
| 30 | + id: 14, |
| 31 | + description: 'Task 14: Schedule client onboarding meeting with Sales team', |
| 32 | + status: 'pending', |
| 33 | + project: 'Sales', |
| 34 | + tags: ['meeting', 'client'], |
| 35 | + uuid: 'uuid-corp-2', |
| 36 | + }, |
| 37 | + { |
| 38 | + id: 15, |
| 39 | + description: |
| 40 | + 'Task 15: Draft technical documentation for API integration module', |
| 41 | + status: 'pending', |
| 42 | + project: 'Engineering', |
| 43 | + tags: ['documentation', 'api'], |
| 44 | + uuid: 'uuid-corp-3', |
| 45 | + }, |
| 46 | + { |
| 47 | + id: 16, |
| 48 | + description: 'Completed Task 1', |
| 49 | + status: 'completed', |
| 50 | + project: 'ProjectA', |
| 51 | + tags: ['completed'], |
| 52 | + uuid: 'uuid-completed-1', |
| 53 | + }, |
| 54 | + { |
| 55 | + id: 17, |
| 56 | + description: 'Deleted Task 1', |
| 57 | + status: 'deleted', |
| 58 | + project: 'ProjectB', |
| 59 | + tags: ['deleted'], |
| 60 | + uuid: 'uuid-deleted-1', |
| 61 | + }, |
| 62 | +]; |
| 63 | + |
| 64 | +export const createToastMock = () => ({ |
| 65 | + toast: { |
| 66 | + success: jest.fn(), |
| 67 | + error: jest.fn(), |
| 68 | + }, |
| 69 | +}); |
| 70 | + |
| 71 | +export const createTasksUtilsMock = () => { |
| 72 | + const originalModule = jest.requireActual('../../tasks-utils'); |
| 73 | + return { |
| 74 | + ...originalModule, |
| 75 | + markTaskAsCompleted: jest.fn(), |
| 76 | + bulkMarkTasksAsCompleted: jest.fn().mockResolvedValue(true), |
| 77 | + markTaskAsDeleted: jest.fn(), |
| 78 | + bulkMarkTasksAsDeleted: jest.fn().mockResolvedValue(true), |
| 79 | + getTimeSinceLastSync: jest |
| 80 | + .fn() |
| 81 | + .mockReturnValue('Last updated 5 minutes ago'), |
| 82 | + hashKey: jest.fn((key: string) => `mockHashedKey-${key}`), |
| 83 | + getPinnedTasks: jest.fn().mockReturnValue(new Set()), |
| 84 | + togglePinnedTask: jest.fn(), |
| 85 | + }; |
| 86 | +}; |
| 87 | + |
| 88 | +export const createHooksMock = () => ({ |
| 89 | + TasksDatabase: jest.fn(() => ({ |
| 90 | + tasks: { |
| 91 | + where: jest.fn(() => ({ |
| 92 | + equals: jest.fn(() => ({ |
| 93 | + toArray: jest.fn().mockResolvedValue(mockTasks), |
| 94 | + delete: jest.fn().mockResolvedValue(undefined), |
| 95 | + })), |
| 96 | + })), |
| 97 | + bulkPut: jest.fn().mockResolvedValue(undefined), |
| 98 | + }, |
| 99 | + transaction: jest.fn(async (_mode, _table, callback) => { |
| 100 | + await callback(); |
| 101 | + return Promise.resolve(); |
| 102 | + }), |
| 103 | + })), |
| 104 | + fetchTaskwarriorTasks: jest.fn().mockResolvedValue([]), |
| 105 | + addTaskToBackend: jest.fn().mockResolvedValue({}), |
| 106 | + editTaskOnBackend: jest.fn().mockResolvedValue({}), |
| 107 | + modifyTaskOnBackend: jest.fn().mockResolvedValue({}), |
| 108 | +}); |
| 109 | + |
| 110 | +export const selectMock = { |
| 111 | + Select: ({ children, onValueChange, value }: any) => ( |
| 112 | + <select |
| 113 | + data-testid="project-select" |
| 114 | + value={value} |
| 115 | + onChange={(e) => onValueChange?.(e.target.value)} |
| 116 | + > |
| 117 | + {children} |
| 118 | + </select> |
| 119 | + ), |
| 120 | + SelectTrigger: ({ children }: any) => children, |
| 121 | + SelectValue: ({ placeholder }: any) => ( |
| 122 | + <option value="" disabled hidden> |
| 123 | + {placeholder} |
| 124 | + </option> |
| 125 | + ), |
| 126 | + SelectContent: ({ children }: any) => children, |
| 127 | + SelectItem: ({ value, children }: any) => ( |
| 128 | + <option value={value}>{children}</option> |
| 129 | + ), |
| 130 | +}; |
0 commit comments