@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.
Files changed (109) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +28 -3
  3. package/dist/SchemaRenderer.js +2 -2
  4. package/dist/components/form/FieldFactory.js +5 -2
  5. package/dist/context/AppShellContext.d.ts +26 -0
  6. package/dist/context/AppShellContext.js +67 -0
  7. package/dist/context/index.d.ts +1 -7
  8. package/dist/context/index.js +1 -7
  9. package/dist/hooks/index.d.ts +1 -0
  10. package/dist/hooks/index.js +1 -0
  11. package/dist/hooks/useDataRefresh.d.ts +36 -0
  12. package/dist/hooks/useDataRefresh.js +50 -0
  13. package/dist/hooks/useDiscovery.d.ts +12 -0
  14. package/dist/hooks/useDiscovery.js +6 -0
  15. package/dist/hooks/usePerformanceBudget.js +1 -1
  16. package/package.json +32 -9
  17. package/.turbo/turbo-build.log +0 -4
  18. package/src/LazyPluginLoader.tsx +0 -174
  19. package/src/SchemaRenderer.tsx +0 -266
  20. package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
  21. package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
  22. package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
  23. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
  24. package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
  25. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
  26. package/src/__tests__/ThemeProvider.test.tsx +0 -451
  27. package/src/__tests__/useNavigationOverlay.test.ts +0 -578
  28. package/src/__tests__/useOffline.test.ts +0 -198
  29. package/src/__tests__/usePageTransition.test.ts +0 -214
  30. package/src/__tests__/usePageVariables.test.tsx +0 -334
  31. package/src/__tests__/usePerformance.test.ts +0 -137
  32. package/src/__tests__/useViewData.test.tsx +0 -422
  33. package/src/__tests__/view-switching.test.tsx +0 -456
  34. package/src/components/form/FieldFactory.tsx +0 -509
  35. package/src/components/form/FormRenderer.test.tsx +0 -744
  36. package/src/components/form/FormRenderer.tsx +0 -258
  37. package/src/components/form/README.md +0 -352
  38. package/src/components/form/index.ts +0 -12
  39. package/src/context/ActionContext.tsx +0 -213
  40. package/src/context/DndContext.tsx +0 -260
  41. package/src/context/NotificationContext.tsx +0 -280
  42. package/src/context/SchemaRendererContext.tsx +0 -48
  43. package/src/context/ThemeContext.tsx +0 -325
  44. package/src/context/__tests__/ActionContext.test.tsx +0 -174
  45. package/src/context/__tests__/DndContext.test.tsx +0 -150
  46. package/src/context/__tests__/NotificationContext.test.tsx +0 -176
  47. package/src/context/__tests__/useDataScope.test.tsx +0 -91
  48. package/src/context/index.ts +0 -13
  49. package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
  50. package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
  51. package/src/hooks/__tests__/useAnimation.test.ts +0 -82
  52. package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
  53. package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
  54. package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
  55. package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
  56. package/src/hooks/__tests__/useDiscovery.test.tsx +0 -149
  57. package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
  58. package/src/hooks/__tests__/useETagCache.test.ts +0 -153
  59. package/src/hooks/__tests__/useExpression.test.ts +0 -86
  60. package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
  61. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
  62. package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
  63. package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
  64. package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
  65. package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
  66. package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
  67. package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
  68. package/src/hooks/index.ts +0 -35
  69. package/src/hooks/useActionEngine.ts +0 -84
  70. package/src/hooks/useActionRunner.ts +0 -119
  71. package/src/hooks/useAnimation.ts +0 -117
  72. package/src/hooks/useClientNotifications.ts +0 -251
  73. package/src/hooks/useColumnSummary.ts +0 -87
  74. package/src/hooks/useCrudShortcuts.ts +0 -126
  75. package/src/hooks/useDebugMode.ts +0 -95
  76. package/src/hooks/useDensityMode.ts +0 -102
  77. package/src/hooks/useDiscovery.ts +0 -154
  78. package/src/hooks/useDynamicApp.ts +0 -142
  79. package/src/hooks/useETagCache.ts +0 -404
  80. package/src/hooks/useExpression.ts +0 -56
  81. package/src/hooks/useFocusManagement.ts +0 -248
  82. package/src/hooks/useFocusTrap.ts +0 -138
  83. package/src/hooks/useGlobalUndo.ts +0 -98
  84. package/src/hooks/useKeyboardShortcuts.ts +0 -119
  85. package/src/hooks/useNavigationOverlay.ts +0 -190
  86. package/src/hooks/useOffline.ts +0 -301
  87. package/src/hooks/usePageTransition.ts +0 -187
  88. package/src/hooks/usePageVariables.tsx +0 -157
  89. package/src/hooks/usePerformance.ts +0 -246
  90. package/src/hooks/usePerformanceBudget.ts +0 -313
  91. package/src/hooks/useReducedMotion.ts +0 -53
  92. package/src/hooks/useSchemaPersistence.ts +0 -222
  93. package/src/hooks/useViewData.ts +0 -201
  94. package/src/hooks/useViewSharing.ts +0 -140
  95. package/src/hooks/useViewTransition.ts +0 -144
  96. package/src/index.ts +0 -41
  97. package/src/spec-bridge/SpecBridge.ts +0 -64
  98. package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
  99. package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
  100. package/src/spec-bridge/bridges/dashboard.ts +0 -180
  101. package/src/spec-bridge/bridges/form-view.ts +0 -109
  102. package/src/spec-bridge/bridges/list-view.ts +0 -187
  103. package/src/spec-bridge/bridges/page.ts +0 -136
  104. package/src/spec-bridge/index.ts +0 -14
  105. package/src/spec-bridge/types.ts +0 -38
  106. package/src/utils/i18n.ts +0 -10
  107. package/tsconfig.json +0 -17
  108. package/tsconfig.tsbuildinfo +0 -1
  109. package/vitest.config.ts +0 -2
