@object-ui/react 3.1.5 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +28 -3
  3. package/dist/SchemaRenderer.js +2 -2
  4. package/dist/components/form/FieldFactory.js +5 -2
  5. package/dist/context/AppShellContext.d.ts +26 -0
  6. package/dist/context/AppShellContext.js +67 -0
  7. package/dist/context/index.d.ts +1 -7
  8. package/dist/context/index.js +1 -7
  9. package/dist/hooks/index.d.ts +1 -0
  10. package/dist/hooks/index.js +1 -0
  11. package/dist/hooks/useDataRefresh.d.ts +36 -0
  12. package/dist/hooks/useDataRefresh.js +50 -0
  13. package/dist/hooks/useDiscovery.d.ts +12 -0
  14. package/dist/hooks/useDiscovery.js +6 -0
  15. package/dist/hooks/usePerformanceBudget.js +1 -1
  16. package/package.json +32 -9
  17. package/.turbo/turbo-build.log +0 -4
  18. package/src/LazyPluginLoader.tsx +0 -174
  19. package/src/SchemaRenderer.tsx +0 -266
  20. package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
  21. package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
  22. package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
  23. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
  24. package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
  25. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
  26. package/src/__tests__/ThemeProvider.test.tsx +0 -451
  27. package/src/__tests__/useNavigationOverlay.test.ts +0 -578
  28. package/src/__tests__/useOffline.test.ts +0 -198
  29. package/src/__tests__/usePageTransition.test.ts +0 -214
  30. package/src/__tests__/usePageVariables.test.tsx +0 -334
  31. package/src/__tests__/usePerformance.test.ts +0 -137
  32. package/src/__tests__/useViewData.test.tsx +0 -422
  33. package/src/__tests__/view-switching.test.tsx +0 -456
  34. package/src/components/form/FieldFactory.tsx +0 -509
  35. package/src/components/form/FormRenderer.test.tsx +0 -744
  36. package/src/components/form/FormRenderer.tsx +0 -258
  37. package/src/components/form/README.md +0 -352
  38. package/src/components/form/index.ts +0 -12
  39. package/src/context/ActionContext.tsx +0 -213
  40. package/src/context/DndContext.tsx +0 -260
  41. package/src/context/NotificationContext.tsx +0 -280
  42. package/src/context/SchemaRendererContext.tsx +0 -48
  43. package/src/context/ThemeContext.tsx +0 -325
  44. package/src/context/__tests__/ActionContext.test.tsx +0 -174
  45. package/src/context/__tests__/DndContext.test.tsx +0 -150
  46. package/src/context/__tests__/NotificationContext.test.tsx +0 -176
  47. package/src/context/__tests__/useDataScope.test.tsx +0 -91
  48. package/src/context/index.ts +0 -13
  49. package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
  50. package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
  51. package/src/hooks/__tests__/useAnimation.test.ts +0 -82
  52. package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
  53. package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
  54. package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
  55. package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
  56. package/src/hooks/__tests__/useDiscovery.test.tsx +0 -149
  57. package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
  58. package/src/hooks/__tests__/useETagCache.test.ts +0 -153
  59. package/src/hooks/__tests__/useExpression.test.ts +0 -86
  60. package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
  61. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
  62. package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
  63. package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
  64. package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
  65. package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
  66. package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
  67. package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
  68. package/src/hooks/index.ts +0 -35
  69. package/src/hooks/useActionEngine.ts +0 -84
  70. package/src/hooks/useActionRunner.ts +0 -119
  71. package/src/hooks/useAnimation.ts +0 -117
  72. package/src/hooks/useClientNotifications.ts +0 -251
  73. package/src/hooks/useColumnSummary.ts +0 -87
  74. package/src/hooks/useCrudShortcuts.ts +0 -126
  75. package/src/hooks/useDebugMode.ts +0 -95
  76. package/src/hooks/useDensityMode.ts +0 -102
  77. package/src/hooks/useDiscovery.ts +0 -154
  78. package/src/hooks/useDynamicApp.ts +0 -142
  79. package/src/hooks/useETagCache.ts +0 -404
  80. package/src/hooks/useExpression.ts +0 -56
  81. package/src/hooks/useFocusManagement.ts +0 -248
  82. package/src/hooks/useFocusTrap.ts +0 -138
  83. package/src/hooks/useGlobalUndo.ts +0 -98
  84. package/src/hooks/useKeyboardShortcuts.ts +0 -119
  85. package/src/hooks/useNavigationOverlay.ts +0 -190
  86. package/src/hooks/useOffline.ts +0 -301
  87. package/src/hooks/usePageTransition.ts +0 -187
  88. package/src/hooks/usePageVariables.tsx +0 -157
  89. package/src/hooks/usePerformance.ts +0 -246
  90. package/src/hooks/usePerformanceBudget.ts +0 -313
  91. package/src/hooks/useReducedMotion.ts +0 -53
  92. package/src/hooks/useSchemaPersistence.ts +0 -222
  93. package/src/hooks/useViewData.ts +0 -201
  94. package/src/hooks/useViewSharing.ts +0 -140
  95. package/src/hooks/useViewTransition.ts +0 -144
  96. package/src/index.ts +0 -41
  97. package/src/spec-bridge/SpecBridge.ts +0 -64
  98. package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
  99. package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
  100. package/src/spec-bridge/bridges/dashboard.ts +0 -180
  101. package/src/spec-bridge/bridges/form-view.ts +0 -109
  102. package/src/spec-bridge/bridges/list-view.ts +0 -187
  103. package/src/spec-bridge/bridges/page.ts +0 -136
  104. package/src/spec-bridge/index.ts +0 -14
  105. package/src/spec-bridge/types.ts +0 -38
  106. package/src/utils/i18n.ts +0 -10
  107. package/tsconfig.json +0 -17
  108. package/tsconfig.tsbuildinfo +0 -1
  109. package/vitest.config.ts +0 -2
