@object-ui/components 0.5.0 → 3.0.0
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/.turbo/turbo-build.log +12 -25
- package/CHANGELOG.md +32 -0
- package/dist/index.css +1 -1
- package/dist/index.js +23987 -22576
- package/dist/index.umd.cjs +30 -30
- package/dist/src/custom/action-param-dialog.d.ts +21 -0
- package/dist/src/custom/index.d.ts +4 -0
- package/dist/src/custom/navigation-overlay.d.ts +50 -0
- package/dist/src/custom/view-skeleton.d.ts +37 -0
- package/dist/src/custom/view-states.d.ts +33 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/renderers/action/action-button.d.ts +11 -0
- package/dist/src/renderers/action/action-group.d.ts +25 -0
- package/dist/src/renderers/action/action-icon.d.ts +10 -0
- package/dist/src/renderers/action/action-menu.d.ts +19 -0
- package/dist/src/renderers/action/index.d.ts +0 -0
- package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
- package/package.json +20 -19
- package/src/__tests__/PageRendererRegions.test.tsx +664 -55
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +811 -0
- package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +327 -0
- package/src/__tests__/accessibility.test.tsx +137 -0
- package/src/__tests__/api-consistency.test.tsx +596 -0
- package/src/__tests__/color-contrast.test.tsx +212 -0
- package/src/__tests__/compliance.test.tsx +72 -0
- package/src/__tests__/edge-cases.test.tsx +285 -0
- package/src/__tests__/navigation-overlay.test.tsx +273 -0
- package/src/__tests__/snapshot-critical.test.tsx +317 -0
- package/src/__tests__/snapshot.test.tsx +205 -0
- package/src/__tests__/view-compliance.test.tsx +153 -0
- package/src/__tests__/wcag-audit.test.tsx +493 -0
- package/src/custom/action-param-dialog.tsx +264 -0
- package/src/custom/index.ts +4 -0
- package/src/custom/navigation-overlay.tsx +296 -0
- package/src/custom/view-skeleton.tsx +243 -0
- package/src/custom/view-states.tsx +153 -0
- package/src/index.ts +1 -0
- package/src/renderers/action/action-button.tsx +147 -0
- package/src/renderers/action/action-group.tsx +270 -0
- package/src/renderers/action/action-icon.tsx +150 -0
- package/src/renderers/action/action-menu.tsx +203 -0
- package/src/renderers/action/index.ts +18 -0
- package/src/renderers/action/resolve-icon.ts +35 -0
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
- package/src/renderers/complex/data-table.tsx +269 -33
- package/src/renderers/complex/resizable.tsx +20 -17
- package/src/renderers/data-display/list.tsx +1 -1
- package/src/renderers/data-display/table.tsx +1 -1
- package/src/renderers/data-display/tree-view.tsx +2 -1
- package/src/renderers/form/form.tsx +33 -10
- package/src/renderers/index.ts +1 -0
- package/src/renderers/layout/aspect-ratio.tsx +1 -1
- package/src/renderers/layout/page.tsx +416 -52
- package/src/renderers/navigation/sidebar.tsx +6 -0
- package/src/renderers/placeholders.tsx +2 -2
- package/src/stories/MockedData.stories.tsx +87 -37
- package/src/stories-json/Accessibility.mdx +297 -0
- package/src/stories-json/EdgeCases.stories.tsx +160 -0
- package/src/stories-json/GettingStarted.mdx +89 -0
- package/src/stories-json/Introduction.mdx +127 -0
- package/src/stories-json/accordion.stories.tsx +1 -1
- package/src/stories-json/aggrid.stories.tsx +1 -1
- package/src/stories-json/alert.stories.tsx +1 -1
- package/src/stories-json/aspect-ratio.stories.tsx +1 -1
- package/src/stories-json/avatar.stories.tsx +1 -1
- package/src/stories-json/badge.stories.tsx +1 -1
- package/src/stories-json/breadcrumb.stories.tsx +1 -1
- package/src/stories-json/button-group.stories.tsx +1 -1
- package/src/stories-json/button.stories.tsx +1 -1
- package/src/stories-json/calendar.stories.tsx +1 -1
- package/src/stories-json/card.stories.tsx +1 -1
- package/src/stories-json/carousel.stories.tsx +1 -1
- package/src/stories-json/charts.stories.tsx +1 -1
- package/src/stories-json/chatbot.stories.tsx +1 -1
- package/src/stories-json/code-editor.stories.tsx +1 -1
- package/src/stories-json/collapsible.stories.tsx +1 -1
- package/src/stories-json/controls.stories.tsx +1 -1
- package/src/stories-json/crm-live-data.stories.tsx +154 -0
- package/src/stories-json/data-table.stories.tsx +80 -4
- package/src/stories-json/data_display_extras.stories.tsx +1 -1
- package/src/stories-json/date-picker.stories.tsx +1 -1
- package/src/stories-json/detail-view.stories.tsx +1 -1
- package/src/stories-json/dialog.stories.tsx +1 -1
- package/src/stories-json/feedback_extras.stories.tsx +1 -1
- package/src/stories-json/feedback_others.stories.tsx +1 -1
- package/src/stories-json/form-variants.stories.tsx +210 -0
- package/src/stories-json/form_advanced.stories.tsx +1 -1
- package/src/stories-json/form_extras.stories.tsx +1 -1
- package/src/stories-json/grid.stories.tsx +1 -1
- package/src/stories-json/icon.stories.tsx +1 -1
- package/src/stories-json/input.stories.tsx +1 -1
- package/src/stories-json/kanban.stories.tsx +1 -1
- package/src/stories-json/layout_extended.stories.tsx +1 -1
- package/src/stories-json/layout_flex.stories.tsx +1 -1
- package/src/stories-json/list-view.stories.tsx +1 -1
- package/src/stories-json/markdown.stories.tsx +1 -1
- package/src/stories-json/menus.stories.tsx +1 -1
- package/src/stories-json/metric-card.stories.tsx +1 -1
- package/src/stories-json/navigation-menu.stories.tsx +1 -1
- package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
- package/src/stories-json/object-aggrid.stories.tsx +1 -1
- package/src/stories-json/object-form.stories.tsx +1 -1
- package/src/stories-json/object-gantt.stories.tsx +1 -1
- package/src/stories-json/object-grid.stories.tsx +159 -1
- package/src/stories-json/object-map.stories.tsx +1 -1
- package/src/stories-json/object-view.stories.tsx +1 -1
- package/src/stories-json/overlay_extras.stories.tsx +1 -1
- package/src/stories-json/overlay_others.stories.tsx +1 -1
- package/src/stories-json/resizable.stories.tsx +1 -1
- package/src/stories-json/select.stories.tsx +1 -1
- package/src/stories-json/separator.stories.tsx +1 -1
- package/src/stories-json/statistic.stories.tsx +1 -1
- package/src/stories-json/tabs.stories.tsx +1 -1
- package/src/stories-json/timeline.stories.tsx +1 -1
- package/src/stories-json/typography.stories.tsx +1 -1
- package/src/ui/slider.tsx +6 -2
- package/src/stories/Introduction.mdx +0 -34
|
@@ -1,59 +1,668 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI — Page Renderer Tests
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* Comprehensive tests for the upgraded Page system:
|
|
6
|
+
* - Page types (record, home, app, utility)
|
|
7
|
+
* - Region-based layouts (header, sidebar, main, aside, footer)
|
|
8
|
+
* - Page variables (PageVariablesProvider)
|
|
9
|
+
* - Legacy body/children fallback
|
|
10
|
+
* - Registration & metadata
|
|
11
|
+
*/
|
|
1
12
|
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
13
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
3
14
|
import { render, screen } from '@testing-library/react';
|
|
4
15
|
import React from 'react';
|
|
5
|
-
import { PageRenderer } from '../renderers/layout/page';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
16
|
+
import { PageRenderer } from '../renderers/layout/page';
|
|
17
|
+
import {
|
|
18
|
+
renderComponent,
|
|
19
|
+
validateComponentRegistration,
|
|
20
|
+
} from './test-utils';
|
|
21
|
+
|
|
22
|
+
// Import renderers to ensure full registration
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
await import('../renderers');
|
|
25
|
+
}, 30000);
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Registration
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
describe('Page Registration', () => {
|
|
32
|
+
it('should register "page" type', () => {
|
|
33
|
+
const v = validateComponentRegistration('page');
|
|
34
|
+
expect(v.isRegistered).toBe(true);
|
|
35
|
+
expect(v.hasConfig).toBe(true);
|
|
36
|
+
expect(v.hasLabel).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should register "record" alias', () => {
|
|
40
|
+
expect(validateComponentRegistration('record').isRegistered).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should register "home" alias', () => {
|
|
44
|
+
expect(validateComponentRegistration('home').isRegistered).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should register "app" alias', () => {
|
|
48
|
+
expect(validateComponentRegistration('app').isRegistered).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should register "utility" alias', () => {
|
|
52
|
+
expect(validateComponentRegistration('utility').isRegistered).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should include pageType input in metadata', () => {
|
|
56
|
+
const v = validateComponentRegistration('page');
|
|
57
|
+
const inputNames = v.config?.inputs?.map((i: any) => i.name) ?? [];
|
|
58
|
+
expect(inputNames).toContain('pageType');
|
|
59
|
+
expect(inputNames).toContain('regions');
|
|
60
|
+
expect(inputNames).toContain('variables');
|
|
61
|
+
expect(inputNames).toContain('object');
|
|
62
|
+
expect(inputNames).toContain('template');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Basic rendering (title, description)
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
describe('PageRenderer — Basic', () => {
|
|
71
|
+
it('should render title and description', () => {
|
|
72
|
+
const { container } = render(
|
|
73
|
+
<PageRenderer
|
|
74
|
+
schema={{ type: 'page', title: 'My Page', description: 'A test page' } as any}
|
|
75
|
+
/>,
|
|
76
|
+
);
|
|
77
|
+
expect(screen.getByText('My Page')).toBeDefined();
|
|
78
|
+
expect(screen.getByText('A test page')).toBeDefined();
|
|
79
|
+
expect(container.querySelector('h1')?.textContent).toBe('My Page');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should render without title gracefully', () => {
|
|
83
|
+
const { container } = render(
|
|
84
|
+
<PageRenderer schema={{ type: 'page' } as any} />,
|
|
85
|
+
);
|
|
86
|
+
expect(container.querySelector('h1')).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should apply data-page-type attribute', () => {
|
|
90
|
+
const { container } = render(
|
|
91
|
+
<PageRenderer
|
|
92
|
+
schema={{ type: 'page', pageType: 'home' } as any}
|
|
93
|
+
/>,
|
|
94
|
+
);
|
|
95
|
+
const root = container.firstElementChild as HTMLElement;
|
|
96
|
+
expect(root.getAttribute('data-page-type')).toBe('home');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should default to record page type', () => {
|
|
100
|
+
const { container } = render(
|
|
101
|
+
<PageRenderer schema={{ type: 'page' } as any} />,
|
|
102
|
+
);
|
|
103
|
+
const root = container.firstElementChild as HTMLElement;
|
|
104
|
+
expect(root.getAttribute('data-page-type')).toBe('record');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should apply custom className', () => {
|
|
108
|
+
const { container } = render(
|
|
109
|
+
<PageRenderer
|
|
110
|
+
schema={{ type: 'page' } as any}
|
|
111
|
+
className="my-custom-class"
|
|
112
|
+
/>,
|
|
113
|
+
);
|
|
114
|
+
const root = container.firstElementChild as HTMLElement;
|
|
115
|
+
expect(root.className).toContain('my-custom-class');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should pass through designer props', () => {
|
|
119
|
+
const { container } = render(
|
|
120
|
+
<PageRenderer
|
|
121
|
+
schema={{ type: 'page' } as any}
|
|
122
|
+
data-obj-id="page-1"
|
|
123
|
+
data-obj-type="page"
|
|
124
|
+
/>,
|
|
125
|
+
);
|
|
126
|
+
const root = container.firstElementChild as HTMLElement;
|
|
127
|
+
expect(root.getAttribute('data-obj-id')).toBe('page-1');
|
|
128
|
+
expect(root.getAttribute('data-obj-type')).toBe('page');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Region rendering
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
describe('PageRenderer — Regions', () => {
|
|
137
|
+
it('should render components from a single main region', () => {
|
|
138
|
+
const schema: any = {
|
|
139
|
+
type: 'page',
|
|
140
|
+
title: 'Test Page',
|
|
141
|
+
regions: [
|
|
142
|
+
{
|
|
143
|
+
name: 'main',
|
|
144
|
+
components: [
|
|
145
|
+
{ type: 'text', value: 'Region Content 1' },
|
|
146
|
+
{ type: 'text', value: 'Region Content 2' },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
153
|
+
expect(screen.getByText('Test Page')).toBeDefined();
|
|
154
|
+
|
|
155
|
+
// Verify region is rendered with data-region attribute
|
|
156
|
+
const mainRegion = container.querySelector('[data-region="main"]');
|
|
157
|
+
expect(mainRegion).not.toBeNull();
|
|
158
|
+
expect(mainRegion!.textContent).toContain('Region Content 1');
|
|
159
|
+
expect(mainRegion!.textContent).toContain('Region Content 2');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should render header region', () => {
|
|
163
|
+
const schema: any = {
|
|
164
|
+
type: 'page',
|
|
165
|
+
regions: [
|
|
166
|
+
{
|
|
167
|
+
name: 'header',
|
|
168
|
+
components: [{ type: 'text', value: 'Header Content' }],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: 'main',
|
|
172
|
+
components: [{ type: 'text', value: 'Main Content' }],
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
178
|
+
expect(screen.getByText('Header Content')).toBeDefined();
|
|
179
|
+
expect(screen.getByText('Main Content')).toBeDefined();
|
|
180
|
+
|
|
181
|
+
// Header region should have data-region attribute
|
|
182
|
+
const headerRegion = container.querySelector('[data-region="header"]');
|
|
183
|
+
expect(headerRegion).not.toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should render sidebar region', () => {
|
|
187
|
+
const schema: any = {
|
|
188
|
+
type: 'page',
|
|
189
|
+
regions: [
|
|
190
|
+
{
|
|
191
|
+
name: 'sidebar',
|
|
192
|
+
components: [{ type: 'text', value: 'Sidebar Nav' }],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'main',
|
|
196
|
+
components: [{ type: 'text', value: 'Main Body' }],
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
202
|
+
expect(screen.getByText('Sidebar Nav')).toBeDefined();
|
|
203
|
+
expect(screen.getByText('Main Body')).toBeDefined();
|
|
204
|
+
|
|
205
|
+
const sidebarRegion = container.querySelector('[data-region="sidebar"]');
|
|
206
|
+
expect(sidebarRegion).not.toBeNull();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should render aside region', () => {
|
|
210
|
+
const schema: any = {
|
|
211
|
+
type: 'page',
|
|
212
|
+
regions: [
|
|
213
|
+
{
|
|
214
|
+
name: 'main',
|
|
215
|
+
components: [{ type: 'text', value: 'Center' }],
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'aside',
|
|
219
|
+
components: [{ type: 'text', value: 'Right Panel' }],
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
225
|
+
expect(screen.getByText('Center')).toBeDefined();
|
|
226
|
+
expect(screen.getByText('Right Panel')).toBeDefined();
|
|
227
|
+
|
|
228
|
+
const asideRegion = container.querySelector('[data-region="aside"]');
|
|
229
|
+
expect(asideRegion).not.toBeNull();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should render footer region', () => {
|
|
233
|
+
const schema: any = {
|
|
234
|
+
type: 'page',
|
|
235
|
+
regions: [
|
|
236
|
+
{
|
|
237
|
+
name: 'main',
|
|
238
|
+
components: [{ type: 'text', value: 'Main' }],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'footer',
|
|
242
|
+
components: [{ type: 'text', value: 'Footer Info' }],
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
248
|
+
expect(screen.getByText('Footer Info')).toBeDefined();
|
|
249
|
+
|
|
250
|
+
const footerRegion = container.querySelector('[data-region="footer"]');
|
|
251
|
+
expect(footerRegion).not.toBeNull();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should render full structured layout (header + sidebar + main + aside + footer)', () => {
|
|
255
|
+
const schema: any = {
|
|
256
|
+
type: 'page',
|
|
257
|
+
regions: [
|
|
258
|
+
{ name: 'header', components: [{ type: 'text', value: 'H' }] },
|
|
259
|
+
{ name: 'sidebar', components: [{ type: 'text', value: 'S' }] },
|
|
260
|
+
{ name: 'main', components: [{ type: 'text', value: 'M' }] },
|
|
261
|
+
{ name: 'aside', components: [{ type: 'text', value: 'A' }] },
|
|
262
|
+
{ name: 'footer', components: [{ type: 'text', value: 'F' }] },
|
|
263
|
+
],
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
267
|
+
for (const text of ['H', 'S', 'M', 'A', 'F']) {
|
|
268
|
+
expect(screen.getByText(text)).toBeDefined();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// All five named regions should be present
|
|
272
|
+
for (const name of ['header', 'sidebar', 'main', 'aside', 'footer']) {
|
|
273
|
+
expect(container.querySelector(`[data-region="${name}"]`)).not.toBeNull();
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('should render unnamed/extra regions alongside main', () => {
|
|
278
|
+
const schema: any = {
|
|
279
|
+
type: 'page',
|
|
280
|
+
regions: [
|
|
281
|
+
{ name: 'main', components: [{ type: 'text', value: 'Main Content' }] },
|
|
282
|
+
{ name: 'analytics', components: [{ type: 'text', value: 'Analytics Widget' }] },
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
render(<PageRenderer schema={schema} />);
|
|
287
|
+
expect(screen.getByText('Main Content')).toBeDefined();
|
|
288
|
+
expect(screen.getByText('Analytics Widget')).toBeDefined();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should handle empty regions gracefully', () => {
|
|
292
|
+
const schema: any = {
|
|
293
|
+
type: 'page',
|
|
294
|
+
title: 'Empty Regions',
|
|
295
|
+
regions: [
|
|
296
|
+
{ name: 'main', components: [] },
|
|
297
|
+
{ name: 'sidebar', components: [] },
|
|
298
|
+
],
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
302
|
+
expect(screen.getByText('Empty Regions')).toBeDefined();
|
|
303
|
+
// Should not crash
|
|
304
|
+
expect(container).toBeDefined();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should handle regions with no named slots (flat stacking)', () => {
|
|
308
|
+
const schema: any = {
|
|
309
|
+
type: 'page',
|
|
310
|
+
regions: [
|
|
311
|
+
{ name: 'section1', components: [{ type: 'text', value: 'First' }] },
|
|
312
|
+
{ name: 'section2', components: [{ type: 'text', value: 'Second' }] },
|
|
313
|
+
],
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
render(<PageRenderer schema={schema} />);
|
|
317
|
+
expect(screen.getByText('First')).toBeDefined();
|
|
318
|
+
expect(screen.getByText('Second')).toBeDefined();
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should apply region className', () => {
|
|
322
|
+
const schema: any = {
|
|
323
|
+
type: 'page',
|
|
324
|
+
regions: [
|
|
325
|
+
{
|
|
326
|
+
name: 'section1',
|
|
327
|
+
className: 'bg-blue-500',
|
|
328
|
+
components: [{ type: 'text', value: 'Styled' }],
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
334
|
+
const region = container.querySelector('[data-region="section1"]');
|
|
335
|
+
expect(region?.className).toContain('bg-blue-500');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
// Page type variants
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
|
|
343
|
+
describe('PageRenderer — Page Types', () => {
|
|
344
|
+
it('should render record page type with max-w-7xl', () => {
|
|
345
|
+
const { container } = render(
|
|
346
|
+
<PageRenderer
|
|
347
|
+
schema={{ type: 'page', pageType: 'record', title: 'Record' } as any}
|
|
348
|
+
/>,
|
|
349
|
+
);
|
|
350
|
+
const inner = container.querySelector('.mx-auto');
|
|
351
|
+
expect(inner?.className).toContain('max-w-7xl');
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should render home page type with max-w-screen-2xl', () => {
|
|
355
|
+
const { container } = render(
|
|
356
|
+
<PageRenderer
|
|
357
|
+
schema={{ type: 'page', pageType: 'home', title: 'Home' } as any}
|
|
358
|
+
/>,
|
|
359
|
+
);
|
|
360
|
+
const inner = container.querySelector('.mx-auto');
|
|
361
|
+
expect(inner?.className).toContain('max-w-screen-2xl');
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('should render app page type with max-w-screen-xl', () => {
|
|
365
|
+
const { container } = render(
|
|
366
|
+
<PageRenderer
|
|
367
|
+
schema={{ type: 'page', pageType: 'app', title: 'App' } as any}
|
|
368
|
+
/>,
|
|
369
|
+
);
|
|
370
|
+
const inner = container.querySelector('.mx-auto');
|
|
371
|
+
expect(inner?.className).toContain('max-w-screen-xl');
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('should render utility page type with max-w-4xl', () => {
|
|
375
|
+
const { container } = render(
|
|
376
|
+
<PageRenderer
|
|
377
|
+
schema={{ type: 'page', pageType: 'utility', title: 'Utility' } as any}
|
|
378
|
+
/>,
|
|
379
|
+
);
|
|
380
|
+
const inner = container.querySelector('.mx-auto');
|
|
381
|
+
expect(inner?.className).toContain('max-w-4xl');
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// ---------------------------------------------------------------------------
|
|
386
|
+
// Legacy body/children fallback
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
|
|
389
|
+
describe('PageRenderer — Legacy Fallback', () => {
|
|
390
|
+
it('should render body array', () => {
|
|
391
|
+
const schema: any = {
|
|
392
|
+
type: 'page',
|
|
393
|
+
title: 'Legacy Page',
|
|
394
|
+
body: [{ type: 'text', value: 'Body Content' }],
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
render(<PageRenderer schema={schema} />);
|
|
398
|
+
expect(screen.getByText('Body Content')).toBeDefined();
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should render children array', () => {
|
|
402
|
+
const schema: any = {
|
|
403
|
+
type: 'page',
|
|
404
|
+
children: [{ type: 'text', value: 'Child Content' }],
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
render(<PageRenderer schema={schema} />);
|
|
408
|
+
expect(screen.getByText('Child Content')).toBeDefined();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('should prefer regions over body when both exist', () => {
|
|
412
|
+
const schema: any = {
|
|
413
|
+
type: 'page',
|
|
414
|
+
regions: [
|
|
415
|
+
{
|
|
416
|
+
name: 'main',
|
|
417
|
+
components: [{ type: 'text', value: 'From Regions' }],
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
body: [{ type: 'text', value: 'From Body' }],
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
render(<PageRenderer schema={schema} />);
|
|
424
|
+
expect(screen.getByText('From Regions')).toBeDefined();
|
|
425
|
+
// Body should not render when regions are present
|
|
426
|
+
expect(screen.queryByText('From Body')).toBeNull();
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('should render empty page without errors', () => {
|
|
430
|
+
const schema: any = { type: 'page' };
|
|
431
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
432
|
+
expect(container).toBeDefined();
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// ---------------------------------------------------------------------------
|
|
437
|
+
// Page Variables
|
|
438
|
+
// ---------------------------------------------------------------------------
|
|
439
|
+
|
|
440
|
+
describe('PageRenderer — Variables', () => {
|
|
441
|
+
it('should wrap content with PageVariablesProvider when variables defined', () => {
|
|
442
|
+
const schema: any = {
|
|
443
|
+
type: 'page',
|
|
444
|
+
title: 'Variable Page',
|
|
445
|
+
variables: [
|
|
446
|
+
{ name: 'selectedId', type: 'string', defaultValue: '' },
|
|
447
|
+
{ name: 'count', type: 'number', defaultValue: 0 },
|
|
448
|
+
],
|
|
449
|
+
body: [{ type: 'text', value: 'Content' }],
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// Renders without error — provider wraps content
|
|
453
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
454
|
+
expect(screen.getByText('Variable Page')).toBeDefined();
|
|
455
|
+
expect(screen.getByText('Content')).toBeDefined();
|
|
456
|
+
expect(container).toBeDefined();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('should render without provider when no variables', () => {
|
|
460
|
+
const schema: any = {
|
|
461
|
+
type: 'page',
|
|
462
|
+
title: 'No Variables',
|
|
463
|
+
body: [{ type: 'text', value: 'Plain' }],
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
467
|
+
expect(screen.getByText('Plain')).toBeDefined();
|
|
468
|
+
expect(container).toBeDefined();
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('should render without provider when variables is empty array', () => {
|
|
472
|
+
const schema: any = {
|
|
473
|
+
type: 'page',
|
|
474
|
+
title: 'Empty Vars',
|
|
475
|
+
variables: [],
|
|
476
|
+
body: [{ type: 'text', value: 'Still Plain' }],
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
480
|
+
expect(screen.getByText('Still Plain')).toBeDefined();
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// ---------------------------------------------------------------------------
|
|
485
|
+
// Integration — via ComponentRegistry renderComponent
|
|
486
|
+
// ---------------------------------------------------------------------------
|
|
487
|
+
|
|
488
|
+
describe('PageRenderer — Registry Integration', () => {
|
|
489
|
+
it('should render page via ComponentRegistry', () => {
|
|
490
|
+
const { container } = renderComponent({
|
|
491
|
+
type: 'page',
|
|
492
|
+
title: 'Registry Page',
|
|
493
|
+
body: [{ type: 'text', value: 'Works' }],
|
|
494
|
+
} as any);
|
|
495
|
+
|
|
496
|
+
expect(screen.getByText('Registry Page')).toBeDefined();
|
|
497
|
+
expect(screen.getByText('Works')).toBeDefined();
|
|
498
|
+
expect(container).toBeDefined();
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it('should render home page via registry alias', () => {
|
|
502
|
+
const { container } = renderComponent({
|
|
503
|
+
type: 'home',
|
|
504
|
+
title: 'Home Dashboard',
|
|
505
|
+
body: [{ type: 'text', value: 'Dashboard Content' }],
|
|
506
|
+
} as any);
|
|
507
|
+
|
|
508
|
+
expect(screen.getByText('Home Dashboard')).toBeDefined();
|
|
509
|
+
expect(container).toBeDefined();
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('should render record page via registry alias', () => {
|
|
513
|
+
const { container } = renderComponent({
|
|
514
|
+
type: 'record',
|
|
515
|
+
title: 'Account Detail',
|
|
516
|
+
} as any);
|
|
517
|
+
|
|
518
|
+
expect(screen.getByText('Account Detail')).toBeDefined();
|
|
519
|
+
expect(container).toBeDefined();
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// ---------------------------------------------------------------------------
|
|
524
|
+
// Page Templates — predefined layout templates
|
|
525
|
+
// ---------------------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
describe('PageRenderer — Templates', () => {
|
|
528
|
+
it('should use header-sidebar-main template when specified', () => {
|
|
529
|
+
const schema: any = {
|
|
530
|
+
type: 'page',
|
|
531
|
+
title: 'Template Page',
|
|
532
|
+
template: 'header-sidebar-main',
|
|
533
|
+
regions: [
|
|
534
|
+
{
|
|
535
|
+
name: 'header',
|
|
536
|
+
components: [{ type: 'text', value: 'Header Content' }],
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
name: 'sidebar',
|
|
540
|
+
components: [{ type: 'text', value: 'Sidebar Content' }],
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
name: 'main',
|
|
544
|
+
components: [{ type: 'text', value: 'Main Content' }],
|
|
545
|
+
},
|
|
546
|
+
],
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
550
|
+
|
|
551
|
+
expect(screen.getByText('Header Content')).toBeDefined();
|
|
552
|
+
expect(screen.getByText('Sidebar Content')).toBeDefined();
|
|
553
|
+
expect(screen.getByText('Main Content')).toBeDefined();
|
|
554
|
+
expect(container.querySelector('[data-template="header-sidebar-main"]')).toBeDefined();
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('should use three-column template when specified', () => {
|
|
558
|
+
const schema: any = {
|
|
559
|
+
type: 'page',
|
|
560
|
+
title: 'Three Column',
|
|
561
|
+
template: 'three-column',
|
|
562
|
+
regions: [
|
|
563
|
+
{
|
|
564
|
+
name: 'sidebar',
|
|
565
|
+
components: [{ type: 'text', value: 'Left Sidebar' }],
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: 'main',
|
|
569
|
+
components: [{ type: 'text', value: 'Center Main' }],
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
name: 'aside',
|
|
573
|
+
components: [{ type: 'text', value: 'Right Aside' }],
|
|
574
|
+
},
|
|
575
|
+
],
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
579
|
+
|
|
580
|
+
expect(screen.getByText('Left Sidebar')).toBeDefined();
|
|
581
|
+
expect(screen.getByText('Center Main')).toBeDefined();
|
|
582
|
+
expect(screen.getByText('Right Aside')).toBeDefined();
|
|
583
|
+
expect(container.querySelector('[data-template="three-column"]')).toBeDefined();
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it('should use dashboard template with grid layout', () => {
|
|
587
|
+
const schema: any = {
|
|
588
|
+
type: 'page',
|
|
589
|
+
title: 'Dashboard',
|
|
590
|
+
template: 'dashboard',
|
|
591
|
+
regions: [
|
|
592
|
+
{
|
|
593
|
+
name: 'header',
|
|
594
|
+
components: [{ type: 'text', value: 'Dashboard Header' }],
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: 'widget1',
|
|
598
|
+
components: [{ type: 'text', value: 'Widget 1' }],
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
name: 'widget2',
|
|
602
|
+
components: [{ type: 'text', value: 'Widget 2' }],
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
608
|
+
|
|
609
|
+
expect(screen.getByText('Dashboard Header')).toBeDefined();
|
|
610
|
+
expect(screen.getByText('Widget 1')).toBeDefined();
|
|
611
|
+
expect(screen.getByText('Widget 2')).toBeDefined();
|
|
612
|
+
expect(container.querySelector('[data-template="dashboard"]')).toBeDefined();
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it('should fall back to page type layout when template is unknown', () => {
|
|
616
|
+
const schema: any = {
|
|
617
|
+
type: 'page',
|
|
618
|
+
title: 'Unknown Template',
|
|
619
|
+
template: 'nonexistent-template',
|
|
620
|
+
pageType: 'home',
|
|
621
|
+
body: [{ type: 'text', value: 'Fallback Content' }],
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
625
|
+
|
|
626
|
+
expect(screen.getByText('Unknown Template')).toBeDefined();
|
|
627
|
+
expect(screen.getByText('Fallback Content')).toBeDefined();
|
|
628
|
+
// Should fall back to home page layout
|
|
629
|
+
expect(container.querySelector('[data-page-type="home"]')).toBeDefined();
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('should use default template when template is "default"', () => {
|
|
633
|
+
const schema: any = {
|
|
634
|
+
type: 'page',
|
|
635
|
+
title: 'Default Template',
|
|
636
|
+
template: 'default',
|
|
637
|
+
regions: [
|
|
638
|
+
{
|
|
639
|
+
name: 'main',
|
|
640
|
+
components: [{ type: 'text', value: 'Default Content' }],
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
646
|
+
expect(screen.getByText('Default Content')).toBeDefined();
|
|
647
|
+
expect(container).toBeDefined();
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it('should prioritize template over pageType', () => {
|
|
651
|
+
const schema: any = {
|
|
652
|
+
type: 'page',
|
|
653
|
+
title: 'Template Priority',
|
|
654
|
+
template: 'dashboard',
|
|
655
|
+
pageType: 'record',
|
|
656
|
+
regions: [
|
|
657
|
+
{
|
|
658
|
+
name: 'panel1',
|
|
659
|
+
components: [{ type: 'text', value: 'Panel 1' }],
|
|
660
|
+
},
|
|
661
|
+
],
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
const { container } = render(<PageRenderer schema={schema} />);
|
|
665
|
+
// Should use dashboard template, not record layout
|
|
666
|
+
expect(container.querySelector('[data-template="dashboard"]')).toBeDefined();
|
|
667
|
+
});
|
|
59
668
|
});
|