@tuturuuu/ui 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/biome.json +1 -1
- package/package.json +73 -71
- package/src/components/ui/accordion.tsx +1 -1
- package/src/components/ui/breadcrumb.tsx +1 -1
- package/src/components/ui/calendar-app/calendar-page-shell.tsx +4 -0
- package/src/components/ui/calendar-app/components/calendar-connections-settings-content.tsx +239 -33
- package/src/components/ui/calendar-app/components/load-smart-scheduling-tasks.tsx +143 -0
- package/src/components/ui/calendar-app/components/priority-view.tsx +10 -3
- package/src/components/ui/calendar-app/components/tasks-sidebar.tsx +4 -116
- package/src/components/ui/calendar-app/components/use-calendar-connections-manager.ts +67 -2
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/carousel.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-external-thread-panel.test.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-external-thread-panel.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-operations-panel.test.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-operations-panel.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-setup-panel.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-sidebar.test.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-sidebar.tsx +2 -2
- package/src/components/ui/chat/chat-agent-details-utils.test.ts +1 -1
- package/src/components/ui/chat/chat-agent-details-utils.tsx +1 -1
- package/src/components/ui/chat/chat-agent-details-zalo-personal-panel.tsx +2 -2
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/context-menu.tsx +5 -1
- package/src/components/ui/custom/__tests__/settings-dialog-shell.test.tsx +3 -0
- package/src/components/ui/custom/__tests__/workspace-select-helpers.test.ts +19 -0
- package/src/components/ui/custom/combobox.test.tsx +195 -0
- package/src/components/ui/custom/combobox.tsx +273 -156
- package/src/components/ui/custom/education/modules/youtube/delete-link-button.tsx +5 -13
- package/src/components/ui/custom/facebook-mockup/facebook-mockup.tsx +7 -1
- package/src/components/ui/custom/facebook-mockup/form.tsx +1 -1
- package/src/components/ui/custom/facebook-mockup/image-upload-field.tsx +1 -1
- package/src/components/ui/custom/facebook-mockup/preview.tsx +1 -1
- package/src/components/ui/custom/settings-dialog-shell.tsx +2 -1
- package/src/components/ui/custom/theme-toggle.tsx +1 -1
- package/src/components/ui/custom/workspace-select.tsx +8 -3
- package/src/components/ui/dialog.test.tsx +52 -0
- package/src/components/ui/dialog.tsx +6 -2
- package/src/components/ui/dropdown-menu.tsx +5 -1
- package/src/components/ui/finance/debts/debt-loan-form.tsx +12 -5
- package/src/components/ui/finance/debts/debt-loan-summary.tsx +3 -2
- package/src/components/ui/finance/debts/debts-page.test.tsx +54 -5
- package/src/components/ui/finance/debts/debts-page.tsx +15 -2
- package/src/components/ui/finance/invoices/components/subscription-group-selector.tsx +3 -5
- package/src/components/ui/finance/invoices/new-invoice-page.test.tsx +25 -5
- package/src/components/ui/finance/invoices/new-invoice-page.tsx +7 -2
- package/src/components/ui/finance/invoices/standard-invoice.tsx +4 -2
- package/src/components/ui/finance/invoices/subscription-invoice.tsx +4 -2
- package/src/components/ui/finance/invoices/utils.ts +3 -1
- package/src/components/ui/finance/transactions/form-content-dialog.tsx +3 -0
- package/src/components/ui/finance/transactions/form-types.ts +1 -0
- package/src/components/ui/finance/transactions/form.tsx +2 -0
- package/src/components/ui/finance/transactions/infinite-transactions-list.tsx +2 -0
- package/src/components/ui/finance/transactions/period-charts/category-breakdown-dialog.tsx +1 -1
- package/src/components/ui/finance/transactions/transaction-edit-dialog.tsx +1 -4
- package/src/components/ui/finance/transactions/transactions-create-summary.tsx +3 -0
- package/src/components/ui/finance/transactions/transactions-page.tsx +4 -1
- package/src/components/ui/finance/wallets/form.test.tsx +51 -3
- package/src/components/ui/finance/wallets/form.tsx +15 -4
- package/src/components/ui/finance/wallets/walletId/wallet-details-actions.tsx +4 -0
- package/src/components/ui/finance/wallets/walletId/wallet-details-page.tsx +4 -2
- package/src/components/ui/finance/wallets/wallets-data-table.tsx +1 -0
- package/src/components/ui/finance/wallets/wallets-page.tsx +5 -2
- package/src/components/ui/input-otp.tsx +1 -1
- package/src/components/ui/legacy/calendar/all-day-event-bar.tsx +28 -39
- package/src/components/ui/legacy/calendar/calendar-cell.tsx +2 -0
- package/src/components/ui/legacy/calendar/calendar-content.tsx +10 -6
- package/src/components/ui/legacy/calendar/calendar-header.tsx +23 -3
- package/src/components/ui/legacy/calendar/calendar-loading-skeleton.tsx +135 -0
- package/src/components/ui/legacy/calendar/calendar-matrix.tsx +175 -237
- package/src/components/ui/legacy/calendar/event-card.test.tsx +177 -0
- package/src/components/ui/legacy/calendar/event-card.tsx +220 -131
- package/src/components/ui/legacy/calendar/event-modal.tsx +17 -17
- package/src/components/ui/legacy/calendar/event-provider-display.tsx +69 -0
- package/src/components/ui/legacy/calendar/smart-calendar.test.tsx +86 -4
- package/src/components/ui/legacy/calendar/smart-calendar.tsx +32 -2
- package/src/components/ui/legacy/meet/create-plan-dialog.tsx +19 -10
- package/src/components/ui/navigation-menu.tsx +1 -1
- package/src/components/ui/pagination.tsx +1 -1
- package/src/components/ui/radio-group.tsx +1 -1
- package/src/components/ui/select.tsx +5 -1
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/storefront/cart-popover.tsx +61 -0
- package/src/components/ui/storefront/cart-summary-parts.tsx +290 -0
- package/src/components/ui/storefront/cart-summary.tsx +93 -154
- package/src/components/ui/storefront/checkout-overlay.tsx +4 -5
- package/src/components/ui/storefront/listing-card.tsx +1 -1
- package/src/components/ui/storefront/merch-sections.tsx +70 -0
- package/src/components/ui/storefront/product-detail.tsx +1 -1
- package/src/components/ui/storefront/storefront-surface.test.tsx +106 -11
- package/src/components/ui/storefront/storefront-surface.tsx +101 -166
- package/src/components/ui/storefront/types.ts +4 -0
- package/src/components/ui/storefront/utils.ts +6 -0
- package/src/components/ui/text-editor/__tests__/extensions.test.ts +123 -0
- package/src/components/ui/text-editor/background-color-extension.ts +62 -0
- package/src/components/ui/text-editor/color-controls.tsx +284 -0
- package/src/components/ui/text-editor/editor.tsx +69 -14
- package/src/components/ui/text-editor/extensions.ts +8 -2
- package/src/components/ui/text-editor/highlight-extension.ts +22 -0
- package/src/components/ui/text-editor/tool-bar.tsx +9 -16
- package/src/components/ui/toast.tsx +1 -1
- package/src/components/ui/tu-do/boards/__tests__/board-share-dialog.test.tsx +270 -0
- package/src/components/ui/tu-do/boards/board-public-link-section.tsx +231 -0
- package/src/components/ui/tu-do/boards/board-share-dialog.tsx +222 -109
- package/src/components/ui/tu-do/boards/boardId/board-column.tsx +112 -43
- package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-clear-delete.ts +2 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-move.ts +5 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/bulk/bulk-mutations-updates.ts +3 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/data/kanban-deadline-query.ts +50 -2
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/__tests__/column-reorder.test.ts +17 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/column-reorder.ts +4 -1
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-drag-cache.ts +38 -9
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-drag-order.ts +2 -8
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/task-sort-key.ts +47 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/dnd/use-kanban-dnd.ts +81 -30
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/__tests__/kanban-planner-island.test.tsx +380 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/kanban-planner-dialog.tsx +204 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-digest-panel.tsx +61 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-item-strip.tsx +54 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-plan-toolbar.tsx +251 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-scope-badge.tsx +27 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-section.tsx +58 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-share-dialog.tsx +238 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-target-controls.tsx +143 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/planner-utils.ts +65 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/planner/use-kanban-planner-state.ts +234 -0
- package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-columns.test.tsx +397 -2
- package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-columns.tsx +103 -13
- package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-deadline-panels.tsx +443 -19
- package/src/components/ui/tu-do/boards/boardId/kanban/rendering/kanban-skeleton.tsx +94 -32
- package/src/components/ui/tu-do/boards/boardId/kanban.tsx +213 -106
- package/src/components/ui/tu-do/boards/boardId/task-board-server-page.test.tsx +26 -4
- package/src/components/ui/tu-do/boards/boardId/task-board-server-page.tsx +5 -2
- package/src/components/ui/tu-do/boards/boardId/task-card/measured-task-card.tsx +3 -0
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card-comparator.ts +3 -0
- package/src/components/ui/tu-do/boards/boardId/task-card/task-card.tsx +191 -28
- package/src/components/ui/tu-do/boards/boardId/task-filter.test.tsx +152 -0
- package/src/components/ui/tu-do/boards/boardId/task-filter.tsx +555 -545
- package/src/components/ui/tu-do/boards/boardId/task-list.tsx +7 -0
- package/src/components/ui/tu-do/boards/share-section.tsx +100 -0
- package/src/components/ui/tu-do/drafts/draft-convert-dialog.tsx +10 -12
- package/src/components/ui/tu-do/drafts/drafts-page.tsx +33 -16
- package/src/components/ui/tu-do/initiatives/task-initiatives-client.tsx +56 -88
- package/src/components/ui/tu-do/my-tasks/my-tasks-content.tsx +26 -2
- package/src/components/ui/tu-do/my-tasks/use-my-tasks-state.ts +55 -8
- package/src/components/ui/tu-do/notes/note-edit-dialog.tsx +1 -4
- package/src/components/ui/tu-do/shared/__tests__/board-client.test.tsx +25 -0
- package/src/components/ui/tu-do/shared/__tests__/board-header.test.tsx +341 -38
- package/src/components/ui/tu-do/shared/__tests__/board-switcher.test.tsx +253 -0
- package/src/components/ui/tu-do/shared/__tests__/board-views.test.tsx +203 -2
- package/src/components/ui/tu-do/shared/__tests__/task-board-loading-state.test.tsx +17 -0
- package/src/components/ui/tu-do/shared/__tests__/task-legacy-route-recovery.test.tsx +16 -0
- package/src/components/ui/tu-do/shared/board-client.tsx +2 -7
- package/src/components/ui/tu-do/shared/board-config-storage.ts +7 -1
- package/src/components/ui/tu-do/shared/board-header.tsx +464 -975
- package/src/components/ui/tu-do/shared/board-layout-settings.tsx +165 -136
- package/src/components/ui/tu-do/shared/board-switcher.tsx +209 -217
- package/src/components/ui/tu-do/shared/board-views.tsx +587 -75
- package/src/components/ui/tu-do/shared/list-view.tsx +227 -1
- package/src/components/ui/tu-do/shared/recycle-bin-panel.tsx +142 -94
- package/src/components/ui/tu-do/shared/special-task-list-pins.ts +51 -0
- package/src/components/ui/tu-do/shared/task-board-loading-state.tsx +28 -0
- package/src/components/ui/tu-do/shared/task-edit-dialog/field-diff-viewer.tsx +3 -2
- package/src/components/ui/tu-do/shared/task-edit-dialog/selective-revert-panel.test.tsx +91 -0
- package/src/components/ui/tu-do/shared/task-edit-dialog/selective-revert-panel.tsx +123 -78
- package/src/components/ui/tu-do/shared/task-edit-dialog/task-activity-section.tsx +7 -1
- package/src/components/ui/tu-do/shared/task-edit-dialog/task-snapshot-dialog.tsx +8 -3
- package/src/components/ui/tu-do/shared/task-edit-dialog.tsx +2 -1
- package/src/components/ui/tu-do/shared/task-legacy-route-recovery.tsx +2 -9
- package/src/declarations.d.ts +1 -0
- package/src/hooks/__tests__/use-calendar-readonly.test.tsx +322 -2
- package/src/hooks/__tests__/use-calendar-sync.test.tsx +446 -0
- package/src/hooks/use-calendar-sync.tsx +247 -243
- package/src/hooks/use-calendar.tsx +323 -138
- package/src/hooks/use-task-actions.ts +24 -0
- package/src/hooks/use-user-workspace-config.ts +75 -0
- package/src/hooks/use-workspace-currency.ts +8 -3
- package/src/hooks/useBoardRealtimeEventHandler.ts +11 -0
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react';
|
|
2
2
|
import type { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { CalendarProvider, useCalendar } from '../use-calendar';
|
|
6
6
|
|
|
7
7
|
const calendarMockState = vi.hoisted(() => ({
|
|
8
8
|
events: [] as CalendarEvent[],
|
|
9
|
+
patchVisibleEvents: vi.fn(),
|
|
10
|
+
refresh: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const internalApiMocks = vi.hoisted(() => ({
|
|
14
|
+
createWorkspaceCalendarEvent: vi.fn(),
|
|
15
|
+
deleteWorkspaceCalendarEvent: vi.fn(),
|
|
16
|
+
updateWorkspaceCalendarEvent: vi.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
vi.mock('@tuturuuu/internal-api', () => ({
|
|
20
|
+
createWorkspaceCalendarEvent: internalApiMocks.createWorkspaceCalendarEvent,
|
|
21
|
+
deleteWorkspaceCalendarEvent: internalApiMocks.deleteWorkspaceCalendarEvent,
|
|
22
|
+
updateWorkspaceCalendarEvent: internalApiMocks.updateWorkspaceCalendarEvent,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
vi.mock('@tuturuuu/supabase/next/client', () => ({
|
|
26
|
+
createClient: () => ({
|
|
27
|
+
auth: {
|
|
28
|
+
getUser: vi.fn().mockResolvedValue({ data: { user: null } }),
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
9
31
|
}));
|
|
10
32
|
|
|
11
33
|
// Mock useCalendarSync
|
|
12
34
|
vi.mock('../use-calendar-sync', () => ({
|
|
13
35
|
useCalendarSync: () => ({
|
|
14
36
|
events: calendarMockState.events,
|
|
15
|
-
|
|
37
|
+
patchVisibleEvents: calendarMockState.patchVisibleEvents,
|
|
38
|
+
refresh: calendarMockState.refresh,
|
|
16
39
|
}),
|
|
17
40
|
}));
|
|
18
41
|
|
|
19
42
|
describe('CalendarProvider Read-Only Mode', () => {
|
|
20
43
|
beforeEach(() => {
|
|
21
44
|
calendarMockState.events = [];
|
|
45
|
+
calendarMockState.patchVisibleEvents.mockReset();
|
|
46
|
+
calendarMockState.refresh.mockReset();
|
|
47
|
+
internalApiMocks.createWorkspaceCalendarEvent.mockReset();
|
|
48
|
+
internalApiMocks.deleteWorkspaceCalendarEvent.mockReset();
|
|
49
|
+
internalApiMocks.updateWorkspaceCalendarEvent.mockReset();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
vi.useRealTimers();
|
|
22
54
|
});
|
|
23
55
|
|
|
24
56
|
const mockUseQuery = vi
|
|
@@ -26,9 +58,32 @@ describe('CalendarProvider Read-Only Mode', () => {
|
|
|
26
58
|
.mockReturnValue({ data: null, isLoading: false });
|
|
27
59
|
const mockUseQueryClient = vi.fn().mockReturnValue({
|
|
28
60
|
invalidateQueries: vi.fn(),
|
|
61
|
+
setQueriesData: vi.fn(),
|
|
29
62
|
setQueryData: vi.fn(),
|
|
30
63
|
});
|
|
31
64
|
|
|
65
|
+
const createWrapper = ({ readOnly = false }: { readOnly?: boolean } = {}) =>
|
|
66
|
+
function Wrapper({ children }: { children: ReactNode }) {
|
|
67
|
+
return (
|
|
68
|
+
<CalendarProvider
|
|
69
|
+
ws={{ id: 'workspace-1', name: 'Workspace' } as any}
|
|
70
|
+
useQuery={mockUseQuery}
|
|
71
|
+
useQueryClient={mockUseQueryClient}
|
|
72
|
+
readOnly={readOnly}
|
|
73
|
+
>
|
|
74
|
+
{children}
|
|
75
|
+
</CalendarProvider>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const baseEvent: CalendarEvent = {
|
|
80
|
+
id: 'event-1',
|
|
81
|
+
title: 'Planning',
|
|
82
|
+
start_at: '2026-06-22T09:00:00.000Z',
|
|
83
|
+
end_at: '2026-06-22T10:00:00.000Z',
|
|
84
|
+
ws_id: 'workspace-1',
|
|
85
|
+
};
|
|
86
|
+
|
|
32
87
|
it('should have readOnly set to true when passed as prop', () => {
|
|
33
88
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
34
89
|
<CalendarProvider
|
|
@@ -158,4 +213,269 @@ describe('CalendarProvider Read-Only Mode', () => {
|
|
|
158
213
|
expect(result.current.isModalOpen).toBe(true);
|
|
159
214
|
expect(result.current.activeEvent?.id).toBe('new');
|
|
160
215
|
});
|
|
216
|
+
|
|
217
|
+
it('patches a created event optimistically before the network promise resolves', async () => {
|
|
218
|
+
let resolveCreate: ((event: CalendarEvent) => void) | undefined;
|
|
219
|
+
internalApiMocks.createWorkspaceCalendarEvent.mockReturnValue(
|
|
220
|
+
new Promise((resolve) => {
|
|
221
|
+
resolveCreate = resolve;
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
226
|
+
wrapper: createWrapper(),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
let createPromise: Promise<CalendarEvent | undefined>;
|
|
230
|
+
act(() => {
|
|
231
|
+
createPromise = result.current.addEvent({
|
|
232
|
+
title: 'New event',
|
|
233
|
+
start_at: '2026-06-22T09:00:00.000Z',
|
|
234
|
+
end_at: '2026-06-22T10:00:00.000Z',
|
|
235
|
+
ws_id: 'workspace-1',
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenCalledWith(
|
|
240
|
+
[expect.objectContaining({ _optimisticStatus: 'creating' })],
|
|
241
|
+
{ status: 'creating' }
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const serverEvent = {
|
|
245
|
+
...baseEvent,
|
|
246
|
+
id: 'event-created',
|
|
247
|
+
title: 'New event',
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
await act(async () => {
|
|
251
|
+
resolveCreate?.(serverEvent);
|
|
252
|
+
await createPromise!;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenLastCalledWith(
|
|
256
|
+
[serverEvent],
|
|
257
|
+
expect.objectContaining({
|
|
258
|
+
clearIds: [expect.stringMatching(/^optimistic-/)],
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('rolls back a failed optimistic create', async () => {
|
|
264
|
+
internalApiMocks.createWorkspaceCalendarEvent.mockRejectedValue(
|
|
265
|
+
new Error('create failed')
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
269
|
+
wrapper: createWrapper(),
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
await act(async () => {
|
|
273
|
+
await expect(
|
|
274
|
+
result.current.addEvent({
|
|
275
|
+
title: 'New event',
|
|
276
|
+
start_at: '2026-06-22T09:00:00.000Z',
|
|
277
|
+
end_at: '2026-06-22T10:00:00.000Z',
|
|
278
|
+
ws_id: 'workspace-1',
|
|
279
|
+
})
|
|
280
|
+
).rejects.toThrow('create failed');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenLastCalledWith(
|
|
284
|
+
[],
|
|
285
|
+
expect.objectContaining({
|
|
286
|
+
clearIds: [expect.stringMatching(/^optimistic-/)],
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('patches an updated event optimistically before the debounced network write', async () => {
|
|
292
|
+
vi.useFakeTimers();
|
|
293
|
+
calendarMockState.events = [baseEvent];
|
|
294
|
+
internalApiMocks.updateWorkspaceCalendarEvent.mockResolvedValue({
|
|
295
|
+
...baseEvent,
|
|
296
|
+
title: 'Updated',
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
300
|
+
wrapper: createWrapper(),
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
let updatePromise: Promise<CalendarEvent | undefined>;
|
|
304
|
+
act(() => {
|
|
305
|
+
updatePromise = result.current.updateEvent('event-1', {
|
|
306
|
+
title: 'Updated',
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenCalledWith(
|
|
311
|
+
[
|
|
312
|
+
expect.objectContaining({
|
|
313
|
+
_optimisticStatus: 'updating',
|
|
314
|
+
title: 'Updated',
|
|
315
|
+
}),
|
|
316
|
+
],
|
|
317
|
+
{ status: 'updating' }
|
|
318
|
+
);
|
|
319
|
+
expect(
|
|
320
|
+
internalApiMocks.updateWorkspaceCalendarEvent
|
|
321
|
+
).not.toHaveBeenCalled();
|
|
322
|
+
|
|
323
|
+
await act(async () => {
|
|
324
|
+
vi.advanceTimersByTime(250);
|
|
325
|
+
await updatePromise!;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
expect(internalApiMocks.updateWorkspaceCalendarEvent).toHaveBeenCalledWith(
|
|
329
|
+
'workspace-1',
|
|
330
|
+
'event-1',
|
|
331
|
+
expect.objectContaining({ title: 'Updated' }),
|
|
332
|
+
expect.any(Object)
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('rolls back a failed optimistic update', async () => {
|
|
337
|
+
vi.useFakeTimers();
|
|
338
|
+
calendarMockState.events = [baseEvent];
|
|
339
|
+
internalApiMocks.updateWorkspaceCalendarEvent.mockRejectedValue(
|
|
340
|
+
new Error('update failed')
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
344
|
+
wrapper: createWrapper(),
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
let updatePromise: Promise<CalendarEvent | undefined>;
|
|
348
|
+
act(() => {
|
|
349
|
+
updatePromise = result.current.updateEvent('event-1', {
|
|
350
|
+
title: 'Broken',
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
await act(async () => {
|
|
355
|
+
vi.advanceTimersByTime(250);
|
|
356
|
+
await expect(updatePromise!).rejects.toThrow('update failed');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenLastCalledWith([
|
|
360
|
+
baseEvent,
|
|
361
|
+
]);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('coalesces rapid event updates to the latest payload', async () => {
|
|
365
|
+
vi.useFakeTimers();
|
|
366
|
+
calendarMockState.events = [baseEvent];
|
|
367
|
+
internalApiMocks.updateWorkspaceCalendarEvent.mockResolvedValue({
|
|
368
|
+
...baseEvent,
|
|
369
|
+
start_at: '2026-06-22T09:30:00.000Z',
|
|
370
|
+
end_at: '2026-06-22T10:30:00.000Z',
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
374
|
+
wrapper: createWrapper(),
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
let firstPromise: Promise<CalendarEvent | undefined>;
|
|
378
|
+
let secondPromise: Promise<CalendarEvent | undefined>;
|
|
379
|
+
|
|
380
|
+
act(() => {
|
|
381
|
+
firstPromise = result.current.updateEvent('event-1', {
|
|
382
|
+
start_at: '2026-06-22T09:15:00.000Z',
|
|
383
|
+
end_at: '2026-06-22T10:15:00.000Z',
|
|
384
|
+
});
|
|
385
|
+
secondPromise = result.current.updateEvent('event-1', {
|
|
386
|
+
start_at: '2026-06-22T09:30:00.000Z',
|
|
387
|
+
end_at: '2026-06-22T10:30:00.000Z',
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
await act(async () => {
|
|
392
|
+
vi.advanceTimersByTime(250);
|
|
393
|
+
await Promise.all([firstPromise!, secondPromise!]);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
expect(internalApiMocks.updateWorkspaceCalendarEvent).toHaveBeenCalledTimes(
|
|
397
|
+
1
|
|
398
|
+
);
|
|
399
|
+
expect(internalApiMocks.updateWorkspaceCalendarEvent).toHaveBeenCalledWith(
|
|
400
|
+
'workspace-1',
|
|
401
|
+
'event-1',
|
|
402
|
+
expect.objectContaining({
|
|
403
|
+
end_at: '2026-06-22T10:30:00.000Z',
|
|
404
|
+
start_at: '2026-06-22T09:30:00.000Z',
|
|
405
|
+
}),
|
|
406
|
+
expect.any(Object)
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('marks a deleted event as pending before the network promise resolves', async () => {
|
|
411
|
+
calendarMockState.events = [baseEvent];
|
|
412
|
+
let resolveDelete:
|
|
413
|
+
| ((result: {
|
|
414
|
+
linkedTaskId: string | null;
|
|
415
|
+
skippedHabitId: string | null;
|
|
416
|
+
}) => void)
|
|
417
|
+
| undefined;
|
|
418
|
+
internalApiMocks.deleteWorkspaceCalendarEvent.mockReturnValue(
|
|
419
|
+
new Promise((resolve) => {
|
|
420
|
+
resolveDelete = resolve;
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
425
|
+
wrapper: createWrapper(),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
let deletePromise: Promise<void>;
|
|
429
|
+
act(() => {
|
|
430
|
+
deletePromise = result.current.deleteEvent('event-1');
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenCalledWith(
|
|
434
|
+
[
|
|
435
|
+
expect.objectContaining({
|
|
436
|
+
...baseEvent,
|
|
437
|
+
_optimisticStatus: 'deleting',
|
|
438
|
+
}),
|
|
439
|
+
],
|
|
440
|
+
{ status: 'deleting' }
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
await act(async () => {
|
|
444
|
+
resolveDelete?.({
|
|
445
|
+
linkedTaskId: null,
|
|
446
|
+
skippedHabitId: null,
|
|
447
|
+
});
|
|
448
|
+
await deletePromise!;
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
expect(internalApiMocks.deleteWorkspaceCalendarEvent).toHaveBeenCalledWith(
|
|
452
|
+
'workspace-1',
|
|
453
|
+
'event-1',
|
|
454
|
+
expect.any(Object)
|
|
455
|
+
);
|
|
456
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenLastCalledWith([], {
|
|
457
|
+
removeIds: ['event-1'],
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('restores a failed optimistic delete', async () => {
|
|
462
|
+
calendarMockState.events = [baseEvent];
|
|
463
|
+
internalApiMocks.deleteWorkspaceCalendarEvent.mockRejectedValue(
|
|
464
|
+
new Error('delete failed')
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
const { result } = renderHook(() => useCalendar(), {
|
|
468
|
+
wrapper: createWrapper(),
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
await act(async () => {
|
|
472
|
+
await expect(result.current.deleteEvent('event-1')).rejects.toThrow(
|
|
473
|
+
'delete failed'
|
|
474
|
+
);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
expect(calendarMockState.patchVisibleEvents).toHaveBeenLastCalledWith([
|
|
478
|
+
baseEvent,
|
|
479
|
+
]);
|
|
480
|
+
});
|
|
161
481
|
});
|