@@ -1,294 +0,0 @@
1
- /**
2
- * Tests for useFocusTrap hook
3
- */
4
- import { describe, it, expect, vi } from 'vitest';
5
- import { renderHook, act } from '@testing-library/react';
6
- import { useFocusTrap } from '../useFocusTrap';
7
-
8
- describe('useFocusTrap', () => {
9
- it('returns a ref object', () => {
10
- const { result } = renderHook(() => useFocusTrap());
11
- expect(result.current).toBeDefined();
12
- expect(result.current).toHaveProperty('current');
13
- });
14
-
15
- it('returns a ref with null initial value', () => {
16
- const { result } = renderHook(() => useFocusTrap());
17
- expect(result.current.current).toBeNull();
18
- });
19
-
20
- it('accepts disabled option', () => {
21
- const { result } = renderHook(() =>
22
- useFocusTrap({ enabled: false })
23
- );
24
- expect(result.current).toBeDefined();
25
- });
26
-
27
- it('accepts all options without error', () => {
28
- const onEscape = vi.fn();
29
- const { result } = renderHook(() =>
30
- useFocusTrap({
31
- enabled: true,
32
- autoFocus: true,
33
- restoreFocus: true,
34
- escapeDeactivates: true,
35
- onEscape,
36
- initialFocus: '.first-input',
37
- })
38
- );
39
- expect(result.current).toBeDefined();
40
- });
41
-
42
- it('defaults to enabled when no options provided', () => {
43
- const { result } = renderHook(() => useFocusTrap());
44
- // Should not throw
45
- expect(result.current.current).toBeNull();
46
- });
47
-
48
- it('auto-focuses the first focusable element when enabled', () => {
49
- const container = document.createElement('div');
50
- const button = document.createElement('button');
51
- button.textContent = 'Click me';
52
- container.appendChild(button);
53
- document.body.appendChild(container);
54
-
55
- const { result } = renderHook(() =>
56
- useFocusTrap<HTMLDivElement>({ enabled: true, autoFocus: true })
57
- );
58
-
59
- act(() => {
60
- (result.current as any).current = container;
61
- });
62
-
63
- // Re-render to trigger effect with the ref set
64
- const { result: result2 } = renderHook(() =>
65
- useFocusTrap<HTMLDivElement>({ enabled: true, autoFocus: true })
66
- );
67
-
68
- document.body.removeChild(container);
69
- });
70
-
71
- it('focuses initialFocus selector when provided', () => {
72
- const container = document.createElement('div');
73
- const input1 = document.createElement('input');
74
- const input2 = document.createElement('input');
75
- input2.className = 'target-input';
76
- container.appendChild(input1);
77
- container.appendChild(input2);
78
- document.body.appendChild(container);
79
-
80
- const focusSpy = vi.spyOn(input2, 'focus');
81
-
82
- const { result, rerender } = renderHook(
83
- ({ enabled }) =>
84
- useFocusTrap<HTMLDivElement>({
85
- enabled,
86
- autoFocus: true,
87
- initialFocus: '.target-input',
88
- }),
89
- { initialProps: { enabled: false } }
90
- );
91
-
92
- // Set the ref
93
- (result.current as any).current = container;
94
-
95
- // Enable the trap to trigger the effect
96
- rerender({ enabled: true });
97
-
98
- expect(focusSpy).toHaveBeenCalled();
99
-
100
- document.body.removeChild(container);
101
- });
102
-
103
- it('handles Escape key when escapeDeactivates is true', () => {
104
- const container = document.createElement('div');
105
- const button = document.createElement('button');
106
- container.appendChild(button);
107
- document.body.appendChild(container);
108
-
109
- const onEscape = vi.fn();
110
-
111
- const { result, rerender } = renderHook(
112
- ({ enabled }) =>
113
- useFocusTrap<HTMLDivElement>({
114
- enabled,
115
- escapeDeactivates: true,
116
- onEscape,
117
- }),
118
- { initialProps: { enabled: false } }
119
- );
120
-
121
- (result.current as any).current = container;
122
- rerender({ enabled: true });
123
-
124
- act(() => {
125
- const event = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true });
126
- container.dispatchEvent(event);
127
- });
128
-
129
- expect(onEscape).toHaveBeenCalled();
130
-
131
- document.body.removeChild(container);
132
- });
133
-
134
- it('traps Tab focus at the end of focusable elements', () => {
135
- const container = document.createElement('div');
136
- const button1 = document.createElement('button');
137
- button1.textContent = 'First';
138
- const button2 = document.createElement('button');
139
- button2.textContent = 'Last';
140
- container.appendChild(button1);
141
- container.appendChild(button2);
142
- document.body.appendChild(container);
143
-
144
- const { result, rerender } = renderHook(
145
- ({ enabled }) =>
146
- useFocusTrap<HTMLDivElement>({
147
- enabled,
148
- autoFocus: false,
149
- }),
150
- { initialProps: { enabled: false } }
151
- );
152
-
153
- (result.current as any).current = container;
154
- rerender({ enabled: true });
155
-
156
- // Focus the last element
157
- button2.focus();
158
-
159
- act(() => {
160
- const event = new KeyboardEvent('keydown', {
161
- key: 'Tab',
162
- bubbles: true,
163
- });
164
- container.dispatchEvent(event);
165
- });
166
-
167
- document.body.removeChild(container);
168
- });
169
-
170
- it('traps Shift+Tab focus at the start of focusable elements', () => {
171
- const container = document.createElement('div');
172
- const button1 = document.createElement('button');
173
- button1.textContent = 'First';
174
- const button2 = document.createElement('button');
175
- button2.textContent = 'Last';
176
- container.appendChild(button1);
177
- container.appendChild(button2);
178
- document.body.appendChild(container);
179
-
180
- const { result, rerender } = renderHook(
181
- ({ enabled }) =>
182
- useFocusTrap<HTMLDivElement>({
183
- enabled,
184
- autoFocus: false,
185
- }),
186
- { initialProps: { enabled: false } }
187
- );
188
-
189
- (result.current as any).current = container;
190
- rerender({ enabled: true });
191
-
192
- // Focus the first element
193
- button1.focus();
194
-
195
- act(() => {
196
- const event = new KeyboardEvent('keydown', {
197
- key: 'Tab',
198
- shiftKey: true,
199
- bubbles: true,
200
- });
201
- container.dispatchEvent(event);
202
- });
203
-
204
- document.body.removeChild(container);
205
- });
206
-
207
- it('restores focus on unmount when restoreFocus is true', () => {
208
- const outsideButton = document.createElement('button');
209
- outsideButton.textContent = 'Outside';
210
- document.body.appendChild(outsideButton);
211
- outsideButton.focus();
212
-
213
- const container = document.createElement('div');
214
- const innerButton = document.createElement('button');
215
- innerButton.textContent = 'Inside';
216
- container.appendChild(innerButton);
217
- document.body.appendChild(container);
218
-
219
- const { result, rerender, unmount } = renderHook(
220
- ({ enabled }) =>
221
- useFocusTrap<HTMLDivElement>({
222
- enabled,
223
- autoFocus: true,
224
- restoreFocus: true,
225
- }),
226
- { initialProps: { enabled: false } }
227
- );
228
-
229
- (result.current as any).current = container;
230
- rerender({ enabled: true });
231
-
232
- unmount();
233
-
234
- document.body.removeChild(container);
235
- document.body.removeChild(outsideButton);
236
- });
237
-
238
- it('ignores non-Tab and non-Escape keys', () => {
239
- const container = document.createElement('div');
240
- const button = document.createElement('button');
241
- container.appendChild(button);
242
- document.body.appendChild(container);
243
-
244
- const { result, rerender } = renderHook(
245
- ({ enabled }) =>
246
- useFocusTrap<HTMLDivElement>({
247
- enabled,
248
- autoFocus: false,
249
- }),
250
- { initialProps: { enabled: false } }
251
- );
252
-
253
- (result.current as any).current = container;
254
- rerender({ enabled: true });
255
-
256
- act(() => {
257
- const event = new KeyboardEvent('keydown', {
258
- key: 'a',
259
- bubbles: true,
260
- });
261
- container.dispatchEvent(event);
262
- });
263
-
264
- document.body.removeChild(container);
265
- });
266
-
267
- it('handles container with no focusable elements', () => {
268
- const container = document.createElement('div');
269
- container.innerHTML = '<span>No focusable elements</span>';
270
- document.body.appendChild(container);
271
-
272
- const { result, rerender } = renderHook(
273
- ({ enabled }) =>
274
- useFocusTrap<HTMLDivElement>({
275
- enabled,
276
- autoFocus: true,
277
- }),
278
- { initialProps: { enabled: false } }
279
- );
280
-
281
- (result.current as any).current = container;
282
- rerender({ enabled: true });
283
-
284
- act(() => {
285
- const event = new KeyboardEvent('keydown', {
286
- key: 'Tab',
287
- bubbles: true,
288
- });
289
- container.dispatchEvent(event);
290
- });
291
-
292
- document.body.removeChild(container);
293
- });
294
- });
@@ -1,144 +0,0 @@
1
- /**
2
- * Tests for useKeyboardShortcuts hook
3
- */
4
- import { describe, it, expect, vi } from 'vitest';
5
- import { renderHook } from '@testing-library/react';
6
- import { useKeyboardShortcuts, getShortcutDescriptions } from '../useKeyboardShortcuts';
7
- import type { KeyboardShortcutDefinition } from '../useKeyboardShortcuts';
8
-
9
- describe('useKeyboardShortcuts', () => {
10
- it('registers shortcuts without error', () => {
11
- const handler = vi.fn();
12
- const shortcuts: KeyboardShortcutDefinition[] = [
13
- { key: 'k', ctrlOrMeta: true, handler, description: 'Search' },
14
- ];
15
-
16
- expect(() => {
17
- renderHook(() => useKeyboardShortcuts(shortcuts));
18
- }).not.toThrow();
19
- });
20
-
21
- it('handles empty shortcuts array', () => {
22
- expect(() => {
23
- renderHook(() => useKeyboardShortcuts([]));
24
- }).not.toThrow();
25
- });
26
-
27
- it('respects enabled option', () => {
28
- const handler = vi.fn();
29
- const shortcuts: KeyboardShortcutDefinition[] = [
30
- { key: 'k', handler },
31
- ];
32
-
33
- expect(() => {
34
- renderHook(() => useKeyboardShortcuts(shortcuts, { enabled: false }));
35
- }).not.toThrow();
36
- });
37
-
38
- it('fires handler on matching keyboard event', () => {
39
- const handler = vi.fn();
40
- const shortcuts: KeyboardShortcutDefinition[] = [
41
- { key: 'Escape', handler },
42
- ];
43
-
44
- renderHook(() => useKeyboardShortcuts(shortcuts));
45
-
46
- // Simulate keydown
47
- const event = new KeyboardEvent('keydown', {
48
- key: 'Escape',
49
- bubbles: true,
50
- });
51
- document.dispatchEvent(event);
52
-
53
- expect(handler).toHaveBeenCalledTimes(1);
54
- });
55
-
56
- it('does not fire handler for non-matching key', () => {
57
- const handler = vi.fn();
58
- const shortcuts: KeyboardShortcutDefinition[] = [
59
- { key: 'k', ctrlOrMeta: true, handler },
60
- ];
61
-
62
- renderHook(() => useKeyboardShortcuts(shortcuts));
63
-
64
- const event = new KeyboardEvent('keydown', {
65
- key: 'k',
66
- bubbles: true,
67
- // No ctrl or meta
68
- });
69
- document.dispatchEvent(event);
70
-
71
- expect(handler).not.toHaveBeenCalled();
72
- });
73
-
74
- it('fires handler when modifier keys match', () => {
75
- const handler = vi.fn();
76
- const shortcuts: KeyboardShortcutDefinition[] = [
77
- { key: 'k', ctrlOrMeta: true, handler },
78
- ];
79
-
80
- renderHook(() => useKeyboardShortcuts(shortcuts));
81
-
82
- const event = new KeyboardEvent('keydown', {
83
- key: 'k',
84
- ctrlKey: true,
85
- bubbles: true,
86
- });
87
- document.dispatchEvent(event);
88
-
89
- expect(handler).toHaveBeenCalledTimes(1);
90
- });
91
-
92
- it('skips disabled shortcuts', () => {
93
- const handler = vi.fn();
94
- const shortcuts: KeyboardShortcutDefinition[] = [
95
- { key: 'k', handler, enabled: false },
96
- ];
97
-
98
- renderHook(() => useKeyboardShortcuts(shortcuts));
99
-
100
- const event = new KeyboardEvent('keydown', {
101
- key: 'k',
102
- bubbles: true,
103
- });
104
- document.dispatchEvent(event);
105
-
106
- expect(handler).not.toHaveBeenCalled();
107
- });
108
- });
109
-
110
- describe('getShortcutDescriptions', () => {
111
- it('returns formatted descriptions', () => {
112
- const shortcuts: KeyboardShortcutDefinition[] = [
113
- { key: 'k', ctrlOrMeta: true, handler: vi.fn(), description: 'Search' },
114
- { key: 'n', ctrlOrMeta: true, shift: true, handler: vi.fn(), description: 'New' },
115
- { key: 'Escape', handler: vi.fn(), description: 'Close' },
116
- ];
117
-
118
- const descriptions = getShortcutDescriptions(shortcuts);
119
-
120
- expect(descriptions).toHaveLength(3);
121
- expect(descriptions[0]).toEqual({ keys: '⌘/Ctrl + K', description: 'Search' });
122
- expect(descriptions[1]).toEqual({ keys: '⌘/Ctrl + Shift + N', description: 'New' });
123
- expect(descriptions[2]).toEqual({ keys: 'Escape', description: 'Close' });
124
- });
125
-
126
- it('excludes shortcuts without descriptions', () => {
127
- const shortcuts: KeyboardShortcutDefinition[] = [
128
- { key: 'k', handler: vi.fn() },
129
- { key: 'n', handler: vi.fn(), description: 'New' },
130
- ];
131
-
132
- const descriptions = getShortcutDescriptions(shortcuts);
133
- expect(descriptions).toHaveLength(1);
134
- });
135
-
136
- it('excludes disabled shortcuts', () => {
137
- const shortcuts: KeyboardShortcutDefinition[] = [
138
- { key: 'k', handler: vi.fn(), description: 'Search', enabled: false },
139
- ];
140
-
141
- const descriptions = getShortcutDescriptions(shortcuts);
142
- expect(descriptions).toHaveLength(0);
143
- });
144
- });
@@ -1,158 +0,0 @@
1
- /**
2
- * Tests for usePageTransition hook
3
- */
4
- import { describe, it, expect, vi } from 'vitest';
5
- import { renderHook } from '@testing-library/react';
6
- import { usePageTransition } from '../usePageTransition';
7
-
8
- describe('usePageTransition', () => {
9
-
10
- it('returns inactive result when type is none (default)', () => {
11
- const { result } = renderHook(() => usePageTransition());
12
- expect(result.current.isActive).toBe(false);
13
- expect(result.current.enterClassName).toBe('');
14
- expect(result.current.exitClassName).toBe('');
15
- expect(result.current.type).toBe('none');
16
- });
17
-
18
- it('returns active result for fade transition', () => {
19
- const { result } = renderHook(() => usePageTransition({ type: 'fade' }));
20
- expect(result.current.isActive).toBe(true);
21
- expect(result.current.enterClassName).toContain('fade-in');
22
- expect(result.current.exitClassName).toContain('fade-out');
23
- expect(result.current.type).toBe('fade');
24
- });
25
-
26
- it('returns correct classes for slide_up transition', () => {
27
- const { result } = renderHook(() => usePageTransition({ type: 'slide_up' }));
28
- expect(result.current.isActive).toBe(true);
29
- expect(result.current.enterClassName).toContain('slide-in-from-bottom');
30
- expect(result.current.exitClassName).toContain('slide-out-to-top');
31
- });
32
-
33
- it('returns correct classes for slide_down transition', () => {
34
- const { result } = renderHook(() => usePageTransition({ type: 'slide_down' }));
35
- expect(result.current.enterClassName).toContain('slide-in-from-top');
36
- expect(result.current.exitClassName).toContain('slide-out-to-bottom');
37
- });
38
-
39
- it('returns correct classes for slide_left transition', () => {
40
- const { result } = renderHook(() => usePageTransition({ type: 'slide_left' }));
41
- expect(result.current.enterClassName).toContain('slide-in-from-right');
42
- expect(result.current.exitClassName).toContain('slide-out-to-left');
43
- });
44
-
45
- it('returns correct classes for slide_right transition', () => {
46
- const { result } = renderHook(() => usePageTransition({ type: 'slide_right' }));
47
- expect(result.current.enterClassName).toContain('slide-in-from-left');
48
- expect(result.current.exitClassName).toContain('slide-out-to-right');
49
- });
50
-
51
- it('returns correct classes for scale transition', () => {
52
- const { result } = renderHook(() => usePageTransition({ type: 'scale' }));
53
- expect(result.current.enterClassName).toContain('zoom-in');
54
- expect(result.current.exitClassName).toContain('zoom-out');
55
- });
56
-
57
- it('returns correct classes for rotate transition', () => {
58
- const { result } = renderHook(() => usePageTransition({ type: 'rotate' }));
59
- expect(result.current.enterClassName).toContain('spin-in');
60
- expect(result.current.exitClassName).toContain('spin-out');
61
- });
62
-
63
- it('returns correct classes for flip transition', () => {
64
- const { result } = renderHook(() => usePageTransition({ type: 'flip' }));
65
- expect(result.current.enterClassName).toContain('zoom-in');
66
- expect(result.current.exitClassName).toContain('zoom-out');
67
- });
68
-
69
- it('uses default duration of 300ms', () => {
70
- const { result } = renderHook(() => usePageTransition({ type: 'fade' }));
71
- expect(result.current.duration).toBe(300);
72
- expect(result.current.enterStyle.animationDuration).toBe('300ms');
73
- });
74
-
75
- it('accepts custom duration', () => {
76
- const { result } = renderHook(() => usePageTransition({ type: 'fade', duration: 500 }));
77
- expect(result.current.duration).toBe(500);
78
- expect(result.current.enterStyle.animationDuration).toBe('500ms');
79
- });
80
-
81
- it('uses ease_in_out easing by default', () => {
82
- const { result } = renderHook(() => usePageTransition({ type: 'fade' }));
83
- expect(result.current.enterStyle.animationTimingFunction).toBe('ease-in-out');
84
- });
85
-
86
- it('accepts custom easing', () => {
87
- const { result } = renderHook(() => usePageTransition({ type: 'fade', easing: 'spring' }));
88
- expect(result.current.enterStyle.animationTimingFunction).toBe('cubic-bezier(0.34, 1.56, 0.64, 1)');
89
- });
90
-
91
- it('sets animationFillMode to both', () => {
92
- const { result } = renderHook(() => usePageTransition({ type: 'fade' }));
93
- expect(result.current.enterStyle.animationFillMode).toBe('both');
94
- expect(result.current.exitStyle.animationFillMode).toBe('both');
95
- });
96
-
97
- it('applies crossFade positioning', () => {
98
- const { result } = renderHook(() => usePageTransition({ type: 'fade', crossFade: true }));
99
- expect(result.current.enterStyle.position).toBe('absolute');
100
- expect(result.current.enterStyle.inset).toBe('0');
101
- expect(result.current.exitStyle.position).toBe('absolute');
102
- expect(result.current.exitStyle.inset).toBe('0');
103
- });
104
-
105
- it('does not apply crossFade positioning when disabled', () => {
106
- const { result } = renderHook(() => usePageTransition({ type: 'fade', crossFade: false }));
107
- expect(result.current.enterStyle.position).toBeUndefined();
108
- expect(result.current.exitStyle.position).toBeUndefined();
109
- });
110
-
111
- it('returns inactive when reduced motion is preferred', () => {
112
- // Mock window.matchMedia to simulate reduced motion preference
113
- const original = window.matchMedia;
114
- window.matchMedia = vi.fn((query: string) => ({
115
- matches: query === '(prefers-reduced-motion: reduce)',
116
- media: query,
117
- onchange: null,
118
- addEventListener: vi.fn(),
119
- removeEventListener: vi.fn(),
120
- addListener: vi.fn(),
121
- removeListener: vi.fn(),
122
- dispatchEvent: vi.fn(),
123
- })) as unknown as typeof window.matchMedia;
124
-
125
- const { result } = renderHook(() => usePageTransition({ type: 'fade' }));
126
- expect(result.current.isActive).toBe(false);
127
- expect(result.current.enterClassName).toBe('');
128
- expect(result.current.exitClassName).toBe('');
129
-
130
- window.matchMedia = original;
131
- });
132
-
133
- it('returns empty styles when inactive', () => {
134
- const { result } = renderHook(() => usePageTransition({ type: 'none' }));
135
- expect(result.current.enterStyle).toEqual({});
136
- expect(result.current.exitStyle).toEqual({});
137
- });
138
-
139
- it('accepts linear easing', () => {
140
- const { result } = renderHook(() => usePageTransition({ type: 'fade', easing: 'linear' }));
141
- expect(result.current.enterStyle.animationTimingFunction).toBe('linear');
142
- });
143
-
144
- it('accepts ease easing', () => {
145
- const { result } = renderHook(() => usePageTransition({ type: 'fade', easing: 'ease' }));
146
- expect(result.current.enterStyle.animationTimingFunction).toBe('ease');
147
- });
148
-
149
- it('accepts ease_in easing', () => {
150
- const { result } = renderHook(() => usePageTransition({ type: 'fade', easing: 'ease_in' }));
151
- expect(result.current.enterStyle.animationTimingFunction).toBe('ease-in');
152
- });
153
-
154
- it('accepts ease_out easing', () => {
155
- const { result } = renderHook(() => usePageTransition({ type: 'fade', easing: 'ease_out' }));
156
- expect(result.current.enterStyle.animationTimingFunction).toBe('ease-out');
157
- });
158
- });