@object-ui/react 3.1.5 → 3.3.1
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 +25 -0
- package/README.md +28 -3
- package/dist/SchemaRenderer.js +2 -2
- package/dist/components/form/FieldFactory.js +5 -2
- package/dist/context/AppShellContext.d.ts +26 -0
- package/dist/context/AppShellContext.js +67 -0
- package/dist/context/index.d.ts +1 -7
- package/dist/context/index.js +1 -7
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useDataRefresh.d.ts +36 -0
- package/dist/hooks/useDataRefresh.js +50 -0
- package/dist/hooks/useDiscovery.d.ts +12 -0
- package/dist/hooks/useDiscovery.js +6 -0
- package/dist/hooks/usePerformanceBudget.js +1 -1
- package/package.json +32 -9
- package/.turbo/turbo-build.log +0 -4
- package/src/LazyPluginLoader.tsx +0 -174
- package/src/SchemaRenderer.tsx +0 -266
- package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
- package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
- package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
- package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
- package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
- package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
- package/src/__tests__/ThemeProvider.test.tsx +0 -451
- package/src/__tests__/useNavigationOverlay.test.ts +0 -578
- package/src/__tests__/useOffline.test.ts +0 -198
- package/src/__tests__/usePageTransition.test.ts +0 -214
- package/src/__tests__/usePageVariables.test.tsx +0 -334
- package/src/__tests__/usePerformance.test.ts +0 -137
- package/src/__tests__/useViewData.test.tsx +0 -422
- package/src/__tests__/view-switching.test.tsx +0 -456
- package/src/components/form/FieldFactory.tsx +0 -509
- package/src/components/form/FormRenderer.test.tsx +0 -744
- package/src/components/form/FormRenderer.tsx +0 -258
- package/src/components/form/README.md +0 -352
- package/src/components/form/index.ts +0 -12
- package/src/context/ActionContext.tsx +0 -213
- package/src/context/DndContext.tsx +0 -260
- package/src/context/NotificationContext.tsx +0 -280
- package/src/context/SchemaRendererContext.tsx +0 -48
- package/src/context/ThemeContext.tsx +0 -325
- package/src/context/__tests__/ActionContext.test.tsx +0 -174
- package/src/context/__tests__/DndContext.test.tsx +0 -150
- package/src/context/__tests__/NotificationContext.test.tsx +0 -176
- package/src/context/__tests__/useDataScope.test.tsx +0 -91
- package/src/context/index.ts +0 -13
- package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
- package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
- package/src/hooks/__tests__/useAnimation.test.ts +0 -82
- package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
- package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
- package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
- package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
- package/src/hooks/__tests__/useDiscovery.test.tsx +0 -149
- package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
- package/src/hooks/__tests__/useETagCache.test.ts +0 -153
- package/src/hooks/__tests__/useExpression.test.ts +0 -86
- package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
- package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
- package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
- package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
- package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
- package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
- package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
- package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
- package/src/hooks/index.ts +0 -35
- package/src/hooks/useActionEngine.ts +0 -84
- package/src/hooks/useActionRunner.ts +0 -119
- package/src/hooks/useAnimation.ts +0 -117
- package/src/hooks/useClientNotifications.ts +0 -251
- package/src/hooks/useColumnSummary.ts +0 -87
- package/src/hooks/useCrudShortcuts.ts +0 -126
- package/src/hooks/useDebugMode.ts +0 -95
- package/src/hooks/useDensityMode.ts +0 -102
- package/src/hooks/useDiscovery.ts +0 -154
- package/src/hooks/useDynamicApp.ts +0 -142
- package/src/hooks/useETagCache.ts +0 -404
- package/src/hooks/useExpression.ts +0 -56
- package/src/hooks/useFocusManagement.ts +0 -248
- package/src/hooks/useFocusTrap.ts +0 -138
- package/src/hooks/useGlobalUndo.ts +0 -98
- package/src/hooks/useKeyboardShortcuts.ts +0 -119
- package/src/hooks/useNavigationOverlay.ts +0 -190
- package/src/hooks/useOffline.ts +0 -301
- package/src/hooks/usePageTransition.ts +0 -187
- package/src/hooks/usePageVariables.tsx +0 -157
- package/src/hooks/usePerformance.ts +0 -246
- package/src/hooks/usePerformanceBudget.ts +0 -313
- package/src/hooks/useReducedMotion.ts +0 -53
- package/src/hooks/useSchemaPersistence.ts +0 -222
- package/src/hooks/useViewData.ts +0 -201
- package/src/hooks/useViewSharing.ts +0 -140
- package/src/hooks/useViewTransition.ts +0 -144
- package/src/index.ts +0 -41
- package/src/spec-bridge/SpecBridge.ts +0 -64
- package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
- package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
- package/src/spec-bridge/bridges/dashboard.ts +0 -180
- package/src/spec-bridge/bridges/form-view.ts +0 -109
- package/src/spec-bridge/bridges/list-view.ts +0 -187
- package/src/spec-bridge/bridges/page.ts +0 -136
- package/src/spec-bridge/index.ts +0 -14
- package/src/spec-bridge/types.ts +0 -38
- package/src/utils/i18n.ts +0 -10
- package/tsconfig.json +0 -17
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -2
|
@@ -1,456 +0,0 @@
|
|
|
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
|
-
});
|