@squiz/dx-page-contents-lib 1.82.1 → 1.83.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.
@@ -0,0 +1,804 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dxp_page_content_types_1 = require("@squiz/dxp-page-content-types");
4
+ const normalizeLayoutData_1 = require("./normalizeLayoutData");
5
+ describe('normalizeLayoutData', () => {
6
+ describe('zonesObjectToArray', () => {
7
+ it('should convert object format to array format', () => {
8
+ const zones = {
9
+ header: {
10
+ displayName: 'Header Zone',
11
+ description: 'Content for the header',
12
+ },
13
+ main: {
14
+ displayName: 'Main Zone',
15
+ description: 'Main content area',
16
+ },
17
+ };
18
+ const result = (0, normalizeLayoutData_1.zonesObjectToArray)(zones);
19
+ expect(result).toEqual([
20
+ {
21
+ key: 'header',
22
+ displayName: 'Header Zone',
23
+ description: 'Content for the header',
24
+ },
25
+ {
26
+ key: 'main',
27
+ displayName: 'Main Zone',
28
+ description: 'Main content area',
29
+ },
30
+ ]);
31
+ });
32
+ it('should handle single zone object', () => {
33
+ const zones = {
34
+ content: {
35
+ displayName: 'Content Zone',
36
+ description: 'Main content',
37
+ },
38
+ };
39
+ const result = (0, normalizeLayoutData_1.zonesObjectToArray)(zones);
40
+ expect(result).toEqual([
41
+ {
42
+ key: 'content',
43
+ displayName: 'Content Zone',
44
+ description: 'Main content',
45
+ },
46
+ ]);
47
+ });
48
+ it('should handle empty object', () => {
49
+ const zones = {};
50
+ const result = (0, normalizeLayoutData_1.zonesObjectToArray)(zones);
51
+ expect(result).toEqual([]);
52
+ });
53
+ it('should preserve all zone properties', () => {
54
+ const zones = {
55
+ sidebar: {
56
+ displayName: 'Sidebar',
57
+ description: 'Sidebar content',
58
+ },
59
+ };
60
+ const result = (0, normalizeLayoutData_1.zonesObjectToArray)(zones);
61
+ expect(result[0]).toHaveProperty('key', 'sidebar');
62
+ expect(result[0]).toHaveProperty('displayName', 'Sidebar');
63
+ expect(result[0]).toHaveProperty('description', 'Sidebar content');
64
+ });
65
+ it('should maintain object key order', () => {
66
+ const zones = {
67
+ first: {
68
+ displayName: 'First',
69
+ description: 'First zone',
70
+ },
71
+ second: {
72
+ displayName: 'Second',
73
+ description: 'Second zone',
74
+ },
75
+ third: {
76
+ displayName: 'Third',
77
+ description: 'Third zone',
78
+ },
79
+ };
80
+ const result = (0, normalizeLayoutData_1.zonesObjectToArray)(zones);
81
+ expect(result[0].key).toBe('first');
82
+ expect(result[1].key).toBe('second');
83
+ expect(result[2].key).toBe('third');
84
+ });
85
+ });
86
+ describe('zonesArrayToObject', () => {
87
+ it('should convert array format to object format', () => {
88
+ const zones = [
89
+ {
90
+ key: 'header',
91
+ displayName: 'Header Zone',
92
+ description: 'Content for the header',
93
+ },
94
+ {
95
+ key: 'main',
96
+ displayName: 'Main Zone',
97
+ description: 'Main content area',
98
+ },
99
+ ];
100
+ const result = (0, normalizeLayoutData_1.zonesArrayToObject)(zones);
101
+ expect(result).toEqual({
102
+ header: {
103
+ displayName: 'Header Zone',
104
+ description: 'Content for the header',
105
+ },
106
+ main: {
107
+ displayName: 'Main Zone',
108
+ description: 'Main content area',
109
+ },
110
+ });
111
+ });
112
+ it('should handle single zone array', () => {
113
+ const zones = [
114
+ {
115
+ key: 'content',
116
+ displayName: 'Content Zone',
117
+ description: 'Main content',
118
+ },
119
+ ];
120
+ const result = (0, normalizeLayoutData_1.zonesArrayToObject)(zones);
121
+ expect(result).toEqual({
122
+ content: {
123
+ displayName: 'Content Zone',
124
+ description: 'Main content',
125
+ },
126
+ });
127
+ });
128
+ it('should handle empty array', () => {
129
+ const zones = [];
130
+ const result = (0, normalizeLayoutData_1.zonesArrayToObject)(zones);
131
+ expect(result).toEqual({});
132
+ });
133
+ it('should remove key property from zone config', () => {
134
+ const zones = [
135
+ {
136
+ key: 'sidebar',
137
+ displayName: 'Sidebar',
138
+ description: 'Sidebar content',
139
+ },
140
+ ];
141
+ const result = (0, normalizeLayoutData_1.zonesArrayToObject)(zones);
142
+ expect(result.sidebar).not.toHaveProperty('key');
143
+ expect(result.sidebar).toHaveProperty('displayName', 'Sidebar');
144
+ expect(result.sidebar).toHaveProperty('description', 'Sidebar content');
145
+ });
146
+ it('should preserve all zone properties except key', () => {
147
+ const zones = [
148
+ {
149
+ key: 'footer',
150
+ displayName: 'Footer Zone',
151
+ description: 'Footer content area',
152
+ },
153
+ ];
154
+ const result = (0, normalizeLayoutData_1.zonesArrayToObject)(zones);
155
+ expect(result.footer).toEqual({
156
+ displayName: 'Footer Zone',
157
+ description: 'Footer content area',
158
+ });
159
+ });
160
+ });
161
+ describe('normalizeZonesToArray', () => {
162
+ it('should return array format when input is already an array', () => {
163
+ const zones = [
164
+ {
165
+ key: 'header',
166
+ displayName: 'Header',
167
+ description: 'Header zone',
168
+ },
169
+ ];
170
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
171
+ expect(result).toEqual(zones);
172
+ expect(Array.isArray(result)).toBe(true);
173
+ });
174
+ it('should convert object format to array format', () => {
175
+ const zones = {
176
+ header: {
177
+ displayName: 'Header',
178
+ description: 'Header zone',
179
+ },
180
+ };
181
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
182
+ expect(result).toEqual([
183
+ {
184
+ key: 'header',
185
+ displayName: 'Header',
186
+ description: 'Header zone',
187
+ },
188
+ ]);
189
+ });
190
+ it('should return undefined when input is undefined', () => {
191
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(undefined);
192
+ expect(result).toBeUndefined();
193
+ });
194
+ it('should return undefined when input is null', () => {
195
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(null);
196
+ expect(result).toBeUndefined();
197
+ });
198
+ it('should handle empty array', () => {
199
+ const zones = [];
200
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
201
+ expect(result).toEqual([]);
202
+ });
203
+ it('should handle empty object', () => {
204
+ const zones = {};
205
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
206
+ expect(result).toEqual([]);
207
+ });
208
+ it('should handle multiple zones in array format', () => {
209
+ const zones = [
210
+ {
211
+ key: 'header',
212
+ displayName: 'Header',
213
+ description: 'Header zone',
214
+ },
215
+ {
216
+ key: 'main',
217
+ displayName: 'Main',
218
+ description: 'Main zone',
219
+ },
220
+ ];
221
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
222
+ expect(result).toEqual(zones);
223
+ });
224
+ it('should handle multiple zones in object format', () => {
225
+ const zones = {
226
+ header: {
227
+ displayName: 'Header',
228
+ description: 'Header zone',
229
+ },
230
+ main: {
231
+ displayName: 'Main',
232
+ description: 'Main zone',
233
+ },
234
+ };
235
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
236
+ expect(result).toEqual([
237
+ {
238
+ key: 'header',
239
+ displayName: 'Header',
240
+ description: 'Header zone',
241
+ },
242
+ {
243
+ key: 'main',
244
+ displayName: 'Main',
245
+ description: 'Main zone',
246
+ },
247
+ ]);
248
+ });
249
+ it('should return undefined when input is not an object (edge case)', () => {
250
+ const zones = 'not-an-object';
251
+ const result = (0, normalizeLayoutData_1.normalizeZonesToArray)(zones);
252
+ expect(result).toBeUndefined();
253
+ });
254
+ });
255
+ describe('normalizeZonesToObject', () => {
256
+ it('should return object format when input is already an object', () => {
257
+ const zones = {
258
+ header: {
259
+ displayName: 'Header',
260
+ description: 'Header zone',
261
+ },
262
+ };
263
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
264
+ expect(result).toEqual(zones);
265
+ expect(typeof result).toBe('object');
266
+ expect(Array.isArray(result)).toBe(false);
267
+ });
268
+ it('should convert array format to object format', () => {
269
+ const zones = [
270
+ {
271
+ key: 'header',
272
+ displayName: 'Header',
273
+ description: 'Header zone',
274
+ },
275
+ ];
276
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
277
+ expect(result).toEqual({
278
+ header: {
279
+ displayName: 'Header',
280
+ description: 'Header zone',
281
+ },
282
+ });
283
+ });
284
+ it('should return undefined when input is undefined', () => {
285
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(undefined);
286
+ expect(result).toBeUndefined();
287
+ });
288
+ it('should return undefined when input is null', () => {
289
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(null);
290
+ expect(result).toBeUndefined();
291
+ });
292
+ it('should handle empty array', () => {
293
+ const zones = [];
294
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
295
+ expect(result).toEqual({});
296
+ });
297
+ it('should handle empty object', () => {
298
+ const zones = {};
299
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
300
+ expect(result).toEqual({});
301
+ });
302
+ it('should handle multiple zones in array format', () => {
303
+ const zones = [
304
+ {
305
+ key: 'header',
306
+ displayName: 'Header',
307
+ description: 'Header zone',
308
+ },
309
+ {
310
+ key: 'main',
311
+ displayName: 'Main',
312
+ description: 'Main zone',
313
+ },
314
+ ];
315
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
316
+ expect(result).toEqual({
317
+ header: {
318
+ displayName: 'Header',
319
+ description: 'Header zone',
320
+ },
321
+ main: {
322
+ displayName: 'Main',
323
+ description: 'Main zone',
324
+ },
325
+ });
326
+ });
327
+ it('should handle multiple zones in object format', () => {
328
+ const zones = {
329
+ header: {
330
+ displayName: 'Header',
331
+ description: 'Header zone',
332
+ },
333
+ main: {
334
+ displayName: 'Main',
335
+ description: 'Main zone',
336
+ },
337
+ };
338
+ const result = (0, normalizeLayoutData_1.normalizeZonesToObject)(zones);
339
+ expect(result).toEqual(zones);
340
+ });
341
+ });
342
+ describe('round-trip conversions', () => {
343
+ it('should convert object to array and back to object', () => {
344
+ const original = {
345
+ header: {
346
+ displayName: 'Header',
347
+ description: 'Header zone',
348
+ },
349
+ main: {
350
+ displayName: 'Main',
351
+ description: 'Main zone',
352
+ },
353
+ };
354
+ const array = (0, normalizeLayoutData_1.zonesObjectToArray)(original);
355
+ const backToObject = (0, normalizeLayoutData_1.zonesArrayToObject)(array);
356
+ expect(backToObject).toEqual(original);
357
+ });
358
+ it('should convert array to object and back to array', () => {
359
+ const original = [
360
+ {
361
+ key: 'header',
362
+ displayName: 'Header',
363
+ description: 'Header zone',
364
+ },
365
+ {
366
+ key: 'main',
367
+ displayName: 'Main',
368
+ description: 'Main zone',
369
+ },
370
+ ];
371
+ const object = (0, normalizeLayoutData_1.zonesArrayToObject)(original);
372
+ const backToArray = (0, normalizeLayoutData_1.zonesObjectToArray)(object);
373
+ expect(backToArray).toEqual(original);
374
+ });
375
+ it('should handle normalizeZonesToArray and normalizeZonesToObject round-trip', () => {
376
+ const original = {
377
+ sidebar: {
378
+ displayName: 'Sidebar',
379
+ description: 'Sidebar content',
380
+ },
381
+ };
382
+ const normalized = (0, normalizeLayoutData_1.normalizeZonesToArray)(original);
383
+ const backToObject = (0, normalizeLayoutData_1.normalizeZonesToObject)(normalized);
384
+ expect(backToObject).toEqual(original);
385
+ });
386
+ });
387
+ describe('normalizeLayoutProperties', () => {
388
+ it('should return undefined when options is undefined', () => {
389
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(undefined);
390
+ expect(result).toBeUndefined();
391
+ });
392
+ it('should return undefined when options is null', () => {
393
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(null);
394
+ expect(result).toBeUndefined();
395
+ });
396
+ it('should convert boolean option correctly', () => {
397
+ const options = {
398
+ showHeader: {
399
+ displayName: 'Show Header',
400
+ description: 'Whether to show the header',
401
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.boolean,
402
+ selectedValue: true,
403
+ },
404
+ };
405
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
406
+ expect(result).toEqual({
407
+ showHeader: {
408
+ type: 'boolean',
409
+ title: 'Show Header',
410
+ description: 'Whether to show the header',
411
+ selectedValue: true,
412
+ },
413
+ });
414
+ });
415
+ it('should convert text option correctly', () => {
416
+ const options = {
417
+ title: {
418
+ displayName: 'Title',
419
+ description: 'Page title',
420
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.text,
421
+ selectedValue: 'My Page',
422
+ },
423
+ };
424
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
425
+ expect(result).toEqual({
426
+ title: {
427
+ type: 'string',
428
+ title: 'Title',
429
+ description: 'Page title',
430
+ selectedValue: 'My Page',
431
+ },
432
+ });
433
+ });
434
+ it('should convert string-enum option correctly with values', () => {
435
+ const options = {
436
+ theme: {
437
+ displayName: 'Theme',
438
+ description: 'Color theme',
439
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.stringEnum,
440
+ values: ['light', 'dark'],
441
+ selectedValue: 'dark',
442
+ },
443
+ };
444
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
445
+ expect(result).toEqual({
446
+ theme: {
447
+ type: 'string',
448
+ title: 'Theme',
449
+ description: 'Color theme',
450
+ enum: ['light', 'dark'],
451
+ selectedValue: 'dark',
452
+ },
453
+ });
454
+ });
455
+ it('should not include selectedValue when undefined', () => {
456
+ const options = {
457
+ showHeader: {
458
+ displayName: 'Show Header',
459
+ description: 'Whether to show the header',
460
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.boolean,
461
+ },
462
+ };
463
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
464
+ expect(result).toEqual({
465
+ showHeader: {
466
+ type: 'boolean',
467
+ title: 'Show Header',
468
+ description: 'Whether to show the header',
469
+ },
470
+ });
471
+ expect(result === null || result === void 0 ? void 0 : result.showHeader).not.toHaveProperty('selectedValue');
472
+ });
473
+ it('should not include enum when values is undefined', () => {
474
+ const options = {
475
+ theme: {
476
+ displayName: 'Theme',
477
+ description: 'Color theme',
478
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.text,
479
+ },
480
+ };
481
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
482
+ expect(result).toEqual({
483
+ theme: {
484
+ type: 'string',
485
+ title: 'Theme',
486
+ description: 'Color theme',
487
+ },
488
+ });
489
+ expect(result === null || result === void 0 ? void 0 : result.theme).not.toHaveProperty('enum');
490
+ });
491
+ it('should handle multiple options', () => {
492
+ const options = {
493
+ showHeader: {
494
+ displayName: 'Show Header',
495
+ description: 'Whether to show the header',
496
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.boolean,
497
+ selectedValue: true,
498
+ },
499
+ title: {
500
+ displayName: 'Title',
501
+ description: 'Page title',
502
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.text,
503
+ selectedValue: 'My Page',
504
+ },
505
+ theme: {
506
+ displayName: 'Theme',
507
+ description: 'Color theme',
508
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.stringEnum,
509
+ values: ['light', 'dark'],
510
+ selectedValue: 'dark',
511
+ },
512
+ };
513
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
514
+ expect(result).toEqual({
515
+ showHeader: {
516
+ type: 'boolean',
517
+ title: 'Show Header',
518
+ description: 'Whether to show the header',
519
+ selectedValue: true,
520
+ },
521
+ title: {
522
+ type: 'string',
523
+ title: 'Title',
524
+ description: 'Page title',
525
+ selectedValue: 'My Page',
526
+ },
527
+ theme: {
528
+ type: 'string',
529
+ title: 'Theme',
530
+ description: 'Color theme',
531
+ enum: ['light', 'dark'],
532
+ selectedValue: 'dark',
533
+ },
534
+ });
535
+ });
536
+ it('should handle empty options object', () => {
537
+ const options = {};
538
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
539
+ expect(result).toEqual({});
540
+ });
541
+ it('should handle option without valueType (defaults to string)', () => {
542
+ // Testing edge case where valueType might be missing (backwards compatibility)
543
+ const options = {
544
+ title: {
545
+ displayName: 'Title',
546
+ description: 'Page title',
547
+ selectedValue: 'My Page',
548
+ // valueType is missing - this is an edge case for backwards compatibility
549
+ },
550
+ };
551
+ const result = (0, normalizeLayoutData_1.normalizeLayoutProperties)(options);
552
+ expect(result).toEqual({
553
+ title: {
554
+ type: 'string',
555
+ title: 'Title',
556
+ description: 'Page title',
557
+ selectedValue: 'My Page',
558
+ },
559
+ });
560
+ });
561
+ });
562
+ describe('normalizeLayoutNode', () => {
563
+ it('should return node unchanged if not a layout node', () => {
564
+ const node = {
565
+ type: 'component',
566
+ componentId: 'test',
567
+ };
568
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
569
+ expect(result).toEqual(node);
570
+ });
571
+ it('should return node unchanged if node is null', () => {
572
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(null);
573
+ expect(result).toBeNull();
574
+ });
575
+ it('should return node unchanged if node is undefined', () => {
576
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(undefined);
577
+ expect(result).toBeUndefined();
578
+ });
579
+ it('should return node unchanged if layout has properties already', () => {
580
+ const node = {
581
+ type: 'layout',
582
+ layout: {
583
+ name: 'test-layout',
584
+ properties: {
585
+ showHeader: {
586
+ type: 'boolean',
587
+ title: 'Show Header',
588
+ description: 'Whether to show the header',
589
+ },
590
+ },
591
+ },
592
+ content: {},
593
+ };
594
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
595
+ expect(result).toEqual(node);
596
+ });
597
+ it('should convert options to properties for minimal layout (no displayName)', () => {
598
+ const node = {
599
+ type: 'layout',
600
+ layout: {
601
+ name: 'test-layout',
602
+ options: {
603
+ showHeader: {
604
+ selectedValue: true,
605
+ },
606
+ title: {
607
+ selectedValue: 'My Page',
608
+ },
609
+ },
610
+ },
611
+ content: {
612
+ main: [],
613
+ },
614
+ };
615
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
616
+ expect(result).toEqual({
617
+ type: 'layout',
618
+ layout: {
619
+ name: 'test-layout',
620
+ properties: {
621
+ showHeader: {
622
+ selectedValue: true,
623
+ },
624
+ title: {
625
+ selectedValue: 'My Page',
626
+ },
627
+ },
628
+ },
629
+ content: {
630
+ main: [],
631
+ },
632
+ });
633
+ expect(result.layout).not.toHaveProperty('options');
634
+ });
635
+ it('should convert options to properties for full layout (with displayName)', () => {
636
+ const node = {
637
+ type: 'layout',
638
+ layout: {
639
+ name: 'test-layout',
640
+ displayName: 'Test Layout',
641
+ description: 'A test layout',
642
+ template: '<div>{{content}}</div>',
643
+ zones: [],
644
+ options: {
645
+ showHeader: {
646
+ displayName: 'Show Header',
647
+ description: 'Whether to show the header',
648
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.boolean,
649
+ selectedValue: true,
650
+ },
651
+ },
652
+ },
653
+ content: {
654
+ main: [],
655
+ },
656
+ };
657
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
658
+ expect(result).toEqual({
659
+ type: 'layout',
660
+ layout: {
661
+ name: 'test-layout',
662
+ displayName: 'Test Layout',
663
+ description: 'A test layout',
664
+ template: '<div>{{content}}</div>',
665
+ zones: [],
666
+ properties: {
667
+ showHeader: {
668
+ type: 'boolean',
669
+ title: 'Show Header',
670
+ description: 'Whether to show the header',
671
+ selectedValue: true,
672
+ },
673
+ },
674
+ },
675
+ content: {
676
+ main: [],
677
+ },
678
+ });
679
+ expect(result.layout).not.toHaveProperty('options');
680
+ });
681
+ it('should not include selectedValue in minimal layout when undefined', () => {
682
+ const node = {
683
+ type: 'layout',
684
+ layout: {
685
+ name: 'test-layout',
686
+ options: {
687
+ showHeader: {
688
+ // selectedValue is undefined
689
+ },
690
+ title: {
691
+ selectedValue: 'My Page',
692
+ },
693
+ },
694
+ },
695
+ content: {},
696
+ };
697
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
698
+ expect(result.layout.properties).toEqual({
699
+ title: {
700
+ selectedValue: 'My Page',
701
+ },
702
+ });
703
+ expect(result.layout.properties.showHeader).toBeUndefined();
704
+ });
705
+ it('should handle layout with both options and properties (should not convert)', () => {
706
+ const node = {
707
+ type: 'layout',
708
+ layout: {
709
+ name: 'test-layout',
710
+ properties: {
711
+ existing: {
712
+ type: 'boolean',
713
+ title: 'Existing',
714
+ },
715
+ },
716
+ options: {
717
+ newOption: {
718
+ selectedValue: true,
719
+ },
720
+ },
721
+ },
722
+ content: {},
723
+ };
724
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
725
+ // Should keep existing properties and not convert options
726
+ expect(result.layout.properties).toEqual({
727
+ existing: {
728
+ type: 'boolean',
729
+ title: 'Existing',
730
+ },
731
+ });
732
+ expect(result.layout).toHaveProperty('options');
733
+ });
734
+ it('should preserve other node properties when converting', () => {
735
+ const node = {
736
+ type: 'layout',
737
+ nodeId: 'node-123',
738
+ layout: {
739
+ name: 'test-layout',
740
+ options: {
741
+ showHeader: {
742
+ selectedValue: true,
743
+ },
744
+ },
745
+ },
746
+ content: {
747
+ main: [{ type: 'text', value: 'Hello' }],
748
+ },
749
+ };
750
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
751
+ expect(result.nodeId).toBe('node-123');
752
+ expect(result.content).toEqual({
753
+ main: [{ type: 'text', value: 'Hello' }],
754
+ });
755
+ });
756
+ it('should handle minimal layout with boolean selectedValue', () => {
757
+ const node = {
758
+ type: 'layout',
759
+ layout: {
760
+ name: 'test-layout',
761
+ options: {
762
+ showHeader: {
763
+ selectedValue: false,
764
+ },
765
+ },
766
+ },
767
+ content: {},
768
+ };
769
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
770
+ expect(result.layout.properties.showHeader.selectedValue).toBe(false);
771
+ });
772
+ it('should handle full layout with enum values', () => {
773
+ const node = {
774
+ type: 'layout',
775
+ layout: {
776
+ name: 'test-layout',
777
+ displayName: 'Test Layout',
778
+ description: 'A test layout',
779
+ template: '<div>{{content}}</div>',
780
+ zones: [],
781
+ options: {
782
+ theme: {
783
+ displayName: 'Theme',
784
+ description: 'Color theme',
785
+ valueType: dxp_page_content_types_1.LayoutOptionValueType.stringEnum,
786
+ values: ['light', 'dark'],
787
+ selectedValue: 'dark',
788
+ },
789
+ },
790
+ },
791
+ content: {},
792
+ };
793
+ const result = (0, normalizeLayoutData_1.normalizeLayoutNode)(node);
794
+ expect(result.layout.properties.theme).toEqual({
795
+ type: 'string',
796
+ title: 'Theme',
797
+ description: 'Color theme',
798
+ enum: ['light', 'dark'],
799
+ selectedValue: 'dark',
800
+ });
801
+ });
802
+ });
803
+ });
804
+ //# sourceMappingURL=normalizeLayoutData.spec.js.map