-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcomponent.test.ts
More file actions
821 lines (722 loc) · 27.3 KB
/
Copy pathcomponent.test.ts
File metadata and controls
821 lines (722 loc) · 27.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
import { describe, it, expect } from 'vitest';
import {
PageHeaderProps,
PageTabsProps,
PageCardProps,
RecordDetailsProps,
RecordRelatedListProps,
RecordHighlightsProps,
RecordActivityProps,
RecordChatterProps,
ComponentPropsMap,
ElementTextPropsSchema,
ElementNumberPropsSchema,
ElementImagePropsSchema,
ElementButtonPropsSchema,
ElementFilterPropsSchema,
ElementFormPropsSchema,
ElementRecordPickerPropsSchema,
ElementTextInputPropsSchema,
} from './component.zod';
import { PageComponentSchema } from './page.zod';
describe('PageHeaderProps', () => {
it('should accept minimal header', () => {
const result = PageHeaderProps.parse({ title: 'My Page' });
expect(result.title).toBe('My Page');
expect(result.breadcrumb).toBe(true);
expect(result.subtitle).toBeUndefined();
expect(result.icon).toBeUndefined();
expect(result.actions).toBeUndefined();
});
it('should accept full header with all fields', () => {
const header = {
title: 'Dashboard',
subtitle: 'Overview',
icon: 'home',
breadcrumb: false,
actions: ['action-1', 'action-2'],
};
const result = PageHeaderProps.parse(header);
expect(result.breadcrumb).toBe(false);
expect(result.actions).toHaveLength(2);
});
it('should reject header without title', () => {
expect(() => PageHeaderProps.parse({})).toThrow();
});
});
describe('PageTabsProps', () => {
it('should accept valid tabs with defaults', () => {
const tabs = {
items: [{ label: 'Tab 1', children: [] }],
};
const result = PageTabsProps.parse(tabs);
expect(result.type).toBe('line');
expect(result.position).toBe('top');
expect(result.items).toHaveLength(1);
});
it('should accept tabs with all options', () => {
const tabs = {
type: 'card' as const,
position: 'left' as const,
items: [{ label: 'Tab 1', icon: 'settings', children: ['child1'] }],
};
expect(() => PageTabsProps.parse(tabs)).not.toThrow();
});
it('should reject invalid type enum', () => {
expect(() => PageTabsProps.parse({ type: 'invalid', items: [] })).toThrow();
});
it('should reject tabs without items', () => {
expect(() => PageTabsProps.parse({})).toThrow();
});
});
describe('PageCardProps', () => {
it('should accept empty card with defaults', () => {
const result = PageCardProps.parse({});
expect(result.bordered).toBe(true);
expect(result.title).toBeUndefined();
expect(result.actions).toBeUndefined();
expect(result.body).toBeUndefined();
expect(result.footer).toBeUndefined();
});
it('should accept full card', () => {
const card = {
title: 'Info Card',
bordered: false,
actions: ['edit', 'delete'],
body: ['component1'],
footer: ['footer-component'],
};
const result = PageCardProps.parse(card);
expect(result.title).toBe('Info Card');
expect(result.bordered).toBe(false);
});
});
describe('RecordDetailsProps', () => {
it('should accept empty with defaults', () => {
const result = RecordDetailsProps.parse({});
expect(result.columns).toBe('2');
expect(result.layout).toBe('auto');
expect(result.sections).toBeUndefined();
});
it('should accept custom layout with sections', () => {
const details = { columns: '3' as const, layout: 'custom' as const, sections: ['sec-1', 'sec-2'] };
expect(() => RecordDetailsProps.parse(details)).not.toThrow();
});
it('should reject invalid column value', () => {
expect(() => RecordDetailsProps.parse({ columns: '5' })).toThrow();
});
});
describe('RecordRelatedListProps', () => {
it('should accept valid related list', () => {
const props = {
objectName: 'contact',
relationshipField: 'account_id',
columns: ['name', 'email'],
};
const result = RecordRelatedListProps.parse(props);
expect(result.limit).toBe(5);
expect(result.sort).toBeUndefined();
});
it('should accept full related list with optional fields', () => {
const props = {
objectName: 'opportunity',
relationshipField: 'account_id',
columns: ['name', 'amount'],
sort: 'created_at',
limit: 10,
};
expect(() => RecordRelatedListProps.parse(props)).not.toThrow();
});
it('should reject without required fields', () => {
expect(() => RecordRelatedListProps.parse({})).toThrow();
expect(() => RecordRelatedListProps.parse({ objectName: 'x' })).toThrow();
});
});
describe('RecordHighlightsProps', () => {
it('should accept valid highlights', () => {
const props = { fields: ['name', 'status', 'amount'] };
const result = RecordHighlightsProps.parse(props);
expect(result.fields).toHaveLength(3);
});
it('should reject empty fields array (min 1)', () => {
expect(() => RecordHighlightsProps.parse({ fields: [] })).toThrow();
});
it('should reject more than 7 fields', () => {
expect(() => RecordHighlightsProps.parse({ fields: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] })).toThrow();
});
it('should reject missing fields', () => {
expect(() => RecordHighlightsProps.parse({})).toThrow();
});
});
describe('ComponentPropsMap', () => {
it('should contain structure components', () => {
expect(ComponentPropsMap['page:header']).toBeDefined();
expect(ComponentPropsMap['page:tabs']).toBeDefined();
expect(ComponentPropsMap['page:card']).toBeDefined();
expect(ComponentPropsMap['page:footer']).toBeDefined();
expect(ComponentPropsMap['page:sidebar']).toBeDefined();
expect(ComponentPropsMap['page:accordion']).toBeDefined();
expect(ComponentPropsMap['page:section']).toBeDefined();
});
it('should contain record components', () => {
expect(ComponentPropsMap['record:details']).toBeDefined();
expect(ComponentPropsMap['record:related_list']).toBeDefined();
expect(ComponentPropsMap['record:highlights']).toBeDefined();
expect(ComponentPropsMap['record:activity']).toBeDefined();
expect(ComponentPropsMap['record:chatter']).toBeDefined();
expect(ComponentPropsMap['record:path']).toBeDefined();
});
it('should contain AI components', () => {
expect(ComponentPropsMap['ai:chat_window']).toBeDefined();
expect(ComponentPropsMap['ai:suggestion']).toBeDefined();
});
it('should parse ai:chat_window with default', () => {
const result = ComponentPropsMap['ai:chat_window'].parse({});
expect(result.mode).toBe('float');
});
it('should parse ai:suggestion with optional context', () => {
const result = ComponentPropsMap['ai:suggestion'].parse({});
expect(result.context).toBeUndefined();
});
it('should parse empty props schemas for utility components', () => {
expect(() => ComponentPropsMap['page:footer'].parse({})).not.toThrow();
expect(() => ComponentPropsMap['global:search'].parse({})).not.toThrow();
expect(() => ComponentPropsMap['user:profile'].parse({})).not.toThrow();
});
});
// ---------------------------------------------------------------------------
// Content Elements in PageComponentType
// ---------------------------------------------------------------------------
describe('Content Elements', () => {
it('should accept element:text component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:text',
properties: { content: 'Hello World' },
})).not.toThrow();
});
it('should accept element:number component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:number',
properties: { object: 'order', aggregate: 'count' },
})).not.toThrow();
});
it('should accept element:image component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:image',
properties: { src: '/images/banner.jpg' },
})).not.toThrow();
});
it('should accept element:divider component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:divider',
properties: {},
})).not.toThrow();
});
});
// ---------------------------------------------------------------------------
// Element Props Schemas
// ---------------------------------------------------------------------------
describe('ElementTextPropsSchema', () => {
it('should accept minimal text props', () => {
const props = ElementTextPropsSchema.parse({ content: 'Hello' });
expect(props.content).toBe('Hello');
expect(props.variant).toBe('body');
expect(props.align).toBe('left');
});
it('should accept full text props', () => {
const props = ElementTextPropsSchema.parse({
content: '# Welcome',
variant: 'heading',
align: 'center',
});
expect(props.variant).toBe('heading');
expect(props.align).toBe('center');
});
it('should accept all variants', () => {
const variants = ['heading', 'subheading', 'body', 'caption'] as const;
variants.forEach(variant => {
expect(() => ElementTextPropsSchema.parse({ content: 'Test', variant })).not.toThrow();
});
});
it('should reject without content', () => {
expect(() => ElementTextPropsSchema.parse({})).toThrow();
});
});
describe('ElementNumberPropsSchema', () => {
it('should accept minimal number props', () => {
const props = ElementNumberPropsSchema.parse({
object: 'order',
aggregate: 'count',
});
expect(props.object).toBe('order');
expect(props.aggregate).toBe('count');
expect(props.field).toBeUndefined();
});
it('should accept full number props', () => {
const props = ElementNumberPropsSchema.parse({
object: 'order',
field: 'amount',
aggregate: 'sum',
filter: { status: 'paid' },
format: 'currency',
prefix: '$',
suffix: ' USD',
});
expect(props.format).toBe('currency');
expect(props.prefix).toBe('$');
expect(props.suffix).toBe(' USD');
});
it('should accept all aggregate functions', () => {
const aggregates = ['count', 'sum', 'avg', 'min', 'max'] as const;
aggregates.forEach(aggregate => {
expect(() => ElementNumberPropsSchema.parse({ object: 'order', aggregate })).not.toThrow();
});
});
it('should accept all format options', () => {
const formats = ['number', 'currency', 'percent'] as const;
formats.forEach(format => {
expect(() => ElementNumberPropsSchema.parse({ object: 'order', aggregate: 'count', format })).not.toThrow();
});
});
it('should reject without required fields', () => {
expect(() => ElementNumberPropsSchema.parse({})).toThrow();
expect(() => ElementNumberPropsSchema.parse({ object: 'order' })).toThrow();
});
});
describe('ElementImagePropsSchema', () => {
it('should accept minimal image props', () => {
const props = ElementImagePropsSchema.parse({ src: '/images/hero.jpg' });
expect(props.src).toBe('/images/hero.jpg');
expect(props.fit).toBe('cover');
});
it('should accept full image props', () => {
const props = ElementImagePropsSchema.parse({
src: '/images/banner.png',
alt: 'Company banner',
fit: 'contain',
height: 200,
});
expect(props.alt).toBe('Company banner');
expect(props.fit).toBe('contain');
expect(props.height).toBe(200);
});
it('should accept all fit modes', () => {
const fits = ['cover', 'contain', 'fill'] as const;
fits.forEach(fit => {
expect(() => ElementImagePropsSchema.parse({ src: '/img.png', fit })).not.toThrow();
});
});
it('should reject without src', () => {
expect(() => ElementImagePropsSchema.parse({})).toThrow();
});
});
// ---------------------------------------------------------------------------
// ComponentPropsMap content elements
// ---------------------------------------------------------------------------
describe('ComponentPropsMap content elements', () => {
it('should contain element:text', () => {
expect(ComponentPropsMap['element:text']).toBeDefined();
});
it('should contain element:number', () => {
expect(ComponentPropsMap['element:number']).toBeDefined();
});
it('should contain element:image', () => {
expect(ComponentPropsMap['element:image']).toBeDefined();
});
it('should contain element:divider', () => {
expect(ComponentPropsMap['element:divider']).toBeDefined();
});
it('should parse element:text props', () => {
const result = ComponentPropsMap['element:text'].parse({ content: 'Hello' });
expect(result.content).toBe('Hello');
});
it('should parse element:number props', () => {
const result = ComponentPropsMap['element:number'].parse({
object: 'order',
aggregate: 'count',
});
expect(result.object).toBe('order');
});
it('should parse element:image props', () => {
const result = ComponentPropsMap['element:image'].parse({ src: '/img.png' });
expect(result.src).toBe('/img.png');
});
it('should parse element:divider (empty props)', () => {
expect(() => ComponentPropsMap['element:divider'].parse({})).not.toThrow();
});
});
// ---------------------------------------------------------------------------
// Interactive Elements — element:button
// ---------------------------------------------------------------------------
describe('Interactive Elements — element:button', () => {
it('should accept element:button component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:button',
properties: { label: 'Submit' },
})).not.toThrow();
});
it('should parse element:button props with defaults', () => {
const props = ElementButtonPropsSchema.parse({ label: 'Save' });
expect(props.label).toBe('Save');
expect(props.variant).toBe('primary');
expect(props.size).toBe('medium');
expect(props.iconPosition).toBe('left');
expect(props.disabled).toBe(false);
});
it('should accept full button props', () => {
const props = ElementButtonPropsSchema.parse({
label: 'Delete',
variant: 'danger',
size: 'large',
icon: 'trash',
iconPosition: 'right',
disabled: true,
});
expect(props.variant).toBe('danger');
expect(props.icon).toBe('trash');
expect(props.disabled).toBe(true);
});
it('should accept all button variants', () => {
const variants = ['primary', 'secondary', 'danger', 'ghost', 'link'] as const;
variants.forEach(variant => {
expect(() => ElementButtonPropsSchema.parse({ label: 'Btn', variant })).not.toThrow();
});
});
it('should reject button without label', () => {
expect(() => ElementButtonPropsSchema.parse({})).toThrow();
});
});
// ---------------------------------------------------------------------------
// Interactive Elements — element:filter
// ---------------------------------------------------------------------------
describe('Interactive Elements — element:filter', () => {
it('should accept element:filter component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:filter',
properties: { object: 'order', fields: ['status'] },
})).not.toThrow();
});
it('should parse filter props with defaults', () => {
const props = ElementFilterPropsSchema.parse({
object: 'order',
fields: ['status', 'priority'],
});
expect(props.object).toBe('order');
expect(props.layout).toBe('inline');
expect(props.showSearch).toBe(true);
});
it('should accept filter with targetVariable', () => {
const props = ElementFilterPropsSchema.parse({
object: 'task',
fields: ['status'],
targetVariable: 'active_filter',
layout: 'sidebar',
});
expect(props.targetVariable).toBe('active_filter');
expect(props.layout).toBe('sidebar');
});
it('should reject filter without required fields', () => {
expect(() => ElementFilterPropsSchema.parse({})).toThrow();
expect(() => ElementFilterPropsSchema.parse({ object: 'order' })).toThrow();
});
});
// ---------------------------------------------------------------------------
// Interactive Elements — element:form
// ---------------------------------------------------------------------------
describe('Interactive Elements — element:form', () => {
it('should accept element:form component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:form',
properties: { object: 'contact' },
})).not.toThrow();
});
it('should parse form props with defaults', () => {
const props = ElementFormPropsSchema.parse({ object: 'contact' });
expect(props.object).toBe('contact');
expect(props.mode).toBe('create');
});
it('should accept full form props', () => {
const props = ElementFormPropsSchema.parse({
object: 'contact',
fields: ['name', 'email', 'phone'],
mode: 'edit',
submitLabel: 'Update Contact',
onSubmit: 'navigate_to("page_detail")',
});
expect(props.mode).toBe('edit');
expect(props.fields).toHaveLength(3);
expect(props.submitLabel).toBe('Update Contact');
});
it('should reject form without object', () => {
expect(() => ElementFormPropsSchema.parse({})).toThrow();
});
});
// ---------------------------------------------------------------------------
// Interactive Elements — element:record_picker
// ---------------------------------------------------------------------------
describe('Interactive Elements — element:record_picker', () => {
it('should accept element:record_picker component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:record_picker',
properties: { object: 'account', displayField: 'name' },
})).not.toThrow();
});
it('should parse record_picker props with defaults', () => {
const props = ElementRecordPickerPropsSchema.parse({
object: 'account',
displayField: 'name',
});
expect(props.object).toBe('account');
expect(props.displayField).toBe('name');
expect(props.multiple).toBe(false);
});
it('should accept full record_picker props', () => {
const props = ElementRecordPickerPropsSchema.parse({
object: 'account',
displayField: 'name',
searchFields: ['name', 'email'],
filter: { status: 'active' },
multiple: true,
targetVariable: 'selected_account',
placeholder: 'Search accounts...',
});
expect(props.multiple).toBe(true);
expect(props.targetVariable).toBe('selected_account');
expect(props.searchFields).toEqual(['name', 'email']);
});
it('should reject record_picker without required fields', () => {
expect(() => ElementRecordPickerPropsSchema.parse({})).toThrow();
expect(() => ElementRecordPickerPropsSchema.parse({ object: 'account' })).toThrow();
});
});
// ---------------------------------------------------------------------------
// Interactive Elements — element:text_input
// ---------------------------------------------------------------------------
describe('Interactive Elements — element:text_input', () => {
it('should accept element:text_input component', () => {
expect(() => PageComponentSchema.parse({
type: 'element:text_input',
properties: { label: 'Workspace name' },
})).not.toThrow();
});
it('should parse text_input props with defaults', () => {
const props = ElementTextInputPropsSchema.parse({});
expect(props.inputType).toBe('text');
expect(props.required).toBe(false);
expect(props.disabled).toBe(false);
});
it('should accept full text_input props', () => {
const props = ElementTextInputPropsSchema.parse({
inputType: 'email',
label: 'Email',
placeholder: 'you@example.com',
defaultValue: 'a@b.com',
required: true,
disabled: false,
description: 'We never share it',
targetVariable: 'email',
});
expect(props.inputType).toBe('email');
expect(props.required).toBe(true);
expect(props.targetVariable).toBe('email');
});
it('should accept all input types', () => {
const types = ['text', 'email', 'number', 'tel', 'url', 'password'] as const;
types.forEach(inputType => {
expect(() => ElementTextInputPropsSchema.parse({ inputType })).not.toThrow();
});
});
it('should accept a numeric defaultValue', () => {
const props = ElementTextInputPropsSchema.parse({ inputType: 'number', defaultValue: 42 });
expect(props.defaultValue).toBe(42);
});
it('should reject an unknown input type', () => {
expect(() => ElementTextInputPropsSchema.parse({ inputType: 'color' })).toThrow();
});
});
// ---------------------------------------------------------------------------
// ComponentPropsMap — interactive elements
// ---------------------------------------------------------------------------
describe('ComponentPropsMap interactive elements', () => {
it('should contain element:button', () => {
expect(ComponentPropsMap['element:button']).toBeDefined();
});
it('should contain element:filter', () => {
expect(ComponentPropsMap['element:filter']).toBeDefined();
});
it('should contain element:form', () => {
expect(ComponentPropsMap['element:form']).toBeDefined();
});
it('should contain element:record_picker', () => {
expect(ComponentPropsMap['element:record_picker']).toBeDefined();
});
it('should contain element:text_input', () => {
expect(ComponentPropsMap['element:text_input']).toBeDefined();
});
it('should parse element:button props', () => {
const result = ComponentPropsMap['element:button'].parse({ label: 'Click Me' });
expect(result.label).toBe('Click Me');
});
it('should parse element:filter props', () => {
const result = ComponentPropsMap['element:filter'].parse({
object: 'order',
fields: ['status'],
});
expect(result.object).toBe('order');
});
it('should parse element:form props', () => {
const result = ComponentPropsMap['element:form'].parse({ object: 'contact' });
expect(result.object).toBe('contact');
});
it('should parse element:record_picker props', () => {
const result = ComponentPropsMap['element:record_picker'].parse({
object: 'account',
displayField: 'name',
});
expect(result.object).toBe('account');
});
it('should parse element:text_input props', () => {
const result = ComponentPropsMap['element:text_input'].parse({ label: 'Name' });
expect(result.inputType).toBe('text');
});
});
// ---------------------------------------------------------------------------
// Enhanced RecordActivityProps (Unified Timeline)
// ---------------------------------------------------------------------------
describe('RecordActivityProps (enhanced)', () => {
it('should accept empty with defaults', () => {
const result = RecordActivityProps.parse({});
expect(result.filterMode).toBe('all');
expect(result.showFilterToggle).toBe(true);
expect(result.limit).toBe(20);
expect(result.showCompleted).toBe(false);
expect(result.unifiedTimeline).toBe(true);
expect(result.showCommentInput).toBe(true);
expect(result.enableMentions).toBe(true);
expect(result.enableReactions).toBe(false);
expect(result.enableThreading).toBe(false);
expect(result.showSubscriptionToggle).toBe(true);
});
it('should accept unified feed item types including comment and field_change', () => {
const result = RecordActivityProps.parse({
types: ['comment', 'field_change', 'task', 'email'],
});
expect(result.types).toEqual(['comment', 'field_change', 'task', 'email']);
});
it('should accept custom filter mode', () => {
const result = RecordActivityProps.parse({ filterMode: 'comments_only' });
expect(result.filterMode).toBe('comments_only');
});
it('should accept all filter modes', () => {
const modes = ['all', 'comments_only', 'changes_only', 'tasks_only'] as const;
modes.forEach(mode => {
expect(() => RecordActivityProps.parse({ filterMode: mode })).not.toThrow();
});
});
it('should accept full configuration', () => {
const result = RecordActivityProps.parse({
types: ['comment', 'field_change'],
filterMode: 'all',
showFilterToggle: true,
limit: 50,
showCompleted: true,
unifiedTimeline: true,
showCommentInput: true,
enableMentions: true,
enableReactions: true,
enableThreading: true,
showSubscriptionToggle: false,
});
expect(result.enableReactions).toBe(true);
expect(result.enableThreading).toBe(true);
expect(result.showSubscriptionToggle).toBe(false);
expect(result.limit).toBe(50);
});
it('should reject invalid feed item type', () => {
expect(() => RecordActivityProps.parse({ types: ['invalid_type'] })).toThrow();
});
});
// ---------------------------------------------------------------------------
// RecordChatterProps (replaces EmptyProps)
// ---------------------------------------------------------------------------
describe('RecordChatterProps', () => {
it('should accept empty with defaults', () => {
const result = RecordChatterProps.parse({});
expect(result.position).toBe('sidebar');
expect(result.collapsible).toBe(true);
expect(result.defaultCollapsed).toBe(false);
expect(result.width).toBeUndefined();
expect(result.feed).toBeUndefined();
});
it('should accept sidebar position with width', () => {
const result = RecordChatterProps.parse({
position: 'sidebar',
width: '350px',
});
expect(result.position).toBe('sidebar');
expect(result.width).toBe('350px');
});
it('should accept numeric width', () => {
const result = RecordChatterProps.parse({ width: 400 });
expect(result.width).toBe(400);
});
it('should accept all position modes', () => {
const positions = ['sidebar', 'inline', 'drawer'] as const;
positions.forEach(position => {
expect(() => RecordChatterProps.parse({ position })).not.toThrow();
});
});
it('should accept collapsed state', () => {
const result = RecordChatterProps.parse({
collapsible: true,
defaultCollapsed: true,
});
expect(result.defaultCollapsed).toBe(true);
});
it('should accept embedded feed configuration', () => {
const result = RecordChatterProps.parse({
position: 'sidebar',
width: '30%',
feed: {
types: ['comment', 'field_change'],
filterMode: 'all',
limit: 30,
enableMentions: true,
enableReactions: true,
},
});
expect(result.feed).toBeDefined();
expect(result.feed!.types).toEqual(['comment', 'field_change']);
expect(result.feed!.limit).toBe(30);
expect(result.feed!.enableReactions).toBe(true);
});
it('should reject invalid position', () => {
expect(() => RecordChatterProps.parse({ position: 'modal' })).toThrow();
});
});
// ---------------------------------------------------------------------------
// ComponentPropsMap — record:chatter is no longer empty
// ---------------------------------------------------------------------------
describe('ComponentPropsMap record:chatter', () => {
it('should parse record:chatter with defaults', () => {
const result = ComponentPropsMap['record:chatter'].parse({});
expect(result.position).toBe('sidebar');
expect(result.collapsible).toBe(true);
});
it('should parse record:chatter with feed config', () => {
const result = ComponentPropsMap['record:chatter'].parse({
position: 'drawer',
feed: { filterMode: 'comments_only' },
});
expect(result.position).toBe('drawer');
expect(result.feed!.filterMode).toBe('comments_only');
});
it('should parse record:activity with unified types', () => {
const result = ComponentPropsMap['record:activity'].parse({
types: ['comment', 'field_change', 'task'],
unifiedTimeline: true,
});
expect(result.types).toEqual(['comment', 'field_change', 'task']);
expect(result.unifiedTimeline).toBe(true);
});
});