@object-ui/react 0.5.0 → 3.0.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +32 -0
- package/dist/LazyPluginLoader.d.ts +44 -0
- package/dist/LazyPluginLoader.js +92 -3
- package/dist/SchemaRenderer.d.ts +20 -1
- package/dist/SchemaRenderer.js +76 -13
- package/dist/components/form/FieldFactory.js +44 -40
- package/dist/components/form/FormRenderer.js +45 -3
- package/dist/context/ActionContext.d.ts +76 -0
- package/dist/context/ActionContext.js +139 -0
- package/dist/context/DndContext.d.ts +135 -0
- package/dist/context/DndContext.js +120 -0
- package/dist/context/NotificationContext.d.ts +113 -0
- package/dist/context/NotificationContext.js +130 -0
- package/dist/context/ThemeContext.d.ts +94 -0
- package/dist/context/ThemeContext.js +215 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.js +4 -0
- package/dist/hooks/index.d.ts +22 -0
- package/dist/hooks/index.js +22 -0
- package/dist/hooks/useActionRunner.d.ts +21 -7
- package/dist/hooks/useActionRunner.js +27 -7
- package/dist/hooks/useAnimation.d.ts +46 -0
- package/dist/hooks/useAnimation.js +59 -0
- package/dist/hooks/useClientNotifications.d.ts +53 -0
- package/dist/hooks/useClientNotifications.js +190 -0
- package/dist/hooks/useColumnSummary.d.ts +38 -0
- package/dist/hooks/useColumnSummary.js +54 -0
- package/dist/hooks/useCrudShortcuts.d.ts +39 -0
- package/dist/hooks/useCrudShortcuts.js +96 -0
- package/dist/hooks/useDensityMode.d.ts +48 -0
- package/dist/hooks/useDensityMode.js +60 -0
- package/dist/hooks/useDiscovery.d.ts +78 -0
- package/dist/hooks/useDiscovery.js +96 -0
- package/dist/hooks/useDynamicApp.d.ts +70 -0
- package/dist/hooks/useDynamicApp.js +92 -0
- package/dist/hooks/useETagCache.d.ts +75 -0
- package/dist/hooks/useETagCache.js +306 -0
- package/dist/hooks/useFocusManagement.d.ts +89 -0
- package/dist/hooks/useFocusManagement.js +188 -0
- package/dist/hooks/useFocusTrap.d.ts +41 -0
- package/dist/hooks/useFocusTrap.js +103 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +49 -0
- package/dist/hooks/useKeyboardShortcuts.js +86 -0
- package/dist/hooks/useNavigationOverlay.d.ts +78 -0
- package/dist/hooks/useNavigationOverlay.js +112 -0
- package/dist/hooks/useOffline.d.ts +96 -0
- package/dist/hooks/useOffline.js +185 -0
- package/dist/hooks/usePageTransition.d.ts +60 -0
- package/dist/hooks/usePageTransition.js +111 -0
- package/dist/hooks/usePageVariables.d.ts +67 -0
- package/dist/hooks/usePageVariables.js +109 -0
- package/dist/hooks/usePerformance.d.ts +87 -0
- package/dist/hooks/usePerformance.js +165 -0
- package/dist/hooks/usePerformanceBudget.d.ts +78 -0
- package/dist/hooks/usePerformanceBudget.js +209 -0
- package/dist/hooks/useReducedMotion.d.ts +28 -0
- package/dist/hooks/useReducedMotion.js +48 -0
- package/dist/hooks/useSchemaPersistence.d.ts +87 -0
- package/dist/hooks/useSchemaPersistence.js +173 -0
- package/dist/hooks/useViewData.d.ts +73 -0
- package/dist/hooks/useViewData.js +135 -0
- package/dist/hooks/useViewSharing.d.ts +57 -0
- package/dist/hooks/useViewSharing.js +74 -0
- package/dist/hooks/useViewTransition.d.ts +54 -0
- package/dist/hooks/useViewTransition.js +83 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/utils/i18n.d.ts +10 -0
- package/dist/utils/i18n.js +12 -0
- package/package.json +7 -5
- package/src/LazyPluginLoader.tsx +129 -7
- package/src/SchemaRenderer.tsx +122 -13
- package/src/__tests__/LazyPluginLoader.test.tsx +97 -1
- package/src/__tests__/SchemaRenderer.aria.test.tsx +118 -0
- package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +114 -0
- package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +132 -0
- package/src/__tests__/ThemeProvider.test.tsx +451 -0
- package/src/__tests__/useNavigationOverlay.test.ts +416 -0
- package/src/__tests__/useOffline.test.ts +198 -0
- package/src/__tests__/usePageTransition.test.ts +214 -0
- package/src/__tests__/usePageVariables.test.tsx +334 -0
- package/src/__tests__/usePerformance.test.ts +137 -0
- package/src/__tests__/useViewData.test.tsx +422 -0
- package/src/__tests__/view-switching.test.tsx +456 -0
- package/src/components/form/FieldFactory.tsx +51 -46
- package/src/components/form/FormRenderer.test.tsx +145 -0
- package/src/components/form/FormRenderer.tsx +52 -3
- package/src/context/ActionContext.tsx +213 -0
- package/src/context/DndContext.tsx +260 -0
- package/src/context/NotificationContext.tsx +280 -0
- package/src/context/ThemeContext.tsx +325 -0
- package/src/context/__tests__/ActionContext.test.tsx +174 -0
- package/src/context/__tests__/DndContext.test.tsx +150 -0
- package/src/context/__tests__/NotificationContext.test.tsx +176 -0
- package/src/context/index.ts +4 -0
- package/src/hooks/__tests__/useActionRunner.test.ts +153 -0
- package/src/hooks/__tests__/useAnimation.test.ts +82 -0
- package/src/hooks/__tests__/useColumnSummary.test.ts +93 -0
- package/src/hooks/__tests__/useDensityMode.test.ts +81 -0
- package/src/hooks/__tests__/useDiscovery.test.tsx +149 -0
- package/src/hooks/__tests__/useDynamicApp.test.ts +161 -0
- package/src/hooks/__tests__/useETagCache.test.ts +153 -0
- package/src/hooks/__tests__/useExpression.test.ts +86 -0
- package/src/hooks/__tests__/useFocusTrap.test.ts +47 -0
- package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +144 -0
- package/src/hooks/__tests__/usePerformanceBudget.test.ts +157 -0
- package/src/hooks/__tests__/useSchemaPersistence.test.ts +220 -0
- package/src/hooks/__tests__/useViewSharing.test.ts +121 -0
- package/src/hooks/__tests__/useViewTransition.test.ts +61 -0
- package/src/hooks/index.ts +22 -1
- package/src/hooks/useActionRunner.ts +49 -11
- package/src/hooks/useAnimation.ts +117 -0
- package/src/hooks/useClientNotifications.ts +251 -0
- package/src/hooks/useColumnSummary.ts +87 -0
- package/src/hooks/useCrudShortcuts.ts +126 -0
- package/src/hooks/useDensityMode.ts +102 -0
- package/src/hooks/useDiscovery.ts +141 -0
- package/src/hooks/useDynamicApp.ts +142 -0
- package/src/hooks/useETagCache.ts +404 -0
- package/src/hooks/useFocusManagement.ts +248 -0
- package/src/hooks/useFocusTrap.ts +138 -0
- package/src/hooks/useKeyboardShortcuts.ts +119 -0
- package/src/hooks/useNavigationOverlay.ts +180 -0
- package/src/hooks/useOffline.ts +301 -0
- package/src/hooks/usePageTransition.ts +187 -0
- package/src/hooks/usePageVariables.tsx +157 -0
- package/src/hooks/usePerformance.ts +246 -0
- package/src/hooks/usePerformanceBudget.ts +313 -0
- package/src/hooks/useReducedMotion.ts +53 -0
- package/src/hooks/useSchemaPersistence.ts +222 -0
- package/src/hooks/useViewData.ts +201 -0
- package/src/hooks/useViewSharing.ts +140 -0
- package/src/hooks/useViewTransition.ts +144 -0
- package/src/index.ts +21 -0
- package/src/utils/i18n.ts +10 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/__tests__/LazyPluginLoader.test.d.ts +0 -8
- package/dist/__tests__/LazyPluginLoader.test.js +0 -49
- package/dist/components/form/FormRenderer.test.d.ts +0 -8
- package/dist/components/form/FormRenderer.test.js +0 -534
- package/dist/index.test.d.ts +0 -8
- package/dist/index.test.js +0 -13
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI — View Switching State Preservation Tests
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Tests that switching between grid ↔ kanban ↔ calendar views preserves
|
|
9
|
+
* selection state, scroll position concept, and filter criteria.
|
|
10
|
+
* Part of P2.4 Performance at Scale roadmap.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
14
|
+
import { renderHook, act } from '@testing-library/react';
|
|
15
|
+
import React from 'react';
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Types for view switching state management
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
type ViewType = 'grid' | 'kanban' | 'calendar';
|
|
22
|
+
|
|
23
|
+
interface ViewState {
|
|
24
|
+
currentView: ViewType;
|
|
25
|
+
selectedIds: string[];
|
|
26
|
+
filters: Record<string, string>;
|
|
27
|
+
scrollPosition: number;
|
|
28
|
+
sortField?: string;
|
|
29
|
+
sortDirection?: 'asc' | 'desc';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// useViewSwitcher hook — manages cross-view state preservation
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
function useViewSwitcher(initialView: ViewType = 'grid') {
|
|
37
|
+
const [state, setState] = React.useState<ViewState>({
|
|
38
|
+
currentView: initialView,
|
|
39
|
+
selectedIds: [],
|
|
40
|
+
filters: {},
|
|
41
|
+
scrollPosition: 0,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const switchView = React.useCallback(
|
|
45
|
+
(newView: ViewType) => {
|
|
46
|
+
setState((prev) => ({
|
|
47
|
+
...prev,
|
|
48
|
+
currentView: newView,
|
|
49
|
+
}));
|
|
50
|
+
},
|
|
51
|
+
[],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const setSelectedIds = React.useCallback(
|
|
55
|
+
(ids: string[]) => {
|
|
56
|
+
setState((prev) => ({ ...prev, selectedIds: ids }));
|
|
57
|
+
},
|
|
58
|
+
[],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const setFilters = React.useCallback(
|
|
62
|
+
(filters: Record<string, string>) => {
|
|
63
|
+
setState((prev) => ({ ...prev, filters }));
|
|
64
|
+
},
|
|
65
|
+
[],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const setScrollPosition = React.useCallback(
|
|
69
|
+
(position: number) => {
|
|
70
|
+
setState((prev) => ({ ...prev, scrollPosition: position }));
|
|
71
|
+
},
|
|
72
|
+
[],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const setSort = React.useCallback(
|
|
76
|
+
(field: string, direction: 'asc' | 'desc') => {
|
|
77
|
+
setState((prev) => ({ ...prev, sortField: field, sortDirection: direction }));
|
|
78
|
+
},
|
|
79
|
+
[],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const clearSelection = React.useCallback(() => {
|
|
83
|
+
setState((prev) => ({ ...prev, selectedIds: [] }));
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const clearFilters = React.useCallback(() => {
|
|
87
|
+
setState((prev) => ({ ...prev, filters: {} }));
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
state,
|
|
92
|
+
switchView,
|
|
93
|
+
setSelectedIds,
|
|
94
|
+
setFilters,
|
|
95
|
+
setScrollPosition,
|
|
96
|
+
setSort,
|
|
97
|
+
clearSelection,
|
|
98
|
+
clearFilters,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Tests
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
describe('View Switching: state preservation', () => {
|
|
107
|
+
it('should initialize with default view and empty state', () => {
|
|
108
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
109
|
+
|
|
110
|
+
expect(result.current.state.currentView).toBe('grid');
|
|
111
|
+
expect(result.current.state.selectedIds).toEqual([]);
|
|
112
|
+
expect(result.current.state.filters).toEqual({});
|
|
113
|
+
expect(result.current.state.scrollPosition).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should switch from grid to kanban while preserving selection', () => {
|
|
117
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
118
|
+
|
|
119
|
+
act(() => {
|
|
120
|
+
result.current.setSelectedIds(['row-1', 'row-5', 'row-10']);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(result.current.state.selectedIds).toEqual(['row-1', 'row-5', 'row-10']);
|
|
124
|
+
|
|
125
|
+
act(() => {
|
|
126
|
+
result.current.switchView('kanban');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(result.current.state.currentView).toBe('kanban');
|
|
130
|
+
expect(result.current.state.selectedIds).toEqual(['row-1', 'row-5', 'row-10']);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should switch from kanban to calendar while preserving selection', () => {
|
|
134
|
+
const { result } = renderHook(() => useViewSwitcher('kanban'));
|
|
135
|
+
|
|
136
|
+
act(() => {
|
|
137
|
+
result.current.setSelectedIds(['card-3', 'card-7']);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
act(() => {
|
|
141
|
+
result.current.switchView('calendar');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(result.current.state.currentView).toBe('calendar');
|
|
145
|
+
expect(result.current.state.selectedIds).toEqual(['card-3', 'card-7']);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should switch from calendar to grid while preserving selection', () => {
|
|
149
|
+
const { result } = renderHook(() => useViewSwitcher('calendar'));
|
|
150
|
+
|
|
151
|
+
act(() => {
|
|
152
|
+
result.current.setSelectedIds(['event-1']);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
act(() => {
|
|
156
|
+
result.current.switchView('grid');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(result.current.state.currentView).toBe('grid');
|
|
160
|
+
expect(result.current.state.selectedIds).toEqual(['event-1']);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('View Switching: filter preservation', () => {
|
|
165
|
+
it('should preserve filters when switching grid → kanban', () => {
|
|
166
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
167
|
+
|
|
168
|
+
act(() => {
|
|
169
|
+
result.current.setFilters({ status: 'active', department: 'engineering' });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
act(() => {
|
|
173
|
+
result.current.switchView('kanban');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(result.current.state.currentView).toBe('kanban');
|
|
177
|
+
expect(result.current.state.filters).toEqual({
|
|
178
|
+
status: 'active',
|
|
179
|
+
department: 'engineering',
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should preserve filters when switching kanban → calendar', () => {
|
|
184
|
+
const { result } = renderHook(() => useViewSwitcher('kanban'));
|
|
185
|
+
|
|
186
|
+
act(() => {
|
|
187
|
+
result.current.setFilters({ priority: 'high' });
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
act(() => {
|
|
191
|
+
result.current.switchView('calendar');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(result.current.state.filters).toEqual({ priority: 'high' });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('should preserve filters across multiple view switches', () => {
|
|
198
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
199
|
+
|
|
200
|
+
act(() => {
|
|
201
|
+
result.current.setFilters({ type: 'bug', assignee: 'alice' });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// grid → kanban
|
|
205
|
+
act(() => {
|
|
206
|
+
result.current.switchView('kanban');
|
|
207
|
+
});
|
|
208
|
+
expect(result.current.state.filters).toEqual({ type: 'bug', assignee: 'alice' });
|
|
209
|
+
|
|
210
|
+
// kanban → calendar
|
|
211
|
+
act(() => {
|
|
212
|
+
result.current.switchView('calendar');
|
|
213
|
+
});
|
|
214
|
+
expect(result.current.state.filters).toEqual({ type: 'bug', assignee: 'alice' });
|
|
215
|
+
|
|
216
|
+
// calendar → grid
|
|
217
|
+
act(() => {
|
|
218
|
+
result.current.switchView('grid');
|
|
219
|
+
});
|
|
220
|
+
expect(result.current.state.filters).toEqual({ type: 'bug', assignee: 'alice' });
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should allow clearing filters independently of view switch', () => {
|
|
224
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
225
|
+
|
|
226
|
+
act(() => {
|
|
227
|
+
result.current.setFilters({ status: 'open' });
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
act(() => {
|
|
231
|
+
result.current.switchView('kanban');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
act(() => {
|
|
235
|
+
result.current.clearFilters();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
expect(result.current.state.currentView).toBe('kanban');
|
|
239
|
+
expect(result.current.state.filters).toEqual({});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe('View Switching: scroll position preservation', () => {
|
|
244
|
+
it('should preserve scroll position when switching views', () => {
|
|
245
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
246
|
+
|
|
247
|
+
act(() => {
|
|
248
|
+
result.current.setScrollPosition(1500);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
act(() => {
|
|
252
|
+
result.current.switchView('kanban');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(result.current.state.scrollPosition).toBe(1500);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should preserve scroll position across full cycle: grid → kanban → calendar → grid', () => {
|
|
259
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
260
|
+
|
|
261
|
+
act(() => {
|
|
262
|
+
result.current.setScrollPosition(3200);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
act(() => {
|
|
266
|
+
result.current.switchView('kanban');
|
|
267
|
+
});
|
|
268
|
+
expect(result.current.state.scrollPosition).toBe(3200);
|
|
269
|
+
|
|
270
|
+
act(() => {
|
|
271
|
+
result.current.switchView('calendar');
|
|
272
|
+
});
|
|
273
|
+
expect(result.current.state.scrollPosition).toBe(3200);
|
|
274
|
+
|
|
275
|
+
act(() => {
|
|
276
|
+
result.current.switchView('grid');
|
|
277
|
+
});
|
|
278
|
+
expect(result.current.state.scrollPosition).toBe(3200);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('View Switching: sort preservation', () => {
|
|
283
|
+
it('should preserve sort when switching views', () => {
|
|
284
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
285
|
+
|
|
286
|
+
act(() => {
|
|
287
|
+
result.current.setSort('name', 'asc');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
act(() => {
|
|
291
|
+
result.current.switchView('kanban');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
expect(result.current.state.sortField).toBe('name');
|
|
295
|
+
expect(result.current.state.sortDirection).toBe('asc');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should preserve sort across multiple switches', () => {
|
|
299
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
300
|
+
|
|
301
|
+
act(() => {
|
|
302
|
+
result.current.setSort('createdAt', 'desc');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
act(() => {
|
|
306
|
+
result.current.switchView('calendar');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
act(() => {
|
|
310
|
+
result.current.switchView('kanban');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
expect(result.current.state.sortField).toBe('createdAt');
|
|
314
|
+
expect(result.current.state.sortDirection).toBe('desc');
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe('View Switching: combined state preservation', () => {
|
|
319
|
+
it('should preserve all state simultaneously when switching views', () => {
|
|
320
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
321
|
+
|
|
322
|
+
// Set up complex state
|
|
323
|
+
act(() => {
|
|
324
|
+
result.current.setSelectedIds(['item-1', 'item-2', 'item-3']);
|
|
325
|
+
result.current.setFilters({ status: 'active', priority: 'high' });
|
|
326
|
+
result.current.setScrollPosition(2500);
|
|
327
|
+
result.current.setSort('title', 'asc');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Switch to kanban
|
|
331
|
+
act(() => {
|
|
332
|
+
result.current.switchView('kanban');
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
expect(result.current.state.currentView).toBe('kanban');
|
|
336
|
+
expect(result.current.state.selectedIds).toEqual(['item-1', 'item-2', 'item-3']);
|
|
337
|
+
expect(result.current.state.filters).toEqual({ status: 'active', priority: 'high' });
|
|
338
|
+
expect(result.current.state.scrollPosition).toBe(2500);
|
|
339
|
+
expect(result.current.state.sortField).toBe('title');
|
|
340
|
+
expect(result.current.state.sortDirection).toBe('asc');
|
|
341
|
+
|
|
342
|
+
// Switch to calendar
|
|
343
|
+
act(() => {
|
|
344
|
+
result.current.switchView('calendar');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
expect(result.current.state.currentView).toBe('calendar');
|
|
348
|
+
expect(result.current.state.selectedIds).toEqual(['item-1', 'item-2', 'item-3']);
|
|
349
|
+
expect(result.current.state.filters).toEqual({ status: 'active', priority: 'high' });
|
|
350
|
+
expect(result.current.state.scrollPosition).toBe(2500);
|
|
351
|
+
expect(result.current.state.sortField).toBe('title');
|
|
352
|
+
expect(result.current.state.sortDirection).toBe('asc');
|
|
353
|
+
|
|
354
|
+
// Switch back to grid
|
|
355
|
+
act(() => {
|
|
356
|
+
result.current.switchView('grid');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(result.current.state.currentView).toBe('grid');
|
|
360
|
+
expect(result.current.state.selectedIds).toEqual(['item-1', 'item-2', 'item-3']);
|
|
361
|
+
expect(result.current.state.filters).toEqual({ status: 'active', priority: 'high' });
|
|
362
|
+
expect(result.current.state.scrollPosition).toBe(2500);
|
|
363
|
+
expect(result.current.state.sortField).toBe('title');
|
|
364
|
+
expect(result.current.state.sortDirection).toBe('asc');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('should allow modifying state after view switch', () => {
|
|
368
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
369
|
+
|
|
370
|
+
act(() => {
|
|
371
|
+
result.current.setSelectedIds(['item-1']);
|
|
372
|
+
result.current.setFilters({ status: 'open' });
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
act(() => {
|
|
376
|
+
result.current.switchView('kanban');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// Modify state in kanban view
|
|
380
|
+
act(() => {
|
|
381
|
+
result.current.setSelectedIds(['item-1', 'item-4']);
|
|
382
|
+
result.current.setFilters({ status: 'open', type: 'feature' });
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
expect(result.current.state.selectedIds).toEqual(['item-1', 'item-4']);
|
|
386
|
+
expect(result.current.state.filters).toEqual({ status: 'open', type: 'feature' });
|
|
387
|
+
|
|
388
|
+
// Switch to calendar - should have updated state
|
|
389
|
+
act(() => {
|
|
390
|
+
result.current.switchView('calendar');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
expect(result.current.state.selectedIds).toEqual(['item-1', 'item-4']);
|
|
394
|
+
expect(result.current.state.filters).toEqual({ status: 'open', type: 'feature' });
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('should handle clearing selection independently of other state', () => {
|
|
398
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
399
|
+
|
|
400
|
+
act(() => {
|
|
401
|
+
result.current.setSelectedIds(['a', 'b', 'c']);
|
|
402
|
+
result.current.setFilters({ status: 'done' });
|
|
403
|
+
result.current.setScrollPosition(800);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
act(() => {
|
|
407
|
+
result.current.switchView('kanban');
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
act(() => {
|
|
411
|
+
result.current.clearSelection();
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(result.current.state.selectedIds).toEqual([]);
|
|
415
|
+
expect(result.current.state.filters).toEqual({ status: 'done' });
|
|
416
|
+
expect(result.current.state.scrollPosition).toBe(800);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
describe('View Switching: rapid switching', () => {
|
|
421
|
+
it('should handle rapid view switches without losing state', () => {
|
|
422
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
423
|
+
|
|
424
|
+
act(() => {
|
|
425
|
+
result.current.setSelectedIds(['item-1']);
|
|
426
|
+
result.current.setFilters({ query: 'test' });
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// Rapid switches
|
|
430
|
+
act(() => {
|
|
431
|
+
result.current.switchView('kanban');
|
|
432
|
+
result.current.switchView('calendar');
|
|
433
|
+
result.current.switchView('grid');
|
|
434
|
+
result.current.switchView('kanban');
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
expect(result.current.state.currentView).toBe('kanban');
|
|
438
|
+
expect(result.current.state.selectedIds).toEqual(['item-1']);
|
|
439
|
+
expect(result.current.state.filters).toEqual({ query: 'test' });
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('should handle switching to the same view', () => {
|
|
443
|
+
const { result } = renderHook(() => useViewSwitcher('grid'));
|
|
444
|
+
|
|
445
|
+
act(() => {
|
|
446
|
+
result.current.setSelectedIds(['x']);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
act(() => {
|
|
450
|
+
result.current.switchView('grid');
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
expect(result.current.state.currentView).toBe('grid');
|
|
454
|
+
expect(result.current.state.selectedIds).toEqual(['x']);
|
|
455
|
+
});
|
|
456
|
+
});
|