-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpage.test.ts
More file actions
1190 lines (1068 loc) · 35.3 KB
/
Copy pathpage.test.ts
File metadata and controls
1190 lines (1068 loc) · 35.3 KB
1
2
3
4
5
6
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { describe, it, expect } from 'vitest';
import {
PageSchema,
PAGE_TYPE_ROADMAP,
PageComponentSchema,
PageRegionSchema,
PageTypeSchema,
RecordReviewConfigSchema,
ElementDataSourceSchema,
BlankPageLayoutSchema,
PageVariableSchema,
InterfacePageConfigSchema,
type Page,
type PageComponent,
type PageRegion,
type ElementDataSource,
type RecordReviewConfig,
type InterfacePageConfig,
} from './page.zod';
describe('PageComponentSchema', () => {
it('should accept valid minimal component', () => {
const component: PageComponent = {
type: 'steedos-labs.related-list',
properties: {},
};
expect(() => PageComponentSchema.parse(component)).not.toThrow();
});
it('should accept component with all fields', () => {
const component = PageComponentSchema.parse({
type: 'steedos-labs.related-list',
id: 'related_contacts',
label: 'Related Contacts',
properties: {
objectName: 'contact',
filterField: 'account_id',
columns: ['name', 'email', 'phone'],
},
visibility: 'record.type == "Customer"',
});
expect(component.id).toBe('related_contacts');
expect(component.label).toBe('Related Contacts');
expect(component.visibility).toBeDefined();
});
it('should accept component with complex properties', () => {
const component = PageComponentSchema.parse({
type: 'custom.dashboard-widget',
properties: {
title: 'Sales Pipeline',
chartType: 'funnel',
dataSource: 'opportunity',
filters: { stage: { $ne: 'Closed Lost' } },
groupBy: 'stage',
aggregate: 'sum',
field: 'amount',
},
});
expect(component.properties.title).toBe('Sales Pipeline');
});
});
describe('PageRegionSchema', () => {
it('should accept valid minimal region', () => {
const region: PageRegion = {
name: 'main',
components: [],
};
expect(() => PageRegionSchema.parse(region)).not.toThrow();
});
it('should accept region with all fields', () => {
const region = PageRegionSchema.parse({
name: 'sidebar',
width: 'small',
components: [
{
type: 'steedos-labs.quick-actions',
properties: { actions: ['edit', 'delete'] },
},
],
});
expect(region.name).toBe('sidebar');
expect(region.width).toBe('small');
expect(region.components).toHaveLength(1);
});
it('should accept different region widths', () => {
const widths: Array<NonNullable<PageRegion['width']>> = ['small', 'medium', 'large', 'full'];
widths.forEach(width => {
const region = PageRegionSchema.parse({
name: 'test',
width,
components: [],
});
expect(region.width).toBe(width);
});
});
it('should accept region with multiple components', () => {
const region = PageRegionSchema.parse({
name: 'main',
components: [
{ type: 'component.header', properties: {} },
{ type: 'component.body', properties: {} },
{ type: 'component.footer', properties: {} },
],
});
expect(region.components).toHaveLength(3);
});
});
describe('PageSchema', () => {
it('should accept valid minimal page', () => {
const page: Page = {
name: 'account_record_page',
label: 'Account Record Page',
regions: [],
};
expect(() => PageSchema.parse(page)).not.toThrow();
});
it('should validate page name format (snake_case)', () => {
expect(() => PageSchema.parse({
name: 'valid_page_name',
label: 'Valid Page',
regions: [],
})).not.toThrow();
expect(() => PageSchema.parse({
name: 'InvalidPage',
label: 'Invalid',
regions: [],
})).toThrow();
expect(() => PageSchema.parse({
name: 'invalid-page',
label: 'Invalid',
regions: [],
})).toThrow();
});
it('should apply default values', () => {
const page = PageSchema.parse({
name: 'test_page',
label: 'Test Page',
regions: [],
});
expect(page.type).toBe('record');
expect(page.template).toBe('default');
expect(page.isDefault).toBe(false);
});
it('should accept page with all fields', () => {
const page = PageSchema.parse({
name: 'account_record_page',
label: 'Account Record Page',
description: 'Custom record page for accounts',
type: 'record',
object: 'account',
template: 'header-sidebar-main',
regions: [
{
name: 'header',
components: [
{ type: 'record.header', properties: {} },
],
},
{
name: 'sidebar',
width: 'small',
components: [
{ type: 'record.details', properties: {} },
],
},
{
name: 'main',
width: 'large',
components: [
{ type: 'related.list', properties: { objectName: 'contact' } },
],
},
],
isDefault: true,
assignedProfiles: ['admin', 'sales_user'],
});
expect(page.object).toBe('account');
expect(page.regions).toHaveLength(3);
expect(page.isDefault).toBe(true);
});
it('should accept the live page types', () => {
const types: Array<Page['type']> = ['record', 'home', 'app', 'utility', 'list'];
types.forEach(type => {
const page = PageSchema.parse({
name: 'test_page',
label: 'Test Page',
type,
regions: [],
});
expect(page.type).toBe(type);
});
});
it('should reject roadmap page types that have no renderer (enforce-or-remove)', () => {
// dashboard / form / record_detail / record_review / overview / blank were
// removed from PageTypeSchema — authoring one used to pass validation then
// break at runtime ("Unknown component type"). The enum is now the live set.
for (const type of PAGE_TYPE_ROADMAP) {
expect(
() => PageSchema.parse({ name: 'test_page', label: 'Test Page', type, regions: [] }),
`roadmap type "${type}" must be rejected until it ships a renderer`,
).toThrow();
}
});
it('should accept record page', () => {
const page = PageSchema.parse({
name: 'opportunity_page',
label: 'Opportunity Page',
type: 'record',
object: 'opportunity',
regions: [
{
name: 'main',
components: [
{ type: 'record.form', properties: {} },
],
},
],
});
expect(page.type).toBe('record');
expect(page.object).toBe('opportunity');
});
it('should accept home page', () => {
const page = PageSchema.parse({
name: 'sales_home',
label: 'Sales Home',
type: 'home',
regions: [
{
name: 'main',
components: [
{ type: 'dashboard.widget', properties: { dashboardId: 'sales_dashboard' } },
],
},
],
});
expect(page.type).toBe('home');
});
it('should accept app page', () => {
const page = PageSchema.parse({
name: 'sales_app',
label: 'Sales App',
type: 'app',
regions: [
{
name: 'main',
components: [
{ type: 'app.navigation', properties: {} },
],
},
],
});
expect(page.type).toBe('app');
});
it('should accept utility page', () => {
const page = PageSchema.parse({
name: 'notes_utility',
label: 'Notes Utility',
type: 'utility',
regions: [
{
name: 'main',
components: [
{ type: 'utility.notes', properties: {} },
],
},
],
});
expect(page.type).toBe('utility');
});
it('should accept page with profile assignments', () => {
const page = PageSchema.parse({
name: 'custom_page',
label: 'Custom Page',
regions: [],
assignedProfiles: ['admin', 'sales_manager', 'sales_rep'],
});
expect(page.assignedProfiles).toHaveLength(3);
});
it('should accept page with custom template', () => {
const page = PageSchema.parse({
name: 'custom_layout_page',
label: 'Custom Layout Page',
template: 'three-column-layout',
regions: [],
});
expect(page.template).toBe('three-column-layout');
});
it('should accept default page', () => {
const page = PageSchema.parse({
name: 'default_page',
label: 'Default Page',
isDefault: true,
regions: [],
});
expect(page.isDefault).toBe(true);
});
it('should accept page with multiple regions', () => {
const page = PageSchema.parse({
name: 'multi_region_page',
label: 'Multi Region Page',
regions: [
{ name: 'header', components: [] },
{ name: 'sidebar', width: 'small', components: [] },
{ name: 'main', width: 'large', components: [] },
{ name: 'footer', components: [] },
],
});
expect(page.regions).toHaveLength(4);
});
it('should accept page with nested component properties', () => {
const page = PageSchema.parse({
name: 'complex_page',
label: 'Complex Page',
regions: [
{
name: 'main',
components: [
{
type: 'custom.widget',
id: 'widget_1',
properties: {
config: {
nested: {
deeply: {
value: 'test',
},
},
},
array: [1, 2, 3],
bool: true,
},
},
],
},
],
});
expect(page.regions[0].components[0].properties.config).toBeDefined();
});
it('should reject page without required fields', () => {
expect(() => PageSchema.parse({
label: 'Test Page',
regions: [],
})).toThrow();
expect(() => PageSchema.parse({
name: 'test_page',
regions: [],
})).toThrow();
// `regions` is intentionally NOT among the required fields — name + label
// alone is a valid page (regions defaults to [], type defaults to 'record').
// See the dedicated "accept page without regions" test below.
});
it('should reject invalid page type', () => {
expect(() => PageSchema.parse({
name: 'test_page',
label: 'Test Page',
type: 'invalid',
regions: [],
})).toThrow();
});
});
describe('Page I18n Integration', () => {
it('should reject i18n object as page label', () => {
expect(() => PageSchema.parse({
name: 'i18n_page',
label: { key: 'pages.dashboard', defaultValue: 'Dashboard' },
regions: [],
})).toThrow();
});
it('should reject i18n as page description', () => {
expect(() => PageSchema.parse({
name: 'desc_page',
label: 'Test',
description: { key: 'pages.test.desc', defaultValue: 'A test page' },
regions: [],
})).toThrow();
});
it('should reject i18n as component label', () => {
expect(() => PageComponentSchema.parse({
type: 'page:header',
label: { key: 'components.header', defaultValue: 'Header' },
properties: {},
})).toThrow();
});
});
describe('Page ARIA Integration', () => {
it('should accept page with ARIA attributes', () => {
expect(() => PageSchema.parse({
name: 'accessible_page',
label: 'Accessible Page',
regions: [],
aria: { ariaLabel: 'Main application page', role: 'main' },
})).not.toThrow();
});
it('should accept component with ARIA attributes', () => {
expect(() => PageComponentSchema.parse({
type: 'nav:menu',
properties: {},
aria: { ariaLabel: 'Main navigation', role: 'navigation' },
})).not.toThrow();
});
});
describe('Page Responsive Integration', () => {
it('should accept component with responsive config', () => {
const result = PageComponentSchema.parse({
type: 'page:sidebar',
properties: {},
responsive: { hiddenOn: ['xs', 'sm'] },
});
expect(result.responsive?.hiddenOn).toEqual(['xs', 'sm']);
});
});
// ---------------------------------------------------------------------------
// PageTypeSchema — unified page types (platform + interface)
// ---------------------------------------------------------------------------
describe('PageTypeSchema', () => {
it('should accept all platform page types', () => {
const types = ['record', 'home', 'app', 'utility'];
types.forEach(type => {
expect(() => PageTypeSchema.parse(type)).not.toThrow();
});
});
it('should accept the live interface page type and reject roadmap ones', () => {
// `list` is the only live interface page type. The rest were declared for
// "roadmap parity" but never rendered — removed from PageTypeSchema
// (enforce-or-remove, tracked in PAGE_TYPE_ROADMAP).
expect(() => PageTypeSchema.parse('list')).not.toThrow();
PAGE_TYPE_ROADMAP.forEach(type => {
expect(() => PageTypeSchema.parse(type), `roadmap type "${type}"`).toThrow();
});
});
it('should reject visualizations as page types (they belong in interfaceConfig.appearance.allowedVisualizations)', () => {
// grid/kanban/calendar/gallery/timeline are visualizations of a `list`
// page, not page kinds — they were removed from PageTypeSchema.
['grid', 'kanban', 'calendar', 'gallery', 'timeline'].forEach(type => {
expect(() => PageTypeSchema.parse(type)).toThrow();
});
});
it('should reject invalid page type', () => {
expect(() => PageTypeSchema.parse('invalid')).toThrow();
});
});
// ---------------------------------------------------------------------------
// RecordReviewConfigSchema
// ---------------------------------------------------------------------------
describe('RecordReviewConfigSchema', () => {
it('should accept minimal review config', () => {
const config: RecordReviewConfig = RecordReviewConfigSchema.parse({
object: 'order',
actions: [
{ label: 'Approve', type: 'approve' },
],
});
expect(config.object).toBe('order');
expect(config.actions).toHaveLength(1);
expect(config.navigation).toBe('sequential');
expect(config.showProgress).toBe(true);
});
it('should accept full review config', () => {
const config = RecordReviewConfigSchema.parse({
object: 'invoice',
filter: { status: 'pending' },
sort: [{ field: 'created_at', order: 'desc' }],
displayFields: ['amount', 'vendor', 'description'],
actions: [
{ label: 'Approve', type: 'approve', field: 'status', value: 'approved', nextRecord: true },
{ label: 'Reject', type: 'reject', field: 'status', value: 'rejected' },
{ label: 'Skip', type: 'skip', nextRecord: true },
{ label: 'Flag', type: 'custom', field: 'flagged', value: true },
],
navigation: 'filtered',
showProgress: false,
});
expect(config.actions).toHaveLength(4);
expect(config.navigation).toBe('filtered');
expect(config.showProgress).toBe(false);
expect(config.displayFields).toEqual(['amount', 'vendor', 'description']);
});
it('should reject review config without object', () => {
expect(() => RecordReviewConfigSchema.parse({
actions: [{ label: 'Approve', type: 'approve' }],
})).toThrow();
});
it('should reject review config without actions', () => {
expect(() => RecordReviewConfigSchema.parse({
object: 'order',
})).toThrow();
});
it('should accept all action types', () => {
const types = ['approve', 'reject', 'skip', 'custom'] as const;
types.forEach(type => {
expect(() => RecordReviewConfigSchema.parse({
object: 'order',
actions: [{ label: 'Action', type }],
})).not.toThrow();
});
});
it('should accept all navigation modes', () => {
const modes = ['sequential', 'random', 'filtered'] as const;
modes.forEach(navigation => {
const config = RecordReviewConfigSchema.parse({
object: 'order',
actions: [{ label: 'Ok', type: 'approve' }],
navigation,
});
expect(config.navigation).toBe(navigation);
});
});
});
// ---------------------------------------------------------------------------
// PageSchema with page types
// ---------------------------------------------------------------------------
describe('PageSchema with page types', () => {
it('should accept a minimal live page', () => {
const page: Page = PageSchema.parse({
name: 'page_overview',
label: 'Overview',
type: 'home',
regions: [],
});
expect(page.name).toBe('page_overview');
expect(page.type).toBe('home');
expect(page.template).toBe('default');
});
it('should accept an app page with components', () => {
const page = PageSchema.parse({
name: 'page_dashboard',
label: 'Dashboard',
type: 'app',
regions: [
{
name: 'main',
components: [
{ type: 'element:number', properties: { object: 'order', aggregate: 'count' } },
],
},
],
});
expect(page.type).toBe('app');
expect(page.regions[0].components).toHaveLength(1);
});
it('should accept page with variables', () => {
const page = PageSchema.parse({
name: 'page_filtered',
label: 'Filtered View',
type: 'home',
variables: [
{ name: 'selectedId', type: 'string' },
{ name: 'showArchived', type: 'boolean', defaultValue: false },
],
regions: [],
});
expect(page.variables).toHaveLength(2);
});
it('should accept page with icon', () => {
const page = PageSchema.parse({
name: 'page_with_icon',
label: 'Dashboard',
type: 'home',
icon: 'bar-chart',
regions: [],
});
expect(page.icon).toBe('bar-chart');
});
it('should reject page with i18n label', () => {
expect(() => PageSchema.parse({
name: 'i18n_page',
label: { key: 'pages.overview', defaultValue: 'Overview' },
regions: [],
})).toThrow();
});
it('should accept page with ARIA attributes', () => {
expect(() => PageSchema.parse({
name: 'accessible_page',
label: 'Accessible Page',
regions: [],
aria: { ariaLabel: 'App overview page', role: 'main' },
})).not.toThrow();
});
});
// ---------------------------------------------------------------------------
// ElementDataSourceSchema (per-element data binding)
// ---------------------------------------------------------------------------
describe('ElementDataSourceSchema', () => {
it('should accept minimal data source', () => {
const ds: ElementDataSource = ElementDataSourceSchema.parse({
object: 'order',
});
expect(ds.object).toBe('order');
expect(ds.view).toBeUndefined();
expect(ds.filter).toBeUndefined();
expect(ds.sort).toBeUndefined();
expect(ds.limit).toBeUndefined();
});
it('should accept full data source', () => {
const ds = ElementDataSourceSchema.parse({
object: 'invoice',
view: 'pending_review',
filter: { status: 'pending' },
sort: [{ field: 'created_at', order: 'desc' }],
limit: 50,
});
expect(ds.object).toBe('invoice');
expect(ds.view).toBe('pending_review');
expect(ds.sort).toHaveLength(1);
expect(ds.limit).toBe(50);
});
it('should reject without object', () => {
expect(() => ElementDataSourceSchema.parse({})).toThrow();
});
it('should reject invalid sort order', () => {
expect(() => ElementDataSourceSchema.parse({
object: 'order',
sort: [{ field: 'name', order: 'invalid' }],
})).toThrow();
});
});
// ---------------------------------------------------------------------------
// PageComponent dataSource integration
// ---------------------------------------------------------------------------
describe('PageComponent dataSource integration', () => {
it('should accept component with dataSource', () => {
const component = PageComponentSchema.parse({
type: 'element:number',
properties: { object: 'order', aggregate: 'sum', field: 'total' },
dataSource: {
object: 'order',
filter: { status: 'completed' },
limit: 100,
},
});
expect(component.dataSource?.object).toBe('order');
expect(component.dataSource?.limit).toBe(100);
});
it('should accept component without dataSource', () => {
const component = PageComponentSchema.parse({
type: 'element:text',
properties: { content: 'Static text' },
});
expect(component.dataSource).toBeUndefined();
});
});
// ---------------------------------------------------------------------------
// BlankPageLayoutSchema — free-form canvas composition
// ---------------------------------------------------------------------------
describe('BlankPageLayoutSchema', () => {
it('should accept minimal layout with defaults', () => {
const layout = BlankPageLayoutSchema.parse({
items: [],
});
expect(layout.columns).toBe(12);
expect(layout.rowHeight).toBe(40);
expect(layout.gap).toBe(8);
expect(layout.items).toHaveLength(0);
});
it('should accept full layout config', () => {
const layout = BlankPageLayoutSchema.parse({
columns: 24,
rowHeight: 20,
gap: 4,
items: [
{ componentId: 'text_1', x: 0, y: 0, width: 12, height: 2 },
{ componentId: 'btn_1', x: 0, y: 2, width: 6, height: 1 },
{ componentId: 'picker_1', x: 6, y: 2, width: 6, height: 3 },
],
});
expect(layout.columns).toBe(24);
expect(layout.items).toHaveLength(3);
expect(layout.items[0].x).toBe(0);
expect(layout.items[2].width).toBe(6);
});
it('should reject item with invalid dimensions', () => {
expect(() => BlankPageLayoutSchema.parse({
items: [{ componentId: 'a', x: 0, y: 0, width: 0, height: 1 }],
})).toThrow();
expect(() => BlankPageLayoutSchema.parse({
items: [{ componentId: 'a', x: -1, y: 0, width: 1, height: 1 }],
})).toThrow();
});
it('should accept page with blankLayout', () => {
const page = PageSchema.parse({
name: 'blank_canvas',
label: 'Canvas',
type: 'home',
regions: [
{
name: 'main',
components: [
{ id: 'text_1', type: 'element:text', properties: { content: 'Hello' } },
{ id: 'btn_1', type: 'element:button', properties: { label: 'Click' } },
],
},
],
blankLayout: {
columns: 12,
items: [
{ componentId: 'text_1', x: 0, y: 0, width: 12, height: 2 },
{ componentId: 'btn_1', x: 0, y: 2, width: 4, height: 1 },
],
},
});
expect(page.blankLayout?.items).toHaveLength(2);
expect(page.blankLayout?.columns).toBe(12);
});
});
// ---------------------------------------------------------------------------
// PageVariableSchema — record_picker variable binding
// ---------------------------------------------------------------------------
describe('PageVariableSchema record_id type', () => {
it('should accept record_id variable type', () => {
const variable = PageVariableSchema.parse({
name: 'selected_account_id',
type: 'record_id',
});
expect(variable.type).toBe('record_id');
});
it('should accept variable with source binding', () => {
const variable = PageVariableSchema.parse({
name: 'selected_account',
type: 'record_id',
source: 'picker_1',
});
expect(variable.source).toBe('picker_1');
});
it('should accept page with record_picker variable binding', () => {
const page = PageSchema.parse({
name: 'blank_picker',
label: 'Picker Page',
type: 'home',
blankLayout: { items: [] },
variables: [
{ name: 'selected_id', type: 'record_id', source: 'account_picker' },
{ name: 'show_details', type: 'boolean', defaultValue: false },
],
regions: [
{
name: 'main',
components: [
{
id: 'account_picker',
type: 'element:record_picker',
properties: {
object: 'account',
displayField: 'name',
targetVariable: 'selected_id',
},
},
],
},
],
});
expect(page.variables).toHaveLength(2);
expect(page.variables![0].type).toBe('record_id');
expect(page.variables![0].source).toBe('account_picker');
});
});
// ---------------------------------------------------------------------------
// Page end-to-end
// ---------------------------------------------------------------------------
describe('Page end-to-end', () => {
it('should accept a complete real-world page definition', () => {
const page = PageSchema.parse({
name: 'page_overview',
label: 'Overview',
type: 'home',
object: 'order',
regions: [
{
name: 'main',
components: [
{
type: 'element:text',
properties: { content: '# Order Dashboard', variant: 'heading' },
},
{
type: 'element:number',
properties: { object: 'order', aggregate: 'count' },
dataSource: { object: 'order', filter: { status: 'pending' } },
},
{
type: 'element:number',
properties: { object: 'order', aggregate: 'sum', field: 'total', format: 'currency', prefix: '$' },
dataSource: { object: 'order', filter: { status: 'completed' } },
},
{
type: 'element:divider',
properties: {},
},
{
type: 'element:image',
properties: { src: '/images/banner.jpg', alt: 'Order management', fit: 'cover', height: 200 },
},
],
},
],
});
expect(page.name).toBe('page_overview');
expect(page.regions[0].components).toHaveLength(5);
});
it('should accept a record_review page with full config', () => {
const page = PageSchema.parse({
name: 'page_review',
label: 'Review Queue',
type: 'home',
object: 'order',
recordReview: {
object: 'order',
filter: { status: 'pending_review' },
sort: [{ field: 'priority', order: 'desc' }],
displayFields: ['customer_name', 'total', 'items_count'],
actions: [
{ label: 'Approve', type: 'approve', field: 'status', value: 'approved' },
{ label: 'Reject', type: 'reject', field: 'status', value: 'rejected' },
{ label: 'Skip', type: 'skip' },
],
navigation: 'sequential',
showProgress: true,
},
regions: [],
});
expect(page.recordReview?.actions).toHaveLength(3);
});
it('should accept a list page bound to an object', () => {
// A grid is a *visualization* of a list page, not a page type — bind the
// object on a `list` page and pick the grid visualization via interfaceConfig.
const page = PageSchema.parse({
name: 'page_grid',
label: 'All Orders',
type: 'list',
object: 'order',
regions: [],
});
expect(page.type).toBe('list');
expect(page.object).toBe('order');
});
});
// ---------------------------------------------------------------------------
// InterfacePageConfigSchema — Airtable Interface parity
// ---------------------------------------------------------------------------
describe('InterfacePageConfigSchema', () => {
it('should accept empty config', () => {
const config: InterfacePageConfig = InterfacePageConfigSchema.parse({});
expect(config).toBeDefined();
});
it('should accept full interface page config', () => {
const config = InterfacePageConfigSchema.parse({
source: 'customers',
levels: 1,
filterBy: [{ field: 'status', operator: 'equals', value: 'active' }],
appearance: {
showDescription: true,
allowedVisualizations: ['grid', 'gallery', 'kanban'],
},
userFilters: {
element: 'tabs',
tabs: [
{ name: 'my_customers', label: 'my customers', isDefault: true },
{ name: 'all_records', label: 'All records' },
],
},
userActions: {
sort: true,
search: true,
filter: true,
rowHeight: true,
addRecordForm: false,
buttons: [],
},
addRecord: {
enabled: true,
position: 'bottom',
mode: 'inline',
},
showRecordCount: true,
allowPrinting: true,
});
expect(config.source).toBe('customers');
expect(config.levels).toBe(1);
expect(config.appearance?.allowedVisualizations).toHaveLength(3);
expect(config.userFilters?.tabs).toHaveLength(2);
expect(config.userActions?.sort).toBe(true);
expect(config.showRecordCount).toBe(true);
expect(config.allowPrinting).toBe(true);
});
it('should accept config with only source and levels', () => {
const config = InterfacePageConfigSchema.parse({
source: 'orders',
levels: 2,
});
expect(config.source).toBe('orders');
expect(config.levels).toBe(2);
});
it('should reject levels < 1', () => {
expect(() => InterfacePageConfigSchema.parse({
levels: 0,
})).toThrow();
});
});