@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,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useDensityMode hook
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import { renderHook, act } from '@testing-library/react';
|
|
6
|
-
import { useDensityMode } from '../useDensityMode';
|
|
7
|
-
|
|
8
|
-
describe('useDensityMode', () => {
|
|
9
|
-
it('defaults to comfortable mode', () => {
|
|
10
|
-
const { result } = renderHook(() => useDensityMode());
|
|
11
|
-
expect(result.current.mode).toBe('comfortable');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('accepts initial mode', () => {
|
|
15
|
-
const { result } = renderHook(() => useDensityMode('compact'));
|
|
16
|
-
expect(result.current.mode).toBe('compact');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('provides correct row height for compact', () => {
|
|
20
|
-
const { result } = renderHook(() => useDensityMode('compact'));
|
|
21
|
-
expect(result.current.rowHeight).toBe(32);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('provides correct row height for comfortable', () => {
|
|
25
|
-
const { result } = renderHook(() => useDensityMode('comfortable'));
|
|
26
|
-
expect(result.current.rowHeight).toBe(40);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('provides correct row height for spacious', () => {
|
|
30
|
-
const { result } = renderHook(() => useDensityMode('spacious'));
|
|
31
|
-
expect(result.current.rowHeight).toBe(52);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('provides padding classes', () => {
|
|
35
|
-
const { result } = renderHook(() => useDensityMode('compact'));
|
|
36
|
-
expect(result.current.paddingClass).toContain('py-1');
|
|
37
|
-
expect(result.current.paddingClass).toContain('px-2');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('provides font size classes', () => {
|
|
41
|
-
const { result } = renderHook(() => useDensityMode('compact'));
|
|
42
|
-
expect(result.current.fontSizeClass).toBe('text-xs');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('cycles through modes', () => {
|
|
46
|
-
const { result } = renderHook(() => useDensityMode('compact'));
|
|
47
|
-
|
|
48
|
-
act(() => {
|
|
49
|
-
result.current.cycle();
|
|
50
|
-
});
|
|
51
|
-
expect(result.current.mode).toBe('comfortable');
|
|
52
|
-
|
|
53
|
-
act(() => {
|
|
54
|
-
result.current.cycle();
|
|
55
|
-
});
|
|
56
|
-
expect(result.current.mode).toBe('spacious');
|
|
57
|
-
|
|
58
|
-
act(() => {
|
|
59
|
-
result.current.cycle();
|
|
60
|
-
});
|
|
61
|
-
expect(result.current.mode).toBe('compact');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('allows setting mode directly', () => {
|
|
65
|
-
const { result } = renderHook(() => useDensityMode());
|
|
66
|
-
|
|
67
|
-
act(() => {
|
|
68
|
-
result.current.setMode('spacious');
|
|
69
|
-
});
|
|
70
|
-
expect(result.current.mode).toBe('spacious');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('accepts custom row heights', () => {
|
|
74
|
-
const { result } = renderHook(() =>
|
|
75
|
-
useDensityMode('compact', {
|
|
76
|
-
rowHeights: { compact: 24, comfortable: 36, spacious: 48 },
|
|
77
|
-
})
|
|
78
|
-
);
|
|
79
|
-
expect(result.current.rowHeight).toBe(24);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useDiscovery hook
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
7
|
-
import { renderHook, waitFor } from '@testing-library/react';
|
|
8
|
-
import { useDiscovery } from '../useDiscovery';
|
|
9
|
-
import { SchemaRendererContext } from '../../context/SchemaRendererContext';
|
|
10
|
-
|
|
11
|
-
function createWrapper(dataSource: any) {
|
|
12
|
-
return ({ children }: { children: React.ReactNode }) =>
|
|
13
|
-
React.createElement(
|
|
14
|
-
SchemaRendererContext.Provider,
|
|
15
|
-
{ value: { dataSource } },
|
|
16
|
-
children,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe('useDiscovery', () => {
|
|
21
|
-
it('returns isLoading false and null discovery when no context is provided', async () => {
|
|
22
|
-
const { result } = renderHook(() => useDiscovery());
|
|
23
|
-
|
|
24
|
-
await waitFor(() => {
|
|
25
|
-
expect(result.current.isLoading).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(result.current.discovery).toBeNull();
|
|
29
|
-
expect(result.current.error).toBeNull();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('returns isLoading false and null discovery when dataSource has no getDiscovery method', async () => {
|
|
33
|
-
const dataSource = { someOtherMethod: vi.fn() };
|
|
34
|
-
|
|
35
|
-
const { result } = renderHook(() => useDiscovery(), {
|
|
36
|
-
wrapper: createWrapper(dataSource),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await waitFor(() => {
|
|
40
|
-
expect(result.current.isLoading).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(result.current.discovery).toBeNull();
|
|
44
|
-
expect(result.current.error).toBeNull();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('successfully fetches discovery data from dataSource.getDiscovery()', async () => {
|
|
48
|
-
const discoveryData = {
|
|
49
|
-
name: 'test-server',
|
|
50
|
-
version: '1.0.0',
|
|
51
|
-
services: {
|
|
52
|
-
auth: { enabled: true, status: 'available' as const },
|
|
53
|
-
data: { enabled: true, status: 'available' as const },
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const dataSource = {
|
|
58
|
-
getDiscovery: vi.fn().mockResolvedValue(discoveryData),
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const { result } = renderHook(() => useDiscovery(), {
|
|
62
|
-
wrapper: createWrapper(dataSource),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(result.current.isLoading).toBe(true);
|
|
66
|
-
|
|
67
|
-
await waitFor(() => {
|
|
68
|
-
expect(result.current.isLoading).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(result.current.discovery).toEqual(discoveryData);
|
|
72
|
-
expect(result.current.error).toBeNull();
|
|
73
|
-
expect(dataSource.getDiscovery).toHaveBeenCalled();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('handles errors from getDiscovery gracefully', async () => {
|
|
77
|
-
const dataSource = {
|
|
78
|
-
getDiscovery: vi.fn().mockRejectedValue(new Error('Network error')),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const { result } = renderHook(() => useDiscovery(), {
|
|
82
|
-
wrapper: createWrapper(dataSource),
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
await waitFor(() => {
|
|
86
|
-
expect(result.current.isLoading).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(result.current.discovery).toBeNull();
|
|
90
|
-
expect(result.current.error?.message).toBe('Network error');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('isAuthEnabled defaults to true when no discovery', async () => {
|
|
94
|
-
const { result } = renderHook(() => useDiscovery());
|
|
95
|
-
|
|
96
|
-
await waitFor(() => {
|
|
97
|
-
expect(result.current.isLoading).toBe(false);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
expect(result.current.isAuthEnabled).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('isAuthEnabled reflects the auth service enabled state', async () => {
|
|
104
|
-
const discoveryData = {
|
|
105
|
-
services: {
|
|
106
|
-
auth: { enabled: false },
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const dataSource = {
|
|
111
|
-
getDiscovery: vi.fn().mockResolvedValue(discoveryData),
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const { result } = renderHook(() => useDiscovery(), {
|
|
115
|
-
wrapper: createWrapper(dataSource),
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
await waitFor(() => {
|
|
119
|
-
expect(result.current.isLoading).toBe(false);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
expect(result.current.isAuthEnabled).toBe(false);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('cleans up on unmount (cancelled flag)', async () => {
|
|
126
|
-
let resolveDiscovery: (value: any) => void;
|
|
127
|
-
const discoveryPromise = new Promise((resolve) => {
|
|
128
|
-
resolveDiscovery = resolve;
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const dataSource = {
|
|
132
|
-
getDiscovery: vi.fn().mockReturnValue(discoveryPromise),
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const { result, unmount } = renderHook(() => useDiscovery(), {
|
|
136
|
-
wrapper: createWrapper(dataSource),
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
expect(result.current.isLoading).toBe(true);
|
|
140
|
-
|
|
141
|
-
unmount();
|
|
142
|
-
|
|
143
|
-
// Resolve after unmount — state should not update
|
|
144
|
-
resolveDiscovery!({ name: 'late-response' });
|
|
145
|
-
|
|
146
|
-
// Discovery should remain null since the component was unmounted
|
|
147
|
-
expect(result.current.discovery).toBeNull();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useDynamicApp hook
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
6
|
-
import { renderHook, waitFor, act } from '@testing-library/react';
|
|
7
|
-
import { useDynamicApp } from '../useDynamicApp';
|
|
8
|
-
|
|
9
|
-
describe('useDynamicApp', () => {
|
|
10
|
-
const staticConfig = {
|
|
11
|
-
name: 'crm',
|
|
12
|
-
label: 'CRM App',
|
|
13
|
-
objects: ['contact', 'account'],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
it('returns static config when no adapter is provided', () => {
|
|
17
|
-
const { result } = renderHook(() =>
|
|
18
|
-
useDynamicApp({ appId: 'crm', staticConfig }),
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
expect(result.current.config).toEqual(staticConfig);
|
|
22
|
-
expect(result.current.isLoading).toBe(false);
|
|
23
|
-
expect(result.current.isServerConfig).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('returns null config when neither adapter nor static config provided', () => {
|
|
27
|
-
const { result } = renderHook(() =>
|
|
28
|
-
useDynamicApp({ appId: 'crm' }),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(result.current.config).toBeNull();
|
|
32
|
-
expect(result.current.isLoading).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('loads config from server adapter', async () => {
|
|
36
|
-
const serverConfig = { name: 'crm', label: 'CRM (Server)', objects: ['contact'] };
|
|
37
|
-
const adapter = {
|
|
38
|
-
getApp: vi.fn().mockResolvedValue(serverConfig),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const { result } = renderHook(() =>
|
|
42
|
-
useDynamicApp({ appId: 'crm', staticConfig, adapter }),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// Initially loading
|
|
46
|
-
expect(result.current.isLoading).toBe(true);
|
|
47
|
-
|
|
48
|
-
await waitFor(() => {
|
|
49
|
-
expect(result.current.isLoading).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(result.current.config).toEqual(serverConfig);
|
|
53
|
-
expect(result.current.isServerConfig).toBe(true);
|
|
54
|
-
expect(adapter.getApp).toHaveBeenCalledWith('crm');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('falls back to static config when server returns null', async () => {
|
|
58
|
-
const adapter = {
|
|
59
|
-
getApp: vi.fn().mockResolvedValue(null),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const { result } = renderHook(() =>
|
|
63
|
-
useDynamicApp({ appId: 'crm', staticConfig, adapter }),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
await waitFor(() => {
|
|
67
|
-
expect(result.current.isLoading).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(result.current.config).toEqual(staticConfig);
|
|
71
|
-
expect(result.current.isServerConfig).toBe(false);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('falls back to static config on server error', async () => {
|
|
75
|
-
const adapter = {
|
|
76
|
-
getApp: vi.fn().mockRejectedValue(new Error('Network error')),
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const { result } = renderHook(() =>
|
|
80
|
-
useDynamicApp({ appId: 'crm', staticConfig, adapter }),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
await waitFor(() => {
|
|
84
|
-
expect(result.current.isLoading).toBe(false);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
expect(result.current.config).toEqual(staticConfig);
|
|
88
|
-
expect(result.current.isServerConfig).toBe(false);
|
|
89
|
-
expect(result.current.error?.message).toBe('Network error');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('skips loading when enabled is false', () => {
|
|
93
|
-
const adapter = {
|
|
94
|
-
getApp: vi.fn(),
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const { result } = renderHook(() =>
|
|
98
|
-
useDynamicApp({ appId: 'crm', staticConfig, adapter, enabled: false }),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
expect(result.current.config).toEqual(staticConfig);
|
|
102
|
-
expect(result.current.isLoading).toBe(false);
|
|
103
|
-
expect(adapter.getApp).not.toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('refresh invalidates cache and re-fetches', async () => {
|
|
107
|
-
let callCount = 0;
|
|
108
|
-
const adapter = {
|
|
109
|
-
getApp: vi.fn().mockImplementation(async () => {
|
|
110
|
-
callCount++;
|
|
111
|
-
return { name: 'crm', version: callCount };
|
|
112
|
-
}),
|
|
113
|
-
invalidateCache: vi.fn(),
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const { result } = renderHook(() =>
|
|
117
|
-
useDynamicApp({ appId: 'crm', adapter }),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
await waitFor(() => {
|
|
121
|
-
expect(result.current.isLoading).toBe(false);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect((result.current.config as any).version).toBe(1);
|
|
125
|
-
|
|
126
|
-
await act(async () => {
|
|
127
|
-
await result.current.refresh();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(adapter.invalidateCache).toHaveBeenCalledWith('app:crm');
|
|
131
|
-
expect((result.current.config as any).version).toBe(2);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('reloads when appId changes', async () => {
|
|
135
|
-
const adapter = {
|
|
136
|
-
getApp: vi.fn().mockImplementation(async (appId: string) => {
|
|
137
|
-
return { name: appId };
|
|
138
|
-
}),
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const { result, rerender } = renderHook(
|
|
142
|
-
({ appId }: { appId: string }) =>
|
|
143
|
-
useDynamicApp({ appId, adapter }),
|
|
144
|
-
{ initialProps: { appId: 'crm' } },
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
await waitFor(() => {
|
|
148
|
-
expect(result.current.isLoading).toBe(false);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect((result.current.config as any).name).toBe('crm');
|
|
152
|
-
|
|
153
|
-
rerender({ appId: 'erp' });
|
|
154
|
-
|
|
155
|
-
await waitFor(() => {
|
|
156
|
-
expect((result.current.config as any).name).toBe('erp');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(adapter.getApp).toHaveBeenCalledWith('erp');
|
|
160
|
-
});
|
|
161
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useETagCache hook
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
5
|
-
import { renderHook, act } from '@testing-library/react';
|
|
6
|
-
import { useETagCache } from '../useETagCache';
|
|
7
|
-
|
|
8
|
-
describe('useETagCache', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
vi.restoreAllMocks();
|
|
11
|
-
// Clear the module-scoped memory cache between tests
|
|
12
|
-
const { result } = renderHook(() => useETagCache());
|
|
13
|
-
act(() => {
|
|
14
|
-
result.current.clearCache();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
vi.restoreAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns initial state with cacheSize: 0', () => {
|
|
23
|
-
const { result } = renderHook(() => useETagCache());
|
|
24
|
-
|
|
25
|
-
expect(result.current.cacheSize).toBe(0);
|
|
26
|
-
expect(result.current.serviceWorkerActive).toBe(false);
|
|
27
|
-
expect(result.current.fetchWithETag).toBeTypeOf('function');
|
|
28
|
-
expect(result.current.invalidate).toBeTypeOf('function');
|
|
29
|
-
expect(result.current.clearCache).toBeTypeOf('function');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('fetchWithETag makes a network request and caches the response', async () => {
|
|
33
|
-
const mockData = { id: 1, name: 'Test' };
|
|
34
|
-
const mockHeaders = new Headers({ etag: '"abc123"' });
|
|
35
|
-
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(
|
|
36
|
-
new Response(JSON.stringify(mockData), {
|
|
37
|
-
status: 200,
|
|
38
|
-
headers: mockHeaders,
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const { result } = renderHook(() => useETagCache());
|
|
43
|
-
|
|
44
|
-
let response: { data: unknown; fromCache: boolean; etag?: string } | undefined;
|
|
45
|
-
await act(async () => {
|
|
46
|
-
response = await result.current.fetchWithETag('/api/test');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
expect(response!.data).toEqual(mockData);
|
|
50
|
-
expect(response!.fromCache).toBe(false);
|
|
51
|
-
expect(response!.etag).toBe('"abc123"');
|
|
52
|
-
expect(result.current.cacheSize).toBe(1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('fetchWithETag sends If-None-Match header on subsequent requests', async () => {
|
|
56
|
-
const mockData = { id: 1 };
|
|
57
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch');
|
|
58
|
-
|
|
59
|
-
// First request — returns data with ETag
|
|
60
|
-
fetchSpy.mockResolvedValueOnce(
|
|
61
|
-
new Response(JSON.stringify(mockData), {
|
|
62
|
-
status: 200,
|
|
63
|
-
headers: new Headers({ etag: '"etag-1"' }),
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const { result } = renderHook(() => useETagCache());
|
|
68
|
-
|
|
69
|
-
await act(async () => {
|
|
70
|
-
await result.current.fetchWithETag('/api/data');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Second request — server returns 304
|
|
74
|
-
fetchSpy.mockResolvedValueOnce(
|
|
75
|
-
new Response(null, { status: 304 }),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
let response: { data: unknown; fromCache: boolean; etag?: string } | undefined;
|
|
79
|
-
await act(async () => {
|
|
80
|
-
response = await result.current.fetchWithETag('/api/data');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Verify If-None-Match was sent
|
|
84
|
-
const secondCallArgs = fetchSpy.mock.calls[1];
|
|
85
|
-
const headers = secondCallArgs[1]?.headers as Headers;
|
|
86
|
-
expect(headers.get('If-None-Match')).toBe('"etag-1"');
|
|
87
|
-
expect(response!.fromCache).toBe(true);
|
|
88
|
-
expect(response!.data).toEqual(mockData);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('invalidate removes a specific cache entry', async () => {
|
|
92
|
-
const mockData = { id: 1 };
|
|
93
|
-
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(
|
|
94
|
-
new Response(JSON.stringify(mockData), {
|
|
95
|
-
status: 200,
|
|
96
|
-
headers: new Headers({ etag: '"etag-x"' }),
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const { result } = renderHook(() => useETagCache());
|
|
101
|
-
|
|
102
|
-
await act(async () => {
|
|
103
|
-
await result.current.fetchWithETag('/api/item');
|
|
104
|
-
});
|
|
105
|
-
expect(result.current.cacheSize).toBe(1);
|
|
106
|
-
|
|
107
|
-
act(() => {
|
|
108
|
-
result.current.invalidate('/api/item');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
expect(result.current.cacheSize).toBe(0);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('clearCache removes all entries', async () => {
|
|
115
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch');
|
|
116
|
-
|
|
117
|
-
fetchSpy.mockResolvedValueOnce(
|
|
118
|
-
new Response(JSON.stringify({ a: 1 }), {
|
|
119
|
-
status: 200,
|
|
120
|
-
headers: new Headers({ etag: '"e1"' }),
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
fetchSpy.mockResolvedValueOnce(
|
|
124
|
-
new Response(JSON.stringify({ b: 2 }), {
|
|
125
|
-
status: 200,
|
|
126
|
-
headers: new Headers({ etag: '"e2"' }),
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const { result } = renderHook(() => useETagCache());
|
|
131
|
-
|
|
132
|
-
await act(async () => {
|
|
133
|
-
await result.current.fetchWithETag('/api/a');
|
|
134
|
-
});
|
|
135
|
-
await act(async () => {
|
|
136
|
-
await result.current.fetchWithETag('/api/b');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
expect(result.current.cacheSize).toBe(2);
|
|
140
|
-
|
|
141
|
-
act(() => {
|
|
142
|
-
result.current.clearCache();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
expect(result.current.cacheSize).toBe(0);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('serviceWorkerActive is false initially', () => {
|
|
149
|
-
const { result } = renderHook(() => useETagCache());
|
|
150
|
-
|
|
151
|
-
expect(result.current.serviceWorkerActive).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for useExpression and useCondition hooks
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { renderHook } from '@testing-library/react';
|
|
7
|
-
import { useExpression, useCondition } from '../useExpression';
|
|
8
|
-
|
|
9
|
-
describe('useExpression', () => {
|
|
10
|
-
it('returns string value directly for non-expression strings', () => {
|
|
11
|
-
const { result } = renderHook(() => useExpression('hello'));
|
|
12
|
-
|
|
13
|
-
expect(result.current).toBe('hello');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns number value directly', () => {
|
|
17
|
-
const { result } = renderHook(() => useExpression(42));
|
|
18
|
-
|
|
19
|
-
expect(result.current).toBe(42);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns boolean value directly', () => {
|
|
23
|
-
const { result } = renderHook(() => useExpression(true));
|
|
24
|
-
|
|
25
|
-
expect(result.current).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns null for null expressions', () => {
|
|
29
|
-
const { result } = renderHook(() => useExpression(null));
|
|
30
|
-
|
|
31
|
-
expect(result.current).toBeNull();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('returns undefined for undefined expressions', () => {
|
|
35
|
-
const { result } = renderHook(() => useExpression(undefined));
|
|
36
|
-
|
|
37
|
-
expect(result.current).toBeUndefined();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('evaluates expressions with ${...} syntax', () => {
|
|
41
|
-
const context = { data: { name: 'John' } };
|
|
42
|
-
const { result } = renderHook(() =>
|
|
43
|
-
useExpression('${data.name}', context),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(result.current).toBe('John');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('evaluates expressions with context data', () => {
|
|
50
|
-
const context = { data: { age: 25 } };
|
|
51
|
-
const { result } = renderHook(() =>
|
|
52
|
-
useExpression('${data.age > 18}', context),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
expect(result.current).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('useCondition', () => {
|
|
60
|
-
it('returns true for boolean true', () => {
|
|
61
|
-
const { result } = renderHook(() => useCondition(true));
|
|
62
|
-
|
|
63
|
-
expect(result.current).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('returns false for boolean false', () => {
|
|
67
|
-
const { result } = renderHook(() => useCondition(false));
|
|
68
|
-
|
|
69
|
-
expect(result.current).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('returns true for undefined', () => {
|
|
73
|
-
const { result } = renderHook(() => useCondition(undefined));
|
|
74
|
-
|
|
75
|
-
expect(result.current).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('evaluates string conditions with context', () => {
|
|
79
|
-
const context = { data: { status: 'active' } };
|
|
80
|
-
const { result } = renderHook(() =>
|
|
81
|
-
useCondition('${data.status === "active"}', context),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(result.current).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
});
|