@object-ui/react 3.3.0 → 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 +9 -0
- package/README.md +21 -1
- 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/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 -516
- 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__/useDataRefresh.test.ts +0 -115
- 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 -247
- 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 -36
- 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/useDataRefresh.ts +0 -58
- package/src/hooks/useDebugMode.ts +0 -95
- package/src/hooks/useDensityMode.ts +0 -102
- package/src/hooks/useDiscovery.ts +0 -168
- 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,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for ActionContext — ActionProvider, useAction, useHasActionProvider
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
6
|
-
import { renderHook, waitFor, act } from '@testing-library/react';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import { ActionProvider, useAction, useHasActionProvider } from '../ActionContext';
|
|
9
|
-
|
|
10
|
-
describe('ActionContext', () => {
|
|
11
|
-
describe('useAction without ActionProvider', () => {
|
|
12
|
-
it('falls back to local ActionRunner with default state', () => {
|
|
13
|
-
const { result } = renderHook(() => useAction());
|
|
14
|
-
|
|
15
|
-
expect(result.current.loading).toBe(false);
|
|
16
|
-
expect(result.current.error).toBeNull();
|
|
17
|
-
expect(result.current.result).toBeNull();
|
|
18
|
-
expect(typeof result.current.execute).toBe('function');
|
|
19
|
-
expect(typeof result.current.executeChain).toBe('function');
|
|
20
|
-
expect(typeof result.current.updateContext).toBe('function');
|
|
21
|
-
expect(result.current.runner).toBeDefined();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('useHasActionProvider', () => {
|
|
26
|
-
it('returns false without provider', () => {
|
|
27
|
-
const { result } = renderHook(() => useHasActionProvider());
|
|
28
|
-
|
|
29
|
-
expect(result.current).toBe(false);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('returns true with provider', () => {
|
|
33
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
34
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
35
|
-
|
|
36
|
-
const { result } = renderHook(() => useHasActionProvider(), { wrapper });
|
|
37
|
-
|
|
38
|
-
expect(result.current).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('ActionProvider basic', () => {
|
|
43
|
-
it('children can access execute function', () => {
|
|
44
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
45
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
46
|
-
|
|
47
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
48
|
-
|
|
49
|
-
expect(typeof result.current.execute).toBe('function');
|
|
50
|
-
expect(typeof result.current.executeChain).toBe('function');
|
|
51
|
-
expect(typeof result.current.updateContext).toBe('function');
|
|
52
|
-
expect(result.current.loading).toBe(false);
|
|
53
|
-
expect(result.current.error).toBeNull();
|
|
54
|
-
expect(result.current.result).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('ActionProvider execute', () => {
|
|
59
|
-
it('executes a toast action and returns result', async () => {
|
|
60
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
61
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
62
|
-
|
|
63
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
64
|
-
|
|
65
|
-
let actionResult: any;
|
|
66
|
-
await act(async () => {
|
|
67
|
-
actionResult = await result.current.execute({
|
|
68
|
-
type: 'script',
|
|
69
|
-
execute: 'true',
|
|
70
|
-
toast: { showOnSuccess: true },
|
|
71
|
-
successMessage: 'Done!',
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expect(actionResult.success).toBe(true);
|
|
76
|
-
|
|
77
|
-
await waitFor(() => {
|
|
78
|
-
expect(result.current.loading).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(result.current.result).toEqual(actionResult);
|
|
82
|
-
expect(result.current.error).toBeNull();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('ActionProvider execute error', () => {
|
|
87
|
-
it('executes an action that fails and sets error state', async () => {
|
|
88
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
89
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
90
|
-
|
|
91
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
92
|
-
|
|
93
|
-
let actionResult: any;
|
|
94
|
-
await act(async () => {
|
|
95
|
-
actionResult = await result.current.execute({
|
|
96
|
-
onClick: vi.fn().mockRejectedValue(new Error('boom')),
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
await waitFor(() => {
|
|
101
|
-
expect(result.current.loading).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(actionResult.success).toBe(false);
|
|
105
|
-
expect(result.current.error).toBeTruthy();
|
|
106
|
-
expect(result.current.result?.success).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('ActionProvider executeChain', () => {
|
|
111
|
-
it('executes a chain of actions', async () => {
|
|
112
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
113
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
114
|
-
|
|
115
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
116
|
-
|
|
117
|
-
let chainResult: any;
|
|
118
|
-
await act(async () => {
|
|
119
|
-
chainResult = await result.current.executeChain([
|
|
120
|
-
{ type: 'script', execute: 'true' },
|
|
121
|
-
{ type: 'script', execute: 'true' },
|
|
122
|
-
]);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
await waitFor(() => {
|
|
126
|
-
expect(result.current.loading).toBe(false);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
expect(chainResult.success).toBe(true);
|
|
130
|
-
expect(result.current.result).toEqual(chainResult);
|
|
131
|
-
expect(result.current.error).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('ActionProvider updateContext', () => {
|
|
136
|
-
it('updateContext is callable', () => {
|
|
137
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
138
|
-
React.createElement(ActionProvider, { context: {} }, children);
|
|
139
|
-
|
|
140
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
141
|
-
|
|
142
|
-
expect(() => {
|
|
143
|
-
result.current.updateContext({ record: { id: 1 } });
|
|
144
|
-
}).not.toThrow();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('ActionProvider with handlers', () => {
|
|
149
|
-
it('invokes onToast handler when a toast action is executed', async () => {
|
|
150
|
-
const onToast = vi.fn();
|
|
151
|
-
const onNavigate = vi.fn();
|
|
152
|
-
|
|
153
|
-
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
154
|
-
React.createElement(
|
|
155
|
-
ActionProvider,
|
|
156
|
-
{ context: {}, onToast, onNavigate },
|
|
157
|
-
children,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const { result } = renderHook(() => useAction(), { wrapper });
|
|
161
|
-
|
|
162
|
-
await act(async () => {
|
|
163
|
-
await result.current.execute({
|
|
164
|
-
type: 'script',
|
|
165
|
-
execute: 'true',
|
|
166
|
-
toast: { showOnSuccess: true },
|
|
167
|
-
successMessage: 'Saved!',
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(onToast).toHaveBeenCalledWith('Saved!', expect.objectContaining({ type: 'success' }));
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for DndProvider and useDnd
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
import { renderHook, act } from '@testing-library/react';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import {
|
|
8
|
-
DndProvider,
|
|
9
|
-
useDnd,
|
|
10
|
-
useHasDndProvider,
|
|
11
|
-
} from '../DndContext';
|
|
12
|
-
|
|
13
|
-
const wrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
14
|
-
<DndProvider>{children}</DndProvider>
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
describe('DndProvider', () => {
|
|
18
|
-
it('provides DnD context', () => {
|
|
19
|
-
const { result } = renderHook(() => useDnd(), { wrapper });
|
|
20
|
-
expect(result.current.enabled).toBe(true);
|
|
21
|
-
expect(result.current.activeItem).toBeNull();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('starts drag operation', () => {
|
|
25
|
-
const onDragStart = vi.fn();
|
|
26
|
-
const customWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
27
|
-
<DndProvider onDragStart={onDragStart}>{children}</DndProvider>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const { result } = renderHook(() => useDnd(), { wrapper: customWrapper });
|
|
31
|
-
|
|
32
|
-
act(() => {
|
|
33
|
-
result.current.startDrag({ id: 'item-1', type: 'card' });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(result.current.activeItem).toEqual({ id: 'item-1', type: 'card' });
|
|
37
|
-
expect(onDragStart).toHaveBeenCalledTimes(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('ends drag operation', () => {
|
|
41
|
-
const onDrop = vi.fn();
|
|
42
|
-
const customWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
43
|
-
<DndProvider onDrop={onDrop}>{children}</DndProvider>
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const { result } = renderHook(() => useDnd(), { wrapper: customWrapper });
|
|
47
|
-
|
|
48
|
-
act(() => {
|
|
49
|
-
result.current.startDrag({ id: 'item-1', type: 'card' });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
act(() => {
|
|
53
|
-
result.current.endDrag('zone-1');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
expect(result.current.activeItem).toBeNull();
|
|
57
|
-
expect(onDrop).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(onDrop).toHaveBeenCalledWith(
|
|
59
|
-
expect.objectContaining({ item: { id: 'item-1', type: 'card' }, targetZoneId: 'zone-1' })
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('cancels drag operation', () => {
|
|
64
|
-
const onDragCancel = vi.fn();
|
|
65
|
-
const customWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
66
|
-
<DndProvider onDragCancel={onDragCancel}>{children}</DndProvider>
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const { result } = renderHook(() => useDnd(), { wrapper: customWrapper });
|
|
70
|
-
|
|
71
|
-
act(() => {
|
|
72
|
-
result.current.startDrag({ id: 'item-1', type: 'card' });
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
act(() => {
|
|
76
|
-
result.current.cancelDrag();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
expect(result.current.activeItem).toBeNull();
|
|
80
|
-
expect(onDragCancel).toHaveBeenCalledTimes(1);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('registers and checks drop zones', () => {
|
|
84
|
-
const { result } = renderHook(() => useDnd(), { wrapper });
|
|
85
|
-
|
|
86
|
-
act(() => {
|
|
87
|
-
result.current.registerDropZone({
|
|
88
|
-
id: 'zone-1',
|
|
89
|
-
acceptTypes: ['card', 'widget'],
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(result.current.canDrop('zone-1', 'card')).toBe(true);
|
|
94
|
-
expect(result.current.canDrop('zone-1', 'unknown')).toBe(false);
|
|
95
|
-
expect(result.current.canDrop('nonexistent', 'card')).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('unregisters drop zones', () => {
|
|
99
|
-
const { result } = renderHook(() => useDnd(), { wrapper });
|
|
100
|
-
|
|
101
|
-
act(() => {
|
|
102
|
-
result.current.registerDropZone({
|
|
103
|
-
id: 'zone-1',
|
|
104
|
-
acceptTypes: ['card'],
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
act(() => {
|
|
109
|
-
result.current.unregisterDropZone('zone-1');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(result.current.canDrop('zone-1', 'card')).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('respects disabled config', () => {
|
|
116
|
-
const onDragStart = vi.fn();
|
|
117
|
-
const customWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
118
|
-
<DndProvider config={{ enabled: false }} onDragStart={onDragStart}>{children}</DndProvider>
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const { result } = renderHook(() => useDnd(), { wrapper: customWrapper });
|
|
122
|
-
|
|
123
|
-
act(() => {
|
|
124
|
-
result.current.startDrag({ id: 'item-1', type: 'card' });
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
expect(result.current.activeItem).toBeNull();
|
|
128
|
-
expect(onDragStart).not.toHaveBeenCalled();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('useHasDndProvider', () => {
|
|
133
|
-
it('returns false outside provider', () => {
|
|
134
|
-
const { result } = renderHook(() => useHasDndProvider());
|
|
135
|
-
expect(result.current).toBe(false);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('returns true inside provider', () => {
|
|
139
|
-
const { result } = renderHook(() => useHasDndProvider(), { wrapper });
|
|
140
|
-
expect(result.current).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe('useDnd without provider', () => {
|
|
145
|
-
it('throws error', () => {
|
|
146
|
-
expect(() => {
|
|
147
|
-
renderHook(() => useDnd());
|
|
148
|
-
}).toThrow('useDnd must be used within a <DndProvider>');
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for NotificationProvider and useNotifications
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
import { renderHook, act } from '@testing-library/react';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import {
|
|
8
|
-
NotificationProvider,
|
|
9
|
-
useNotifications,
|
|
10
|
-
useHasNotificationProvider,
|
|
11
|
-
} from '../NotificationContext';
|
|
12
|
-
|
|
13
|
-
const wrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
14
|
-
<NotificationProvider>{children}</NotificationProvider>
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
describe('NotificationProvider', () => {
|
|
18
|
-
it('provides notifications context', () => {
|
|
19
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
20
|
-
expect(result.current.notifications).toEqual([]);
|
|
21
|
-
expect(result.current.unreadCount).toBe(0);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('adds a notification via notify', () => {
|
|
25
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
26
|
-
|
|
27
|
-
act(() => {
|
|
28
|
-
result.current.notify({ title: 'Hello', severity: 'info' });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
expect(result.current.notifications).toHaveLength(1);
|
|
32
|
-
expect(result.current.notifications[0].title).toBe('Hello');
|
|
33
|
-
expect(result.current.unreadCount).toBe(1);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('adds info notification', () => {
|
|
37
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
38
|
-
|
|
39
|
-
act(() => {
|
|
40
|
-
result.current.info('Info title', 'Info message');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(result.current.notifications[0].severity).toBe('info');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('adds success notification', () => {
|
|
47
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
48
|
-
|
|
49
|
-
act(() => {
|
|
50
|
-
result.current.success('Success!');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(result.current.notifications[0].severity).toBe('success');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('adds warning notification', () => {
|
|
57
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
58
|
-
|
|
59
|
-
act(() => {
|
|
60
|
-
result.current.warning('Warning!');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
expect(result.current.notifications[0].severity).toBe('warning');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('adds error notification', () => {
|
|
67
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
68
|
-
|
|
69
|
-
act(() => {
|
|
70
|
-
result.current.error('Error!');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(result.current.notifications[0].severity).toBe('error');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('marks notification as read', () => {
|
|
77
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
78
|
-
|
|
79
|
-
let id: string = '';
|
|
80
|
-
act(() => {
|
|
81
|
-
id = result.current.info('Test');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
act(() => {
|
|
85
|
-
result.current.markAsRead(id);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(result.current.notifications[0].read).toBe(true);
|
|
89
|
-
expect(result.current.unreadCount).toBe(0);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('marks all as read', () => {
|
|
93
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
94
|
-
|
|
95
|
-
act(() => {
|
|
96
|
-
result.current.info('Test 1');
|
|
97
|
-
result.current.info('Test 2');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
act(() => {
|
|
101
|
-
result.current.markAllAsRead();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(result.current.unreadCount).toBe(0);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('dismisses a notification', () => {
|
|
108
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
109
|
-
|
|
110
|
-
let id: string = '';
|
|
111
|
-
act(() => {
|
|
112
|
-
id = result.current.info('Test');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
act(() => {
|
|
116
|
-
result.current.dismiss(id);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
expect(result.current.notifications).toHaveLength(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('clears all notifications', () => {
|
|
123
|
-
const { result } = renderHook(() => useNotifications(), { wrapper });
|
|
124
|
-
|
|
125
|
-
act(() => {
|
|
126
|
-
result.current.info('Test 1');
|
|
127
|
-
result.current.info('Test 2');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
act(() => {
|
|
131
|
-
result.current.clearAll();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(result.current.notifications).toHaveLength(0);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('calls onToast handler', () => {
|
|
138
|
-
const onToast = vi.fn();
|
|
139
|
-
const customWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
140
|
-
<NotificationProvider onToast={onToast}>{children}</NotificationProvider>
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
const { result } = renderHook(() => useNotifications(), {
|
|
144
|
-
wrapper: customWrapper,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
act(() => {
|
|
148
|
-
result.current.info('Toast test');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect(onToast).toHaveBeenCalledTimes(1);
|
|
152
|
-
expect(onToast).toHaveBeenCalledWith(
|
|
153
|
-
expect.objectContaining({ title: 'Toast test', severity: 'info' })
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('useHasNotificationProvider', () => {
|
|
159
|
-
it('returns false outside provider', () => {
|
|
160
|
-
const { result } = renderHook(() => useHasNotificationProvider());
|
|
161
|
-
expect(result.current).toBe(false);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('returns true inside provider', () => {
|
|
165
|
-
const { result } = renderHook(() => useHasNotificationProvider(), { wrapper });
|
|
166
|
-
expect(result.current).toBe(true);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('useNotifications without provider', () => {
|
|
171
|
-
it('throws error', () => {
|
|
172
|
-
expect(() => {
|
|
173
|
-
renderHook(() => useNotifications());
|
|
174
|
-
}).toThrow('useNotifications must be used within a <NotificationProvider>');
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useDataScope hook — verifies correct scoping behavior.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { renderHook } from '@testing-library/react';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import { SchemaRendererProvider, useDataScope } from '../SchemaRendererContext';
|
|
9
|
-
|
|
10
|
-
describe('useDataScope', () => {
|
|
11
|
-
it('returns undefined when no path is provided', () => {
|
|
12
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
13
|
-
<SchemaRendererProvider dataSource={{ users: [1, 2, 3] }}>
|
|
14
|
-
{children}
|
|
15
|
-
</SchemaRendererProvider>
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const { result } = renderHook(() => useDataScope(undefined), { wrapper });
|
|
19
|
-
|
|
20
|
-
expect(result.current).toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('returns undefined when path is empty string', () => {
|
|
24
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
25
|
-
<SchemaRendererProvider dataSource={{ users: [1, 2, 3] }}>
|
|
26
|
-
{children}
|
|
27
|
-
</SchemaRendererProvider>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const { result } = renderHook(() => useDataScope(''), { wrapper });
|
|
31
|
-
|
|
32
|
-
expect(result.current).toBeUndefined();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns scoped data when a valid path is given', () => {
|
|
36
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
37
|
-
<SchemaRendererProvider dataSource={{ users: [{ name: 'Alice' }] }}>
|
|
38
|
-
{children}
|
|
39
|
-
</SchemaRendererProvider>
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const { result } = renderHook(() => useDataScope('users'), { wrapper });
|
|
43
|
-
|
|
44
|
-
expect(result.current).toEqual([{ name: 'Alice' }]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('resolves nested paths', () => {
|
|
48
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
49
|
-
<SchemaRendererProvider dataSource={{ app: { settings: { theme: 'dark' } } }}>
|
|
50
|
-
{children}
|
|
51
|
-
</SchemaRendererProvider>
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const { result } = renderHook(() => useDataScope('app.settings.theme'), { wrapper });
|
|
55
|
-
|
|
56
|
-
expect(result.current).toBe('dark');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('returns undefined for non-existent path', () => {
|
|
60
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
61
|
-
<SchemaRendererProvider dataSource={{ users: [] }}>
|
|
62
|
-
{children}
|
|
63
|
-
</SchemaRendererProvider>
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const { result } = renderHook(() => useDataScope('nonexistent'), { wrapper });
|
|
67
|
-
|
|
68
|
-
expect(result.current).toBeUndefined();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('returns undefined when no SchemaRendererProvider is present', () => {
|
|
72
|
-
const { result } = renderHook(() => useDataScope('users'));
|
|
73
|
-
|
|
74
|
-
expect(result.current).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('does not return the adapter/service object when no path is given', () => {
|
|
78
|
-
// Simulate the real scenario: dataSource is a service adapter with methods
|
|
79
|
-
const adapter = { find: () => {}, create: () => {}, update: () => {} };
|
|
80
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
81
|
-
<SchemaRendererProvider dataSource={adapter}>
|
|
82
|
-
{children}
|
|
83
|
-
</SchemaRendererProvider>
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const { result } = renderHook(() => useDataScope(undefined), { wrapper });
|
|
87
|
-
|
|
88
|
-
// Should NOT return the adapter — that would prevent ObjectChart from fetching
|
|
89
|
-
expect(result.current).toBeUndefined();
|
|
90
|
-
});
|
|
91
|
-
});
|
package/src/context/index.ts
DELETED
|
@@ -1,13 +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
|
-
export * from './SchemaRendererContext';
|
|
10
|
-
export * from './ActionContext';
|
|
11
|
-
export * from './ThemeContext';
|
|
12
|
-
export * from './NotificationContext';
|
|
13
|
-
export * from './DndContext';
|