@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,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useActionEngine hook
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
6
|
-
import { renderHook, act } from '@testing-library/react';
|
|
7
|
-
import { useActionEngine } from '../useActionEngine';
|
|
8
|
-
|
|
9
|
-
describe('useActionEngine', () => {
|
|
10
|
-
const sampleActions = [
|
|
11
|
-
{
|
|
12
|
-
name: 'mark_complete',
|
|
13
|
-
type: 'script',
|
|
14
|
-
execute: 'true',
|
|
15
|
-
locations: ['list_toolbar', 'record_header'],
|
|
16
|
-
bulkEnabled: true,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: 'delete_record',
|
|
20
|
-
type: 'api',
|
|
21
|
-
endpoint: '/api/delete',
|
|
22
|
-
locations: ['record_more'],
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: 'view_details',
|
|
26
|
-
type: 'url',
|
|
27
|
-
target: '/details',
|
|
28
|
-
locations: ['list_item'],
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: 'global_search',
|
|
32
|
-
type: 'script',
|
|
33
|
-
execute: 'true',
|
|
34
|
-
locations: ['global_nav'],
|
|
35
|
-
shortcut: 'ctrl+k',
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
describe('getActionsForLocation', () => {
|
|
40
|
-
it('returns actions for list_toolbar', () => {
|
|
41
|
-
const { result } = renderHook(() =>
|
|
42
|
-
useActionEngine({ actions: sampleActions }),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const actions = result.current.getActionsForLocation('list_toolbar');
|
|
46
|
-
expect(actions.length).toBe(1);
|
|
47
|
-
expect(actions[0].name).toBe('mark_complete');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('returns actions for record_header', () => {
|
|
51
|
-
const { result } = renderHook(() =>
|
|
52
|
-
useActionEngine({ actions: sampleActions }),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const actions = result.current.getActionsForLocation('record_header');
|
|
56
|
-
expect(actions.length).toBe(1);
|
|
57
|
-
expect(actions[0].name).toBe('mark_complete');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('returns actions for record_more', () => {
|
|
61
|
-
const { result } = renderHook(() =>
|
|
62
|
-
useActionEngine({ actions: sampleActions }),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const actions = result.current.getActionsForLocation('record_more');
|
|
66
|
-
expect(actions.length).toBe(1);
|
|
67
|
-
expect(actions[0].name).toBe('delete_record');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('returns empty array for location with no actions', () => {
|
|
71
|
-
const { result } = renderHook(() =>
|
|
72
|
-
useActionEngine({ actions: sampleActions }),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const actions = result.current.getActionsForLocation('record_related');
|
|
76
|
-
expect(actions.length).toBe(0);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('getBulkActions', () => {
|
|
81
|
-
it('returns only bulk-enabled actions', () => {
|
|
82
|
-
const { result } = renderHook(() =>
|
|
83
|
-
useActionEngine({ actions: sampleActions }),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const bulkActions = result.current.getBulkActions();
|
|
87
|
-
expect(bulkActions.length).toBe(1);
|
|
88
|
-
expect(bulkActions[0].name).toBe('mark_complete');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('executeAction', () => {
|
|
93
|
-
it('executes a registered action by name', async () => {
|
|
94
|
-
const { result } = renderHook(() =>
|
|
95
|
-
useActionEngine({ actions: sampleActions }),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
let actionResult: any;
|
|
99
|
-
await act(async () => {
|
|
100
|
-
actionResult = await result.current.executeAction('mark_complete');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
expect(actionResult.success).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('returns error for unregistered action', async () => {
|
|
107
|
-
const { result } = renderHook(() =>
|
|
108
|
-
useActionEngine({ actions: sampleActions }),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
let actionResult: any;
|
|
112
|
-
await act(async () => {
|
|
113
|
-
actionResult = await result.current.executeAction('nonexistent');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
expect(actionResult.success).toBe(false);
|
|
117
|
-
expect(actionResult.error).toContain('not found');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('handleShortcut', () => {
|
|
122
|
-
it('handles registered keyboard shortcut', async () => {
|
|
123
|
-
const { result } = renderHook(() =>
|
|
124
|
-
useActionEngine({ actions: sampleActions }),
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
let shortcutResult: any;
|
|
128
|
-
await act(async () => {
|
|
129
|
-
shortcutResult = await result.current.handleShortcut('ctrl+k');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
expect(shortcutResult).not.toBeNull();
|
|
133
|
-
expect(shortcutResult.success).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('returns null for unregistered shortcut', async () => {
|
|
137
|
-
const { result } = renderHook(() =>
|
|
138
|
-
useActionEngine({ actions: sampleActions }),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
let shortcutResult: any;
|
|
142
|
-
await act(async () => {
|
|
143
|
-
shortcutResult = await result.current.handleShortcut('ctrl+z');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
expect(shortcutResult).toBeNull();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('defaults', () => {
|
|
151
|
-
it('works with no options', () => {
|
|
152
|
-
const { result } = renderHook(() => useActionEngine());
|
|
153
|
-
|
|
154
|
-
expect(result.current.engine).toBeDefined();
|
|
155
|
-
expect(typeof result.current.getActionsForLocation).toBe('function');
|
|
156
|
-
expect(typeof result.current.getBulkActions).toBe('function');
|
|
157
|
-
expect(typeof result.current.executeAction).toBe('function');
|
|
158
|
-
expect(typeof result.current.handleShortcut).toBe('function');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('works with empty actions array', () => {
|
|
162
|
-
const { result } = renderHook(() =>
|
|
163
|
-
useActionEngine({ actions: [] }),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
const actions = result.current.getActionsForLocation('list_toolbar');
|
|
167
|
-
expect(actions).toEqual([]);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useActionRunner hook
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
6
|
-
import { renderHook, waitFor, act } from '@testing-library/react';
|
|
7
|
-
import { useActionRunner } from '../useActionRunner';
|
|
8
|
-
|
|
9
|
-
describe('useActionRunner', () => {
|
|
10
|
-
it('returns initial state with loading=false, error=null, result=null', () => {
|
|
11
|
-
const { result } = renderHook(() => useActionRunner());
|
|
12
|
-
|
|
13
|
-
expect(result.current.loading).toBe(false);
|
|
14
|
-
expect(result.current.error).toBeNull();
|
|
15
|
-
expect(result.current.result).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('exposes runner, execute, and updateContext', () => {
|
|
19
|
-
const { result } = renderHook(() => useActionRunner());
|
|
20
|
-
|
|
21
|
-
expect(result.current.runner).toBeDefined();
|
|
22
|
-
expect(typeof result.current.execute).toBe('function');
|
|
23
|
-
expect(typeof result.current.updateContext).toBe('function');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('handles options with context key format', () => {
|
|
27
|
-
const { result } = renderHook(() =>
|
|
28
|
-
useActionRunner({ context: { data: { name: 'test' } } }),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(result.current.runner).toBeDefined();
|
|
32
|
-
expect(result.current.loading).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('handles plain context object format (backwards compat)', () => {
|
|
36
|
-
const { result } = renderHook(() =>
|
|
37
|
-
useActionRunner({ data: { name: 'test' } }),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
expect(result.current.runner).toBeDefined();
|
|
41
|
-
expect(result.current.loading).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('sets loading=true during execution and loading=false after', async () => {
|
|
45
|
-
let resolveAction: () => void;
|
|
46
|
-
const pendingAction = new Promise<void>((resolve) => {
|
|
47
|
-
resolveAction = resolve;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const { result } = renderHook(() => useActionRunner());
|
|
51
|
-
|
|
52
|
-
let executePromise: Promise<unknown>;
|
|
53
|
-
act(() => {
|
|
54
|
-
executePromise = result.current.execute({
|
|
55
|
-
onClick: () => pendingAction,
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
await waitFor(() => {
|
|
60
|
-
expect(result.current.loading).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
await act(async () => {
|
|
64
|
-
resolveAction!();
|
|
65
|
-
await executePromise;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(result.current.loading).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('sets result on successful action execution', async () => {
|
|
72
|
-
const onNavigate = vi.fn();
|
|
73
|
-
const { result } = renderHook(() =>
|
|
74
|
-
useActionRunner({ context: {}, onNavigate }),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
await act(async () => {
|
|
78
|
-
await result.current.execute({
|
|
79
|
-
type: 'navigation',
|
|
80
|
-
navigate: { to: '/dashboard' },
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(result.current.result).toEqual({ success: true });
|
|
85
|
-
expect(result.current.error).toBeNull();
|
|
86
|
-
expect(result.current.loading).toBe(false);
|
|
87
|
-
expect(onNavigate).toHaveBeenCalledWith(
|
|
88
|
-
'/dashboard',
|
|
89
|
-
expect.objectContaining({ external: false }),
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('sets error on failed action execution (catch path)', async () => {
|
|
94
|
-
const { result } = renderHook(() => useActionRunner());
|
|
95
|
-
|
|
96
|
-
await act(async () => {
|
|
97
|
-
await result.current.execute({
|
|
98
|
-
onClick: () => {
|
|
99
|
-
throw new Error('Something went wrong');
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(result.current.error).toBe('Something went wrong');
|
|
105
|
-
expect(result.current.result).toEqual({
|
|
106
|
-
success: false,
|
|
107
|
-
error: 'Something went wrong',
|
|
108
|
-
});
|
|
109
|
-
expect(result.current.loading).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('updateContext calls runner.updateContext', () => {
|
|
113
|
-
const { result } = renderHook(() => useActionRunner());
|
|
114
|
-
|
|
115
|
-
const spy = vi.spyOn(result.current.runner, 'updateContext');
|
|
116
|
-
|
|
117
|
-
act(() => {
|
|
118
|
-
result.current.updateContext({ data: { id: 42 } });
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
expect(spy).toHaveBeenCalledWith({ data: { id: 42 } });
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('accepts handler options (onToast, onNavigate, etc.)', async () => {
|
|
125
|
-
const onToast = vi.fn();
|
|
126
|
-
const onNavigate = vi.fn();
|
|
127
|
-
|
|
128
|
-
const { result } = renderHook(() =>
|
|
129
|
-
useActionRunner({
|
|
130
|
-
context: {},
|
|
131
|
-
onToast,
|
|
132
|
-
onNavigate,
|
|
133
|
-
}),
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
await act(async () => {
|
|
137
|
-
await result.current.execute({
|
|
138
|
-
type: 'navigation',
|
|
139
|
-
navigate: { to: '/settings' },
|
|
140
|
-
successMessage: 'Navigated!',
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(onNavigate).toHaveBeenCalledWith(
|
|
145
|
-
'/settings',
|
|
146
|
-
expect.objectContaining({ external: false }),
|
|
147
|
-
);
|
|
148
|
-
expect(onToast).toHaveBeenCalledWith(
|
|
149
|
-
'Navigated!',
|
|
150
|
-
expect.objectContaining({ type: 'success' }),
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useAnimation and useReducedMotion hooks
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import { renderHook } from '@testing-library/react';
|
|
6
|
-
import { useAnimation } from '../useAnimation';
|
|
7
|
-
import { useReducedMotion } from '../useReducedMotion';
|
|
8
|
-
|
|
9
|
-
describe('useAnimation', () => {
|
|
10
|
-
it('returns empty className and style for no config', () => {
|
|
11
|
-
const { result } = renderHook(() => useAnimation());
|
|
12
|
-
expect(result.current.className).toBe('');
|
|
13
|
-
expect(result.current.style).toEqual({});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns empty when preset is none', () => {
|
|
17
|
-
const { result } = renderHook(() => useAnimation({ preset: 'none' }));
|
|
18
|
-
expect(result.current.className).toBe('');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('returns empty when disabled', () => {
|
|
22
|
-
const { result } = renderHook(() =>
|
|
23
|
-
useAnimation({ preset: 'fade', enabled: false })
|
|
24
|
-
);
|
|
25
|
-
expect(result.current.className).toBe('');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns correct className for fade preset', () => {
|
|
29
|
-
const { result } = renderHook(() => useAnimation({ preset: 'fade' }));
|
|
30
|
-
expect(result.current.className).toContain('fade-in');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns correct className for slide-up preset', () => {
|
|
34
|
-
const { result } = renderHook(() => useAnimation({ preset: 'slide-up' }));
|
|
35
|
-
expect(result.current.className).toContain('slide-in-from-bottom');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns correct className for scale preset', () => {
|
|
39
|
-
const { result } = renderHook(() => useAnimation({ preset: 'scale' }));
|
|
40
|
-
expect(result.current.className).toContain('zoom-in');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns correct className for scale-fade preset', () => {
|
|
44
|
-
const { result } = renderHook(() => useAnimation({ preset: 'scale-fade' }));
|
|
45
|
-
expect(result.current.className).toContain('fade-in');
|
|
46
|
-
expect(result.current.className).toContain('zoom-in');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('applies custom duration', () => {
|
|
50
|
-
const { result } = renderHook(() =>
|
|
51
|
-
useAnimation({ preset: 'fade', duration: 300 })
|
|
52
|
-
);
|
|
53
|
-
expect(result.current.style.animationDuration).toBe('300ms');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('applies custom delay', () => {
|
|
57
|
-
const { result } = renderHook(() =>
|
|
58
|
-
useAnimation({ preset: 'fade', delay: 100 })
|
|
59
|
-
);
|
|
60
|
-
expect(result.current.style.animationDelay).toBe('100ms');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('applies easing function', () => {
|
|
64
|
-
const { result } = renderHook(() =>
|
|
65
|
-
useAnimation({ preset: 'fade', easing: 'spring' })
|
|
66
|
-
);
|
|
67
|
-
expect(result.current.style.animationTimingFunction).toContain('cubic-bezier');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('useReducedMotion', () => {
|
|
72
|
-
it('returns a boolean value', () => {
|
|
73
|
-
const { result } = renderHook(() => useReducedMotion());
|
|
74
|
-
expect(typeof result.current).toBe('boolean');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('defaults to false when matchMedia returns false', () => {
|
|
78
|
-
const { result } = renderHook(() => useReducedMotion());
|
|
79
|
-
// jsdom matchMedia always returns false by default
|
|
80
|
-
expect(result.current).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useColumnSummary hook
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import { renderHook } from '@testing-library/react';
|
|
6
|
-
import { useColumnSummary } from '../useColumnSummary';
|
|
7
|
-
|
|
8
|
-
const sampleData = [
|
|
9
|
-
{ name: 'Alice', amount: 100, category: 'A' },
|
|
10
|
-
{ name: 'Bob', amount: 200, category: 'B' },
|
|
11
|
-
{ name: 'Charlie', amount: 300, category: 'A' },
|
|
12
|
-
{ name: 'Diana', amount: 400, category: 'C' },
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
describe('useColumnSummary', () => {
|
|
16
|
-
it('computes sum correctly', () => {
|
|
17
|
-
const { result } = renderHook(() =>
|
|
18
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'sum' })
|
|
19
|
-
);
|
|
20
|
-
expect(result.current.value).toBe(1000);
|
|
21
|
-
expect(result.current.label).toBe('SUM');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('computes avg correctly', () => {
|
|
25
|
-
const { result } = renderHook(() =>
|
|
26
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'avg' })
|
|
27
|
-
);
|
|
28
|
-
expect(result.current.value).toBe(250);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('computes count correctly', () => {
|
|
32
|
-
const { result } = renderHook(() =>
|
|
33
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'count' })
|
|
34
|
-
);
|
|
35
|
-
expect(result.current.value).toBe(4);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('computes min correctly', () => {
|
|
39
|
-
const { result } = renderHook(() =>
|
|
40
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'min' })
|
|
41
|
-
);
|
|
42
|
-
expect(result.current.value).toBe(100);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('computes max correctly', () => {
|
|
46
|
-
const { result } = renderHook(() =>
|
|
47
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'max' })
|
|
48
|
-
);
|
|
49
|
-
expect(result.current.value).toBe(400);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('computes distinct correctly', () => {
|
|
53
|
-
const { result } = renderHook(() =>
|
|
54
|
-
useColumnSummary(sampleData, { field: 'category', function: 'distinct' })
|
|
55
|
-
);
|
|
56
|
-
expect(result.current.value).toBe(3); // A, B, C
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('uses custom label', () => {
|
|
60
|
-
const { result } = renderHook(() =>
|
|
61
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'sum', label: 'Total Revenue' })
|
|
62
|
-
);
|
|
63
|
-
expect(result.current.label).toBe('Total Revenue');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('returns formatted string', () => {
|
|
67
|
-
const { result } = renderHook(() =>
|
|
68
|
-
useColumnSummary(sampleData, { field: 'amount', function: 'sum' }, 'en-US')
|
|
69
|
-
);
|
|
70
|
-
expect(result.current.formatted).toBe('1,000');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('handles empty data for sum', () => {
|
|
74
|
-
const { result } = renderHook(() =>
|
|
75
|
-
useColumnSummary([], { field: 'amount', function: 'sum' })
|
|
76
|
-
);
|
|
77
|
-
expect(result.current.value).toBe(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('handles empty data for avg', () => {
|
|
81
|
-
const { result } = renderHook(() =>
|
|
82
|
-
useColumnSummary([], { field: 'amount', function: 'avg' })
|
|
83
|
-
);
|
|
84
|
-
expect(result.current.value).toBe(0);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('handles empty data for min', () => {
|
|
88
|
-
const { result } = renderHook(() =>
|
|
89
|
-
useColumnSummary([], { field: 'amount', function: 'min' })
|
|
90
|
-
);
|
|
91
|
-
expect(result.current.value).toBe(0);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useCrudShortcuts hook
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
import { renderHook } from '@testing-library/react';
|
|
6
|
-
import { useCrudShortcuts } from '../useCrudShortcuts';
|
|
7
|
-
|
|
8
|
-
describe('useCrudShortcuts', () => {
|
|
9
|
-
it('renders without error with empty callbacks', () => {
|
|
10
|
-
expect(() => {
|
|
11
|
-
renderHook(() => useCrudShortcuts({}));
|
|
12
|
-
}).not.toThrow();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('renders without error when disabled', () => {
|
|
16
|
-
expect(() => {
|
|
17
|
-
renderHook(() => useCrudShortcuts({}, false));
|
|
18
|
-
}).not.toThrow();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('registers onCreate shortcut', () => {
|
|
22
|
-
const onCreate = vi.fn();
|
|
23
|
-
expect(() => {
|
|
24
|
-
renderHook(() => useCrudShortcuts({ onCreate }));
|
|
25
|
-
}).not.toThrow();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('registers onEdit shortcut', () => {
|
|
29
|
-
const onEdit = vi.fn();
|
|
30
|
-
expect(() => {
|
|
31
|
-
renderHook(() => useCrudShortcuts({ onEdit }));
|
|
32
|
-
}).not.toThrow();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('registers onDelete shortcut', () => {
|
|
36
|
-
const onDelete = vi.fn();
|
|
37
|
-
expect(() => {
|
|
38
|
-
renderHook(() => useCrudShortcuts({ onDelete }));
|
|
39
|
-
}).not.toThrow();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('registers onSave shortcut', () => {
|
|
43
|
-
const onSave = vi.fn();
|
|
44
|
-
expect(() => {
|
|
45
|
-
renderHook(() => useCrudShortcuts({ onSave }));
|
|
46
|
-
}).not.toThrow();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('registers onDuplicate shortcut', () => {
|
|
50
|
-
const onDuplicate = vi.fn();
|
|
51
|
-
expect(() => {
|
|
52
|
-
renderHook(() => useCrudShortcuts({ onDuplicate }));
|
|
53
|
-
}).not.toThrow();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('registers onCancel shortcut', () => {
|
|
57
|
-
const onCancel = vi.fn();
|
|
58
|
-
expect(() => {
|
|
59
|
-
renderHook(() => useCrudShortcuts({ onCancel }));
|
|
60
|
-
}).not.toThrow();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('registers onSearch shortcut', () => {
|
|
64
|
-
const onSearch = vi.fn();
|
|
65
|
-
expect(() => {
|
|
66
|
-
renderHook(() => useCrudShortcuts({ onSearch }));
|
|
67
|
-
}).not.toThrow();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('registers all shortcuts together', () => {
|
|
71
|
-
expect(() => {
|
|
72
|
-
renderHook(() =>
|
|
73
|
-
useCrudShortcuts({
|
|
74
|
-
onCreate: vi.fn(),
|
|
75
|
-
onEdit: vi.fn(),
|
|
76
|
-
onDelete: vi.fn(),
|
|
77
|
-
onSave: vi.fn(),
|
|
78
|
-
onDuplicate: vi.fn(),
|
|
79
|
-
onCancel: vi.fn(),
|
|
80
|
-
onSearch: vi.fn(),
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
}).not.toThrow();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
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
|
-
|
|
9
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
10
|
-
import { renderHook, act } from '@testing-library/react';
|
|
11
|
-
import { useDebugMode } from '../useDebugMode';
|
|
12
|
-
|
|
13
|
-
describe('useDebugMode', () => {
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
vi.restoreAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('defaults to disabled when no URL params are present', () => {
|
|
19
|
-
const { result } = renderHook(() => useDebugMode());
|
|
20
|
-
expect(result.current.enabled).toBe(false);
|
|
21
|
-
expect(result.current.flags.enabled).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('provides toggle function', () => {
|
|
25
|
-
const { result } = renderHook(() => useDebugMode());
|
|
26
|
-
expect(typeof result.current.toggle).toBe('function');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('toggles enabled state on toggle()', () => {
|
|
30
|
-
const { result } = renderHook(() => useDebugMode());
|
|
31
|
-
expect(result.current.enabled).toBe(false);
|
|
32
|
-
|
|
33
|
-
act(() => {
|
|
34
|
-
result.current.toggle();
|
|
35
|
-
});
|
|
36
|
-
expect(result.current.enabled).toBe(true);
|
|
37
|
-
|
|
38
|
-
act(() => {
|
|
39
|
-
result.current.toggle();
|
|
40
|
-
});
|
|
41
|
-
expect(result.current.enabled).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('setEnabled explicitly sets the state', () => {
|
|
45
|
-
const { result } = renderHook(() => useDebugMode());
|
|
46
|
-
|
|
47
|
-
act(() => {
|
|
48
|
-
result.current.setEnabled(true);
|
|
49
|
-
});
|
|
50
|
-
expect(result.current.enabled).toBe(true);
|
|
51
|
-
|
|
52
|
-
act(() => {
|
|
53
|
-
result.current.setEnabled(false);
|
|
54
|
-
});
|
|
55
|
-
expect(result.current.enabled).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('responds to Ctrl+Shift+D keyboard shortcut', () => {
|
|
59
|
-
const { result } = renderHook(() => useDebugMode());
|
|
60
|
-
expect(result.current.enabled).toBe(false);
|
|
61
|
-
|
|
62
|
-
act(() => {
|
|
63
|
-
const event = new KeyboardEvent('keydown', {
|
|
64
|
-
key: 'D',
|
|
65
|
-
ctrlKey: true,
|
|
66
|
-
shiftKey: true,
|
|
67
|
-
bubbles: true,
|
|
68
|
-
});
|
|
69
|
-
document.dispatchEvent(event);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(result.current.enabled).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('flags reflect enabled state', () => {
|
|
76
|
-
const { result } = renderHook(() => useDebugMode());
|
|
77
|
-
|
|
78
|
-
act(() => {
|
|
79
|
-
result.current.setEnabled(true);
|
|
80
|
-
});
|
|
81
|
-
expect(result.current.flags.enabled).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
});
|