@@ -1,550 +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 } from 'vitest';
10
- import { SpecBridge } from '../SpecBridge';
11
- import { bridgeListView } from '../bridges/list-view';
12
- import { bridgeFormView } from '../bridges/form-view';
13
- import { bridgePage } from '../bridges/page';
14
- import { bridgeDashboard } from '../bridges/dashboard';
15
- import type { BridgeFn } from '../types';
16
-
17
- describe('SpecBridge', () => {
18
- describe('class orchestration', () => {
19
- it('registers built-in bridges on construction', () => {
20
- const bridge = new SpecBridge();
21
- // All four built-in types should work without error
22
- expect(() => bridge.transform('list', {})).not.toThrow();
23
- expect(() => bridge.transform('form', {})).not.toThrow();
24
- expect(() => bridge.transform('page', {})).not.toThrow();
25
- expect(() => bridge.transform('dashboard', {})).not.toThrow();
26
- });
27
-
28
- it('throws for unknown spec types', () => {
29
- const bridge = new SpecBridge();
30
- expect(() => bridge.transform('unknown', {})).toThrow(
31
- 'No bridge registered for spec type: unknown',
32
- );
33
- });
34
-
35
- it('allows custom bridge registration', () => {
36
- const bridge = new SpecBridge();
37
- const customBridge: BridgeFn = (spec) => ({
38
- type: 'custom-widget',
39
- id: spec.id,
40
- });
41
- bridge.register('custom', customBridge);
42
-
43
- const node = bridge.transform('custom', { id: 'my-custom' });
44
- expect(node.type).toBe('custom-widget');
45
- expect(node.id).toBe('my-custom');
46
- });
47
-
48
- it('allows overriding built-in bridges', () => {
49
- const bridge = new SpecBridge();
50
- const override: BridgeFn = () => ({ type: 'my-list' });
51
- bridge.register('list', override);
52
-
53
- const node = bridge.transformListView({});
54
- expect(node.type).toBe('my-list');
55
- });
56
-
57
- it('passes context to bridge functions', () => {
58
- const bridge = new SpecBridge({
59
- user: { role: 'admin' },
60
- variables: { theme: 'dark' },
61
- });
62
- const spy: BridgeFn = (_spec, ctx) => ({
63
- type: 'test',
64
- user: ctx.user,
65
- variables: ctx.variables,
66
- });
67
- bridge.register('test', spy);
68
-
69
- const node = bridge.transform('test', {});
70
- expect(node.user).toEqual({ role: 'admin' });
71
- expect(node.variables).toEqual({ theme: 'dark' });
72
- });
73
-
74
- it('updates context via updateContext', () => {
75
- const bridge = new SpecBridge({ user: { role: 'viewer' } });
76
- bridge.updateContext({ user: { role: 'admin' } });
77
-
78
- const spy: BridgeFn = (_spec, ctx) => ({
79
- type: 'test',
80
- role: ctx.user?.role,
81
- });
82
- bridge.register('ctx-test', spy);
83
-
84
- const node = bridge.transform('ctx-test', {});
85
- expect(node.role).toBe('admin');
86
- });
87
- });
88
-
89
- describe('bridgeListView', () => {
90
- it('transforms a basic list view spec', () => {
91
- const spec = {
92
- name: 'accounts_list',
93
- label: 'All Accounts',
94
- type: 'grid',
95
- columns: [
96
- { field: 'name', label: 'Account Name', width: 200, sortable: true },
97
- { field: 'industry', label: 'Industry', width: 150 },
98
- ],
99
- data: { provider: 'object', object: 'Account' },
100
- selection: { mode: 'multiple' },
101
- pagination: { pageSize: 25 },
102
- };
103
-
104
- const bridge = new SpecBridge();
105
- const node = bridge.transformListView(spec);
106
-
107
- expect(node.type).toBe('object-grid');
108
- expect(node.id).toBe('accounts_list');
109
- expect(node.label).toBe('All Accounts');
110
- expect(node.columns).toHaveLength(2);
111
- expect(node.columns[0].accessorKey).toBe('name');
112
- expect(node.columns[0].header).toBe('Account Name');
113
- expect(node.columns[0].width).toBe(200);
114
- expect(node.columns[0].sortable).toBe(true);
115
- expect(node.columns[1].accessorKey).toBe('industry');
116
- expect(node.data).toEqual({ provider: 'object', object: 'Account' });
117
- expect(node.selection).toEqual({ mode: 'multiple' });
118
- expect(node.pagination).toEqual({ pageSize: 25 });
119
- });
120
-
121
- it('uses field name as header fallback', () => {
122
- const node = bridgeListView(
123
- { columns: [{ field: 'email' }] },
124
- {},
125
- );
126
- expect(node.columns[0].header).toBe('email');
127
- });
128
-
129
- it('maps column properties correctly', () => {
130
- const node = bridgeListView(
131
- {
132
- columns: [
133
- {
134
- field: 'status',
135
- label: 'Status',
136
- align: 'center',
137
- hidden: false,
138
- resizable: true,
139
- wrap: true,
140
- type: 'badge',
141
- pinned: 'left',
142
- summary: { type: 'count' },
143
- link: { href: '/status' },
144
- action: { type: 'navigate' },
145
- },
146
- ],
147
- },
148
- {},
149
- );
150
-
151
- const col = node.columns[0];
152
- expect(col.align).toBe('center');
153
- expect(col.hidden).toBe(false);
154
- expect(col.resizable).toBe(true);
155
- expect(col.wrap).toBe(true);
156
- expect(col.type).toBe('badge');
157
- expect(col.pinned).toBe('left');
158
- expect(col.summary).toEqual({ type: 'count' });
159
- expect(col.link).toEqual({ href: '/status' });
160
- expect(col.action).toEqual({ type: 'navigate' });
161
- });
162
-
163
- it('maps rowHeight to density', () => {
164
- const compact = bridgeListView({ rowHeight: 'compact' }, {});
165
- expect(compact.density).toBe('compact');
166
-
167
- const comfortable = bridgeListView({ rowHeight: 'comfortable' }, {});
168
- expect(comfortable.density).toBe('comfortable');
169
-
170
- const spacious = bridgeListView({ rowHeight: 'spacious' }, {});
171
- expect(spacious.density).toBe('spacious');
172
-
173
- const small = bridgeListView({ rowHeight: 'small' }, {});
174
- expect(small.density).toBe('compact');
175
-
176
- const short = bridgeListView({ rowHeight: 'short' }, {});
177
- expect(short.density).toBe('compact');
178
-
179
- const extraTall = bridgeListView({ rowHeight: 'extra_tall' }, {});
180
- expect(extraTall.density).toBe('spacious');
181
- });
182
-
183
- it('includes optional list properties', () => {
184
- const node = bridgeListView(
185
- {
186
- sort: { field: 'name', direction: 'asc' },
187
- filter: { status: 'active' },
188
- grouping: { field: 'region' },
189
- rowColor: { field: 'priority' },
190
- searchableFields: ['name', 'email'],
191
- quickFilters: [{ field: 'status', values: ['active'] }],
192
- },
193
- {},
194
- );
195
-
196
- expect(node.sort).toEqual({ field: 'name', direction: 'asc' });
197
- expect(node.filter).toEqual({ status: 'active' });
198
- expect(node.grouping).toEqual({ field: 'region' });
199
- expect(node.rowColor).toEqual({ field: 'priority' });
200
- expect(node.searchableFields).toEqual(['name', 'email']);
201
- expect(node.quickFilters).toHaveLength(1);
202
- });
203
-
204
- it('handles empty spec gracefully', () => {
205
- const node = bridgeListView({}, {});
206
- expect(node.type).toBe('object-grid');
207
- expect(node.columns).toEqual([]);
208
- });
209
- });
210
-
211
- describe('bridgeFormView', () => {
212
- it('transforms a basic form view spec', () => {
213
- const spec = {
214
- type: 'create',
215
- data: { provider: 'object', object: 'Contact' },
216
- sections: [
217
- {
218
- label: 'Basic Info',
219
- columns: 2,
220
- fields: [
221
- { field: 'firstName', label: 'First Name', required: true },
222
- { field: 'lastName', label: 'Last Name', required: true },
223
- { field: 'email', label: 'Email', placeholder: 'you@example.com' },
224
- ],
225
- },
226
- ],
227
- };
228
-
229
- const bridge = new SpecBridge();
230
- const node = bridge.transformFormView(spec);
231
-
232
- expect(node.type).toBe('object-form');
233
- expect(node.id).toBe('form-create');
234
- expect(node.data).toEqual({ provider: 'object', object: 'Contact' });
235
- expect(node.sections).toHaveLength(1);
236
- expect(node.sections[0].label).toBe('Basic Info');
237
- expect(node.sections[0].columns).toBe(2);
238
- expect(node.sections[0].fields).toHaveLength(3);
239
- expect(node.sections[0].fields[0].name).toBe('firstName');
240
- expect(node.sections[0].fields[0].required).toBe(true);
241
- });
242
-
243
- it('maps field properties correctly', () => {
244
- const node = bridgeFormView(
245
- {
246
- sections: [
247
- {
248
- fields: [
249
- {
250
- field: 'notes',
251
- label: 'Notes',
252
- placeholder: 'Enter notes',
253
- helpText: 'Keep it brief',
254
- readonly: true,
255
- hidden: false,
256
- colSpan: 2,
257
- widget: 'textarea',
258
- dependsOn: ['status'],
259
- visibleOn: '${status === "active"}',
260
- },
261
- ],
262
- },
263
- ],
264
- },
265
- {},
266
- );
267
-
268
- const field = node.sections[0].fields[0];
269
- expect(field.name).toBe('notes');
270
- expect(field.label).toBe('Notes');
271
- expect(field.placeholder).toBe('Enter notes');
272
- expect(field.helpText).toBe('Keep it brief');
273
- expect(field.readonly).toBe(true);
274
- expect(field.hidden).toBe(false);
275
- expect(field.colSpan).toBe(2);
276
- expect(field.widget).toBe('textarea');
277
- expect(field.dependsOn).toEqual(['status']);
278
- expect(field.visibleOn).toBe('${status === "active"}');
279
- });
280
-
281
- it('maps section properties correctly', () => {
282
- const node = bridgeFormView(
283
- {
284
- sections: [
285
- {
286
- label: 'Advanced',
287
- collapsible: true,
288
- collapsed: true,
289
- columns: 3,
290
- fields: [],
291
- },
292
- ],
293
- },
294
- {},
295
- );
296
-
297
- const section = node.sections[0];
298
- expect(section.label).toBe('Advanced');
299
- expect(section.collapsible).toBe(true);
300
- expect(section.collapsed).toBe(true);
301
- expect(section.columns).toBe(3);
302
- });
303
-
304
- it('uses default id when type is not specified', () => {
305
- const node = bridgeFormView({}, {});
306
- expect(node.id).toBe('form-default');
307
- });
308
-
309
- it('uses field name as label fallback', () => {
310
- const node = bridgeFormView(
311
- { sections: [{ fields: [{ field: 'age' }] }] },
312
- {},
313
- );
314
- expect(node.sections[0].fields[0].label).toBe('age');
315
- });
316
-
317
- it('passes groups through', () => {
318
- const node = bridgeFormView(
319
- { groups: [{ name: 'g1', label: 'Group 1' }] },
320
- {},
321
- );
322
- expect(node.groups).toEqual([{ name: 'g1', label: 'Group 1' }]);
323
- });
324
- });
325
-
326
- describe('bridgePage', () => {
327
- it('transforms a basic page spec', () => {
328
- const spec = {
329
- name: 'account_detail',
330
- label: 'Account Detail',
331
- type: 'detail',
332
- variables: { accountId: '123' },
333
- regions: [
334
- {
335
- name: 'main',
336
- components: [
337
- {
338
- type: 'ui.heading',
339
- id: 'title',
340
- label: 'Account Details',
341
- properties: { level: 2 },
342
- },
343
- {
344
- type: 'ui.card',
345
- id: 'info-card',
346
- className: 'mt-4',
347
- },
348
- ],
349
- },
350
- ],
351
- };
352
-
353
- const bridge = new SpecBridge();
354
- const node = bridge.transformPage(spec);
355
-
356
- expect(node.type).toBe('page');
357
- expect(node.id).toBe('account_detail');
358
- expect(node.label).toBe('Account Detail');
359
- expect(node.pageType).toBe('detail');
360
- expect(node.variables).toEqual({ accountId: '123' });
361
- expect(Array.isArray(node.body)).toBe(true);
362
-
363
- const regions = node.body as any[];
364
- expect(regions).toHaveLength(1);
365
- expect(regions[0].type).toBe('page-region');
366
- expect(regions[0].id).toBe('main');
367
-
368
- const components = regions[0].body as any[];
369
- expect(components).toHaveLength(2);
370
- expect(components[0].type).toBe('ui.heading');
371
- expect(components[0].level).toBe(2);
372
- expect(components[1].className).toBe('mt-4');
373
- });
374
-
375
- it('maps component properties and events', () => {
376
- const node = bridgePage(
377
- {
378
- regions: [
379
- {
380
- components: [
381
- {
382
- type: 'ui.button',
383
- id: 'save-btn',
384
- label: 'Save',
385
- events: { onClick: 'save' },
386
- visibility: '${canEdit}',
387
- dataSource: { provider: 'api', read: '/api/data' },
388
- responsive: { sm: 'hidden' },
389
- aria: { label: 'Save record' },
390
- },
391
- ],
392
- },
393
- ],
394
- },
395
- {},
396
- );
397
-
398
- const regions = node.body as any[];
399
- const comp = regions[0].body[0];
400
- expect(comp.type).toBe('ui.button');
401
- expect(comp.label).toBe('Save');
402
- expect(comp.events).toEqual({ onClick: 'save' });
403
- expect(comp.visibility).toBe('${canEdit}');
404
- expect(comp.dataSource).toEqual({ provider: 'api', read: '/api/data' });
405
- expect(comp.responsive).toEqual({ sm: 'hidden' });
406
- expect(comp.aria).toEqual({ label: 'Save record' });
407
- });
408
-
409
- it('includes template and object when present', () => {
410
- const node = bridgePage(
411
- { template: 'two-column', object: 'Account' },
412
- {},
413
- );
414
- expect(node.template).toBe('two-column');
415
- expect(node.object).toBe('Account');
416
- });
417
-
418
- it('handles empty regions gracefully', () => {
419
- const node = bridgePage({}, {});
420
- expect(node.type).toBe('page');
421
- expect(node.body).toEqual([]);
422
- });
423
- });
424
-
425
- describe('bridgeDashboard', () => {
426
- it('transforms a basic dashboard spec', () => {
427
- const spec = {
428
- name: 'sales_dashboard',
429
- label: 'Sales Dashboard',
430
- widgets: [
431
- {
432
- title: 'Revenue',
433
- type: 'bar-chart',
434
- object: 'Opportunity',
435
- categoryField: 'stage',
436
- valueField: 'amount',
437
- aggregate: 'sum',
438
- },
439
- {
440
- title: 'Pipeline',
441
- type: 'metric',
442
- object: 'Opportunity',
443
- valueField: 'count',
444
- },
445
- ],
446
- header: { title: 'Sales Overview' },
447
- globalFilters: [
448
- { field: 'region', type: 'select' },
449
- ],
450
- };
451
-
452
- const bridge = new SpecBridge();
453
- const node = bridge.transformDashboard(spec);
454
-
455
- expect(node.type).toBe('dashboard');
456
- expect(node.id).toBe('sales_dashboard');
457
- expect(node.label).toBe('Sales Dashboard');
458
-
459
- const body = node.body as any[];
460
- // header + filter-bar + widget-grid
461
- expect(body).toHaveLength(3);
462
- expect(body[0].type).toBe('dashboard-header');
463
- expect(body[0].title).toBe('Sales Overview');
464
- expect(body[1].type).toBe('filter-bar');
465
- expect(body[1].filters).toHaveLength(1);
466
-
467
- const widgetGrid = body[2];
468
- expect(widgetGrid.type).toBe('widget-grid');
469
- const widgets = widgetGrid.body as any[];
470
- expect(widgets).toHaveLength(2);
471
- expect(widgets[0].type).toBe('bar-chart');
472
- expect(widgets[0].title).toBe('Revenue');
473
- expect(widgets[0].categoryField).toBe('stage');
474
- expect(widgets[0].valueField).toBe('amount');
475
- expect(widgets[0].aggregate).toBe('sum');
476
- expect(widgets[1].type).toBe('metric');
477
- });
478
-
479
- it('maps widget properties correctly', () => {
480
- const node = bridgeDashboard(
481
- {
482
- widgets: [
483
- {
484
- title: 'Chart',
485
- description: 'A chart',
486
- type: 'line-chart',
487
- chartConfig: { smooth: true },
488
- colorVariant: 'blue',
489
- object: 'Deal',
490
- filter: { status: 'won' },
491
- categoryField: 'month',
492
- valueField: 'revenue',
493
- aggregate: 'avg',
494
- measures: [{ field: 'revenue', agg: 'sum' }],
495
- layout: { x: 0, y: 0, w: 6, h: 4 },
496
- },
497
- ],
498
- },
499
- {},
500
- );
501
-
502
- const widgetGrid = (node.body as any[])[0];
503
- const widget = widgetGrid.body[0];
504
- expect(widget.title).toBe('Chart');
505
- expect(widget.description).toBe('A chart');
506
- expect(widget.chartConfig).toEqual({ smooth: true });
507
- expect(widget.colorVariant).toBe('blue');
508
- expect(widget.object).toBe('Deal');
509
- expect(widget.filter).toEqual({ status: 'won' });
510
- expect(widget.measures).toHaveLength(1);
511
- expect(widget.layout).toEqual({ x: 0, y: 0, w: 6, h: 4 });
512
- });
513
-
514
- it('omits header and filters when not present', () => {
515
- const node = bridgeDashboard({ widgets: [] }, {});
516
- const body = node.body as any[];
517
- // Only widget-grid
518
- expect(body).toHaveLength(1);
519
- expect(body[0].type).toBe('widget-grid');
520
- });
521
-
522
- it('assigns sequential widget ids', () => {
523
- const node = bridgeDashboard(
524
- {
525
- widgets: [
526
- { title: 'A', type: 'metric' },
527
- { title: 'B', type: 'metric' },
528
- { title: 'C', type: 'metric' },
529
- ],
530
- },
531
- {},
532
- );
533
-
534
- const widgetGrid = (node.body as any[])[0];
535
- const widgets = widgetGrid.body as any[];
536
- expect(widgets[0].id).toBe('widget-0');
537
- expect(widgets[1].id).toBe('widget-1');
538
- expect(widgets[2].id).toBe('widget-2');
539
- });
540
-
541
- it('defaults widget type to chart', () => {
542
- const node = bridgeDashboard(
543
- { widgets: [{ title: 'Untitled' }] },
544
- {},
545
- );
546
- const widgetGrid = (node.body as any[])[0];
547
- expect(widgetGrid.body[0].type).toBe('chart');
548
- });
549
- });
550
- });