@squiz/dx-page-contents-lib 1.78.1 → 1.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/formatted-text.d.ts +20 -50
- package/lib/formatted-text.js +5 -46
- package/lib/formatted-text.js.map +1 -1
- package/lib/formatted-text.spec.js +0 -10
- package/lib/formatted-text.spec.js.map +1 -1
- package/lib/layout-content.d.ts +316 -510
- package/lib/layout-content.js +30 -24
- package/lib/layout-content.js.map +1 -1
- package/lib/layout-content.spec.js +49 -10
- package/lib/layout-content.spec.js.map +1 -1
- package/lib/layouts/custom-layout.d.ts +6 -1056
- package/lib/layouts/index.d.ts +10 -4683
- package/lib/layouts/index.js +0 -6
- package/lib/layouts/index.js.map +1 -1
- package/lib/layouts/raw.layout.d.ts +5 -927
- package/lib/mocks/PageContentsHelpers.d.ts +37 -6359
- package/lib/mocks/PageContentsHelpers.js +40 -76
- package/lib/mocks/PageContentsHelpers.js.map +1 -1
- package/lib/mocks/PageContentsMocks.d.ts +7 -6
- package/lib/mocks/PageContentsMocks.js +54 -36
- package/lib/mocks/PageContentsMocks.js.map +1 -1
- package/lib/page-contents-lib.d.ts +17 -236
- package/lib/page-contents-lib.js +3 -23
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +133 -242
- package/lib/page-contents-lib.spec.js.map +1 -1
- package/lib/resolvers/create-variant-resolver.js +1 -1
- package/lib/resolvers/create-variant-resolver.js.map +1 -1
- package/lib/resolvers/create-variant-resolver.spec.js +50 -20
- package/lib/resolvers/create-variant-resolver.spec.js.map +1 -1
- package/lib/resolvers/default-layout-resolver.d.ts +2 -2
- package/lib/resolvers/default-layout-resolver.js +10 -4
- package/lib/resolvers/default-layout-resolver.js.map +1 -1
- package/lib/resolvers/default-layout-resolver.spec.js.map +1 -1
- package/lib/resolvers/default-variation-resolver.d.ts +2 -2
- package/lib/resolvers/default-variation-resolver.js +15 -5
- package/lib/resolvers/default-variation-resolver.js.map +1 -1
- package/lib/resolvers/default-variation-resolver.spec.js +22 -5
- package/lib/resolvers/default-variation-resolver.spec.js.map +1 -1
- package/package.json +1 -1
- package/lib/layouts/single-column.layout.d.ts +0 -950
- package/lib/layouts/single-column.layout.js +0 -15
- package/lib/layouts/single-column.layout.js.map +0 -1
- package/lib/layouts/two-column.layout.d.ts +0 -1883
- package/lib/layouts/two-column.layout.js +0 -16
- package/lib/layouts/two-column.layout.js.map +0 -1
|
@@ -16,11 +16,10 @@ describe('assertIsContentStructure', () => {
|
|
|
16
16
|
{
|
|
17
17
|
type: 'tag',
|
|
18
18
|
tag: 'p',
|
|
19
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
20
19
|
children: [
|
|
21
|
-
{ type: 'text', value: 'MY DEFAULT BLOCK'
|
|
22
|
-
{ type: 'tag', tag: 'p', children: []
|
|
23
|
-
{ type: 'tag', tag: 'br', children: []
|
|
20
|
+
{ type: 'text', value: 'MY DEFAULT BLOCK' },
|
|
21
|
+
{ type: 'tag', tag: 'p', children: [] },
|
|
22
|
+
{ type: 'tag', tag: 'br', children: [] },
|
|
24
23
|
],
|
|
25
24
|
},
|
|
26
25
|
],
|
|
@@ -82,8 +81,7 @@ describe('assertIsContentStructure', () => {
|
|
|
82
81
|
{
|
|
83
82
|
type: 'tag',
|
|
84
83
|
tag: 'p',
|
|
85
|
-
|
|
86
|
-
children: [{ type: 'text', value: 'FOUR', nodeId: (0, crypto_1.randomUUID)() }],
|
|
84
|
+
children: [{ type: 'text', value: 'FOUR' }],
|
|
87
85
|
},
|
|
88
86
|
],
|
|
89
87
|
type: 'fragment',
|
|
@@ -110,8 +108,13 @@ describe('assertIsContentStructure', () => {
|
|
|
110
108
|
it.each(['text', 'component', 'matrix-image', 'variation'])('should not allow children on %s node', (nodeType) => {
|
|
111
109
|
content[zoneId] = [
|
|
112
110
|
{
|
|
113
|
-
|
|
114
|
-
children: [
|
|
111
|
+
type: 'fragment',
|
|
112
|
+
children: [
|
|
113
|
+
{
|
|
114
|
+
...mocks_1.VALID_CONTENT_NODES[nodeType],
|
|
115
|
+
children: [],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
115
118
|
},
|
|
116
119
|
];
|
|
117
120
|
expect(() => (0, page_contents_lib_1.assertIsContentStructure)(content)).toThrow();
|
|
@@ -120,67 +123,46 @@ describe('assertIsContentStructure', () => {
|
|
|
120
123
|
content[zoneId] = [
|
|
121
124
|
{
|
|
122
125
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
123
|
-
type: '
|
|
124
|
-
|
|
125
|
-
children: [mocks_1.VALID_CONTENT_NODES.component],
|
|
126
|
+
type: 'fragment',
|
|
127
|
+
children: [mocks_1.VALID_CONTENT_NODES['link-to-matrix-asset']],
|
|
126
128
|
},
|
|
127
129
|
];
|
|
128
130
|
expect(() => (0, page_contents_lib_1.assertIsContentStructure)(content)).not.toThrow();
|
|
129
131
|
});
|
|
130
132
|
});
|
|
131
133
|
describe('assertIsPageLayout', () => {
|
|
132
|
-
describe('
|
|
133
|
-
it('should validate a
|
|
134
|
+
describe('layout-raw', () => {
|
|
135
|
+
it('should validate a layout-raw layout', () => {
|
|
134
136
|
const layout = {
|
|
135
|
-
name: '
|
|
137
|
+
name: 'layout-raw',
|
|
136
138
|
content: {
|
|
137
139
|
main: [mocks_1.VALID_CONTENT_NODES.component],
|
|
138
140
|
},
|
|
139
141
|
};
|
|
140
142
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
141
143
|
});
|
|
142
|
-
it('should validate a two-column layout', () => {
|
|
143
|
-
const layout = {
|
|
144
|
-
name: 'two-column',
|
|
145
|
-
content: {
|
|
146
|
-
left: [mocks_1.VALID_CONTENT_NODES.component],
|
|
147
|
-
right: [mocks_1.VALID_CONTENT_NODES.component],
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
151
|
-
});
|
|
152
144
|
it.each(['text', 'component', 'matrix-image', 'variation'])('should not allow children on %s node', (nodeType) => {
|
|
153
145
|
const layout = {
|
|
154
|
-
name: '
|
|
146
|
+
name: 'layout-raw',
|
|
155
147
|
content: {
|
|
156
148
|
main: [
|
|
157
149
|
{
|
|
158
|
-
|
|
159
|
-
children: [
|
|
150
|
+
type: 'fragment',
|
|
151
|
+
children: [
|
|
152
|
+
{
|
|
153
|
+
...mocks_1.VALID_CONTENT_NODES[nodeType],
|
|
154
|
+
children: [],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
160
157
|
},
|
|
161
158
|
],
|
|
162
159
|
},
|
|
163
160
|
};
|
|
164
161
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrow();
|
|
165
162
|
});
|
|
166
|
-
it('should validate a deeply nested layout', () => {
|
|
167
|
-
const layout = {
|
|
168
|
-
name: 'single-column',
|
|
169
|
-
content: {
|
|
170
|
-
main: [
|
|
171
|
-
{
|
|
172
|
-
type: 'tag',
|
|
173
|
-
tag: 'div',
|
|
174
|
-
children: [mocks_1.VALID_CONTENT_NODES.component],
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
180
|
-
});
|
|
181
163
|
it('should allow variation nodes with no content', () => {
|
|
182
164
|
const layout = {
|
|
183
|
-
name: '
|
|
165
|
+
name: 'layout-raw',
|
|
184
166
|
content: {
|
|
185
167
|
main: [mocks_1.VALID_CONTENT_NODES.variation],
|
|
186
168
|
},
|
|
@@ -189,7 +171,7 @@ describe('assertIsPageLayout', () => {
|
|
|
189
171
|
});
|
|
190
172
|
it('should allow variation nodes with content', () => {
|
|
191
173
|
const layout = {
|
|
192
|
-
name: '
|
|
174
|
+
name: 'layout-raw',
|
|
193
175
|
content: {
|
|
194
176
|
main: [
|
|
195
177
|
{
|
|
@@ -198,16 +180,26 @@ describe('assertIsPageLayout', () => {
|
|
|
198
180
|
default: {
|
|
199
181
|
node: {
|
|
200
182
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
201
|
-
type: '
|
|
202
|
-
|
|
183
|
+
type: 'fragment',
|
|
184
|
+
children: [
|
|
185
|
+
{
|
|
186
|
+
type: 'text',
|
|
187
|
+
value: 'Default content',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
203
190
|
},
|
|
204
191
|
},
|
|
205
192
|
variants: [
|
|
206
193
|
{
|
|
207
194
|
node: {
|
|
208
195
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
209
|
-
type: '
|
|
210
|
-
|
|
196
|
+
type: 'fragment',
|
|
197
|
+
children: [
|
|
198
|
+
{
|
|
199
|
+
type: 'text',
|
|
200
|
+
value: 'Variant content',
|
|
201
|
+
},
|
|
202
|
+
],
|
|
211
203
|
},
|
|
212
204
|
conditions: {
|
|
213
205
|
segment: {
|
|
@@ -224,7 +216,7 @@ describe('assertIsPageLayout', () => {
|
|
|
224
216
|
});
|
|
225
217
|
it('should not allow variation nodes with no variants', () => {
|
|
226
218
|
const layout = {
|
|
227
|
-
name: '
|
|
219
|
+
name: 'layout-raw',
|
|
228
220
|
content: {
|
|
229
221
|
main: [
|
|
230
222
|
{
|
|
@@ -245,7 +237,7 @@ describe('assertIsPageLayout', () => {
|
|
|
245
237
|
['experiment', { experiment: { id: 'experiment-1', variant: 'A' } }],
|
|
246
238
|
])('should not allow variants with duplicate %s condition', (description, conditions) => {
|
|
247
239
|
const layout = {
|
|
248
|
-
name: '
|
|
240
|
+
name: 'layout-raw',
|
|
249
241
|
content: {
|
|
250
242
|
main: [
|
|
251
243
|
{
|
|
@@ -258,16 +250,26 @@ describe('assertIsPageLayout', () => {
|
|
|
258
250
|
{
|
|
259
251
|
node: {
|
|
260
252
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
261
|
-
type: '
|
|
262
|
-
|
|
253
|
+
type: 'fragment',
|
|
254
|
+
children: [
|
|
255
|
+
{
|
|
256
|
+
type: 'text',
|
|
257
|
+
value: 'Variant content 1',
|
|
258
|
+
},
|
|
259
|
+
],
|
|
263
260
|
},
|
|
264
261
|
conditions,
|
|
265
262
|
},
|
|
266
263
|
{
|
|
267
264
|
node: {
|
|
268
265
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
269
|
-
type: '
|
|
270
|
-
|
|
266
|
+
type: 'fragment',
|
|
267
|
+
children: [
|
|
268
|
+
{
|
|
269
|
+
type: 'text',
|
|
270
|
+
value: 'Variant content 2',
|
|
271
|
+
},
|
|
272
|
+
],
|
|
271
273
|
},
|
|
272
274
|
conditions,
|
|
273
275
|
},
|
|
@@ -292,7 +294,7 @@ describe('assertIsPageLayout', () => {
|
|
|
292
294
|
],
|
|
293
295
|
])('should allow variants with non-duplication %s conditions', (description, firstConditions, secondConditions) => {
|
|
294
296
|
const layout = {
|
|
295
|
-
name: '
|
|
297
|
+
name: 'layout-raw',
|
|
296
298
|
content: {
|
|
297
299
|
main: [
|
|
298
300
|
{
|
|
@@ -305,16 +307,26 @@ describe('assertIsPageLayout', () => {
|
|
|
305
307
|
{
|
|
306
308
|
node: {
|
|
307
309
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
308
|
-
type: '
|
|
309
|
-
|
|
310
|
+
type: 'fragment',
|
|
311
|
+
children: [
|
|
312
|
+
{
|
|
313
|
+
type: 'text',
|
|
314
|
+
value: 'Variant content 1',
|
|
315
|
+
},
|
|
316
|
+
],
|
|
310
317
|
},
|
|
311
318
|
conditions: firstConditions,
|
|
312
319
|
},
|
|
313
320
|
{
|
|
314
321
|
node: {
|
|
315
322
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
316
|
-
type: '
|
|
317
|
-
|
|
323
|
+
type: 'fragment',
|
|
324
|
+
children: [
|
|
325
|
+
{
|
|
326
|
+
type: 'text',
|
|
327
|
+
value: 'Variant content 2',
|
|
328
|
+
},
|
|
329
|
+
],
|
|
318
330
|
},
|
|
319
331
|
conditions: secondConditions,
|
|
320
332
|
},
|
|
@@ -401,8 +413,8 @@ describe('assertIsPageLayout', () => {
|
|
|
401
413
|
},
|
|
402
414
|
content: {
|
|
403
415
|
main: [
|
|
404
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
405
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
416
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
417
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
406
418
|
],
|
|
407
419
|
},
|
|
408
420
|
};
|
|
@@ -428,8 +440,8 @@ describe('assertIsPageLayout', () => {
|
|
|
428
440
|
},
|
|
429
441
|
content: {
|
|
430
442
|
main: [
|
|
431
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
432
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
443
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
444
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
433
445
|
],
|
|
434
446
|
},
|
|
435
447
|
};
|
|
@@ -447,8 +459,8 @@ describe('assertIsPageLayout', () => {
|
|
|
447
459
|
},
|
|
448
460
|
content: {
|
|
449
461
|
main: [
|
|
450
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
451
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
462
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
463
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
452
464
|
],
|
|
453
465
|
},
|
|
454
466
|
};
|
|
@@ -466,56 +478,24 @@ describe('PageLayoutContentResolver', () => {
|
|
|
466
478
|
it('should resolve nested component nodes', async () => {
|
|
467
479
|
const layoutContent = [
|
|
468
480
|
{
|
|
469
|
-
type: '
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
},
|
|
474
|
-
];
|
|
475
|
-
const resolver = new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver });
|
|
476
|
-
const resolvedContent = await resolver.resolve(layoutContent);
|
|
477
|
-
expect(resolvedContent).toEqual([
|
|
478
|
-
{
|
|
479
|
-
type: 'tag',
|
|
480
|
-
nodeId: expect.any(String),
|
|
481
|
-
tag: 'div',
|
|
482
|
-
children: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
483
|
-
},
|
|
484
|
-
]);
|
|
485
|
-
});
|
|
486
|
-
it('should resolve nested component nodes in multiple levels', async () => {
|
|
487
|
-
const layoutContent = [
|
|
488
|
-
{
|
|
489
|
-
type: 'tag',
|
|
490
|
-
tag: 'div',
|
|
481
|
+
type: 'variation',
|
|
482
|
+
default: {
|
|
483
|
+
node: mocks_1.VALID_CONTENT_NODES.component,
|
|
484
|
+
},
|
|
491
485
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
492
|
-
|
|
493
|
-
mocks_1.VALID_CONTENT_NODES.component,
|
|
494
|
-
{
|
|
495
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
496
|
-
type: 'tag',
|
|
497
|
-
tag: 'div',
|
|
498
|
-
children: [mocks_1.VALID_CONTENT_NODES.component],
|
|
499
|
-
},
|
|
500
|
-
],
|
|
486
|
+
variants: [],
|
|
501
487
|
},
|
|
502
488
|
];
|
|
503
489
|
const resolver = new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver });
|
|
504
490
|
const resolvedContent = await resolver.resolve(layoutContent);
|
|
505
491
|
expect(resolvedContent).toEqual([
|
|
506
492
|
{
|
|
507
|
-
type: '
|
|
508
|
-
tag: 'div',
|
|
493
|
+
type: 'variation',
|
|
509
494
|
nodeId: expect.any(String),
|
|
510
|
-
|
|
511
|
-
expect.objectContaining({ contentItem: mocks_1.mockContentItem }),
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
nodeId: expect.any(String),
|
|
515
|
-
tag: 'div',
|
|
516
|
-
children: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
517
|
-
},
|
|
518
|
-
],
|
|
495
|
+
default: {
|
|
496
|
+
node: expect.objectContaining({ contentItem: mocks_1.mockContentItem }),
|
|
497
|
+
},
|
|
498
|
+
variants: [],
|
|
519
499
|
},
|
|
520
500
|
]);
|
|
521
501
|
});
|
|
@@ -560,16 +540,16 @@ describe('resolveLayout', () => {
|
|
|
560
540
|
},
|
|
561
541
|
});
|
|
562
542
|
});
|
|
563
|
-
it('should resolve a
|
|
543
|
+
it('should resolve a layout-raw layout', async () => {
|
|
564
544
|
const layout = {
|
|
565
|
-
name: '
|
|
545
|
+
name: 'layout-raw',
|
|
566
546
|
content: {
|
|
567
547
|
main: [mocks_1.VALID_CONTENT_NODES.component],
|
|
568
548
|
},
|
|
569
549
|
};
|
|
570
550
|
const resolvedLayout = await (0, page_contents_lib_1.resolveLayout)(layout, new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver }));
|
|
571
551
|
expect(resolvedLayout).toEqual({
|
|
572
|
-
name: '
|
|
552
|
+
name: 'layout-raw',
|
|
573
553
|
content: {
|
|
574
554
|
main: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
575
555
|
},
|
|
@@ -602,23 +582,6 @@ describe('resolveLayout', () => {
|
|
|
602
582
|
},
|
|
603
583
|
});
|
|
604
584
|
});
|
|
605
|
-
it('should resolve a two-column layout', async () => {
|
|
606
|
-
const layout = {
|
|
607
|
-
name: 'two-column',
|
|
608
|
-
content: {
|
|
609
|
-
left: [mocks_1.VALID_CONTENT_NODES.component],
|
|
610
|
-
right: [mocks_1.VALID_CONTENT_NODES.component],
|
|
611
|
-
},
|
|
612
|
-
};
|
|
613
|
-
const resolvedLayout = await (0, page_contents_lib_1.resolveLayout)(layout, new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver }));
|
|
614
|
-
expect(resolvedLayout).toEqual({
|
|
615
|
-
name: 'two-column',
|
|
616
|
-
content: {
|
|
617
|
-
left: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
618
|
-
right: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
619
|
-
},
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
585
|
it('should return the layout if does not match resolver', async () => {
|
|
623
586
|
const layout = {
|
|
624
587
|
// @ts-expect-error not a layout name
|
|
@@ -637,24 +600,22 @@ describe('renderLayout', () => {
|
|
|
637
600
|
it.each([
|
|
638
601
|
[
|
|
639
602
|
'component',
|
|
640
|
-
`<
|
|
603
|
+
`<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/>`,
|
|
641
604
|
],
|
|
642
|
-
['tag', '<div
|
|
643
|
-
['text', '
|
|
605
|
+
['tag', '<div></div>'],
|
|
606
|
+
['text', 'test'],
|
|
644
607
|
])('should render a page layout with a %s node', async (nodeType, expectedHtml) => {
|
|
645
|
-
const layout = new mocks_1.
|
|
646
|
-
.addNode(mockNodeFactory.createNode(nodeType))
|
|
647
|
-
.build();
|
|
608
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(mockNodeFactory.createNode(nodeType)).build();
|
|
648
609
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
649
610
|
expect(result).toBe(expectedHtml);
|
|
650
611
|
});
|
|
651
612
|
it('should render a page layout with multiple types of nodes', async () => {
|
|
652
|
-
const layout = new mocks_1.
|
|
613
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
653
614
|
.addNode(mockNodeFactory.createNode('component'))
|
|
654
615
|
.addNode(mockNodeFactory.createNode('tag'))
|
|
655
616
|
.build();
|
|
656
617
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
657
|
-
expect(result).toBe(`<
|
|
618
|
+
expect(result).toBe(`<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/><div></div>`);
|
|
658
619
|
});
|
|
659
620
|
it.each([['span', 'div', 'nav', 'article', 'aside', 'header', 'footer']])('should render a page custom-layout with a %s tag replaced', async (tag) => {
|
|
660
621
|
const layout = new mocks_1.CustomLayoutBuilder({
|
|
@@ -742,70 +703,23 @@ describe('renderLayout', () => {
|
|
|
742
703
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
743
704
|
expect(normalizeHtml(result)).toBe(normalizeHtml(`<span class=""><span class="test"><p class="invalid-node-type">Error rendering developer template mock-dev-layout-with-classes</p></span></span>`));
|
|
744
705
|
});
|
|
745
|
-
it('should render a developer layout node inside a
|
|
706
|
+
it('should render a developer layout node inside a layout-raw layout', async () => {
|
|
746
707
|
const mockBuilder = new mocks_1.MockNodeFactory();
|
|
747
708
|
const developerLayoutNode = {
|
|
748
709
|
type: 'layout',
|
|
749
710
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
750
711
|
layout: {
|
|
751
712
|
template: '<div class="dev-layout">{{zones.content}}</div>',
|
|
752
|
-
name: 'dev-layout-in-
|
|
713
|
+
name: 'dev-layout-in-layout-raw',
|
|
753
714
|
options: {},
|
|
754
715
|
},
|
|
755
716
|
content: {
|
|
756
717
|
content: [mockBuilder.createNodeWithId('component', 'nested-component')],
|
|
757
718
|
},
|
|
758
719
|
};
|
|
759
|
-
const layout = new mocks_1.
|
|
760
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
761
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container"><div class="dev-layout"><esi:include src="${config.componentRootUrl}/r/nested-component?_componentSet=my-component-set&_contentItemId=123"/></div></div>`));
|
|
762
|
-
});
|
|
763
|
-
it('should render developer layout nodes in a two-column layout', async () => {
|
|
764
|
-
const mockBuilder = new mocks_1.MockNodeFactory();
|
|
765
|
-
const leftLayoutNode = {
|
|
766
|
-
type: 'layout',
|
|
767
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
768
|
-
layout: {
|
|
769
|
-
template: '<section class="left-dev-layout">{{zones.content}}</section>',
|
|
770
|
-
name: 'dev-layout-left',
|
|
771
|
-
options: {},
|
|
772
|
-
},
|
|
773
|
-
content: {
|
|
774
|
-
content: [mockBuilder.createNodeWithId('component', 'left-component')],
|
|
775
|
-
},
|
|
776
|
-
};
|
|
777
|
-
const rightLayoutNode = {
|
|
778
|
-
type: 'layout',
|
|
779
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
780
|
-
layout: {
|
|
781
|
-
template: '<aside class="right-dev-layout">{{zones.content}}</aside>',
|
|
782
|
-
name: 'dev-layout-right',
|
|
783
|
-
options: {},
|
|
784
|
-
},
|
|
785
|
-
content: {
|
|
786
|
-
content: [mockBuilder.createNodeWithId('component', 'right-component')],
|
|
787
|
-
},
|
|
788
|
-
};
|
|
789
|
-
const layout = {
|
|
790
|
-
name: 'two-column',
|
|
791
|
-
content: {
|
|
792
|
-
left: [leftLayoutNode],
|
|
793
|
-
right: [rightLayoutNode],
|
|
794
|
-
},
|
|
795
|
-
};
|
|
720
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
|
|
796
721
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
797
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="
|
|
798
|
-
<div class="left">
|
|
799
|
-
<section class="left-dev-layout">
|
|
800
|
-
<esi:include src="${config.componentRootUrl}/r/left-component?_componentSet=my-component-set&_contentItemId=123"/>
|
|
801
|
-
</section>
|
|
802
|
-
</div>
|
|
803
|
-
<div class="right">
|
|
804
|
-
<aside class="right-dev-layout">
|
|
805
|
-
<esi:include src="${config.componentRootUrl}/r/right-component?_componentSet=my-component-set&_contentItemId=123"/>
|
|
806
|
-
</aside>
|
|
807
|
-
</div>
|
|
808
|
-
</div>`));
|
|
722
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="dev-layout"><esi:include src="${config.componentRootUrl}/r/nested-component?_componentSet=my-component-set&_contentItemId=123"/></div>`));
|
|
809
723
|
});
|
|
810
724
|
it('should render a developer layout node with text nodes inside a layout-raw layout', async () => {
|
|
811
725
|
const developerLayoutNode = {
|
|
@@ -817,8 +731,10 @@ describe('renderLayout', () => {
|
|
|
817
731
|
options: {},
|
|
818
732
|
},
|
|
819
733
|
content: {
|
|
820
|
-
title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
|
|
821
|
-
body: [
|
|
734
|
+
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
735
|
+
body: [
|
|
736
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
737
|
+
],
|
|
822
738
|
},
|
|
823
739
|
};
|
|
824
740
|
const layout = {
|
|
@@ -856,15 +772,14 @@ describe('renderLayout', () => {
|
|
|
856
772
|
outerContent: [innerLayoutNode],
|
|
857
773
|
},
|
|
858
774
|
};
|
|
859
|
-
const layout = new mocks_1.
|
|
775
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayoutNode).build();
|
|
860
776
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
861
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(
|
|
777
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`
|
|
862
778
|
<div class="outer-layout">
|
|
863
779
|
<div class="inner-layout">
|
|
864
780
|
<esi:include src="${config.componentRootUrl}/r/inner-component?_componentSet=my-component-set&_contentItemId=123"/>
|
|
865
781
|
</div>
|
|
866
|
-
</div
|
|
867
|
-
</div>`));
|
|
782
|
+
</div>`));
|
|
868
783
|
});
|
|
869
784
|
it('should handle deeply nested layout nodes', async () => {
|
|
870
785
|
const mockBuilder = new mocks_1.MockNodeFactory();
|
|
@@ -930,7 +845,7 @@ describe('renderLayout', () => {
|
|
|
930
845
|
options: {},
|
|
931
846
|
},
|
|
932
847
|
content: {
|
|
933
|
-
heading: [{ type: 'text', value: 'Inner Heading', nodeId: (0, crypto_1.randomUUID)() }],
|
|
848
|
+
heading: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner Heading' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
934
849
|
content: [mockBuilder.createNodeWithId('component', 'inner-mixed-component')],
|
|
935
850
|
},
|
|
936
851
|
};
|
|
@@ -943,14 +858,15 @@ describe('renderLayout', () => {
|
|
|
943
858
|
options: {},
|
|
944
859
|
},
|
|
945
860
|
content: {
|
|
946
|
-
intro: [
|
|
861
|
+
intro: [
|
|
862
|
+
{ type: 'fragment', children: [{ type: 'text', value: '<p>Introduction text</p>' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
863
|
+
],
|
|
947
864
|
main: [innerLayout],
|
|
948
865
|
},
|
|
949
866
|
};
|
|
950
|
-
const layout = new mocks_1.
|
|
867
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayout).build();
|
|
951
868
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
952
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="
|
|
953
|
-
<div class="outer-mixed">
|
|
869
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-mixed">
|
|
954
870
|
<div class="intro"><p>Introduction text</p></div>
|
|
955
871
|
<div class="main">
|
|
956
872
|
<div class="inner-mixed">
|
|
@@ -960,8 +876,7 @@ describe('renderLayout', () => {
|
|
|
960
876
|
</div>
|
|
961
877
|
</div>
|
|
962
878
|
</div>
|
|
963
|
-
</div
|
|
964
|
-
</div>`));
|
|
879
|
+
</div>`));
|
|
965
880
|
});
|
|
966
881
|
it('should add HTML comments for developer defined layouts in preview mode', async () => {
|
|
967
882
|
const developerLayoutNode = {
|
|
@@ -973,8 +888,10 @@ describe('renderLayout', () => {
|
|
|
973
888
|
options: {},
|
|
974
889
|
},
|
|
975
890
|
content: {
|
|
976
|
-
title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
|
|
977
|
-
body: [
|
|
891
|
+
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
892
|
+
body: [
|
|
893
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
894
|
+
],
|
|
978
895
|
},
|
|
979
896
|
};
|
|
980
897
|
const contentPage = {
|
|
@@ -996,7 +913,7 @@ describe('renderLayout', () => {
|
|
|
996
913
|
options: {},
|
|
997
914
|
},
|
|
998
915
|
content: {
|
|
999
|
-
content: [{ type: 'text', value: 'Inner content', nodeId: (0, crypto_1.randomUUID)() }],
|
|
916
|
+
content: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner content' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
1000
917
|
},
|
|
1001
918
|
};
|
|
1002
919
|
const developerLayoutNode = {
|
|
@@ -1034,7 +951,7 @@ describe('renderLayout', () => {
|
|
|
1034
951
|
content: [
|
|
1035
952
|
{
|
|
1036
953
|
type: 'fragment',
|
|
1037
|
-
children: [{ type: 'text', value: 'Fragment content'
|
|
954
|
+
children: [{ type: 'text', value: 'Fragment content' }],
|
|
1038
955
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1039
956
|
},
|
|
1040
957
|
],
|
|
@@ -1058,7 +975,7 @@ describe('renderLayout', () => {
|
|
|
1058
975
|
},
|
|
1059
976
|
};
|
|
1060
977
|
it('should render translated fragment nodes', async () => {
|
|
1061
|
-
const layout = new mocks_1.
|
|
978
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1062
979
|
.addNode({
|
|
1063
980
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1064
981
|
type: 'fragment',
|
|
@@ -1066,7 +983,6 @@ describe('renderLayout', () => {
|
|
|
1066
983
|
{
|
|
1067
984
|
type: 'text',
|
|
1068
985
|
value: 'English text',
|
|
1069
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1070
986
|
},
|
|
1071
987
|
],
|
|
1072
988
|
i18n: {
|
|
@@ -1082,10 +998,10 @@ describe('renderLayout', () => {
|
|
|
1082
998
|
})
|
|
1083
999
|
.build();
|
|
1084
1000
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1085
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('
|
|
1001
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml('French text'));
|
|
1086
1002
|
});
|
|
1087
1003
|
it('should render translated component nodes', async () => {
|
|
1088
|
-
const layout = new mocks_1.
|
|
1004
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1089
1005
|
.addNode({
|
|
1090
1006
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1091
1007
|
type: 'component',
|
|
@@ -1099,10 +1015,10 @@ describe('renderLayout', () => {
|
|
|
1099
1015
|
})
|
|
1100
1016
|
.build();
|
|
1101
1017
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1102
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<
|
|
1018
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/>`));
|
|
1103
1019
|
});
|
|
1104
1020
|
it('should render mixed translated and untranslated nodes', async () => {
|
|
1105
|
-
const layout = new mocks_1.
|
|
1021
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1106
1022
|
.addNode({
|
|
1107
1023
|
// Translated fragment
|
|
1108
1024
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
@@ -1111,7 +1027,6 @@ describe('renderLayout', () => {
|
|
|
1111
1027
|
{
|
|
1112
1028
|
type: 'text',
|
|
1113
1029
|
value: 'English text',
|
|
1114
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1115
1030
|
},
|
|
1116
1031
|
],
|
|
1117
1032
|
i18n: {
|
|
@@ -1136,7 +1051,7 @@ describe('renderLayout', () => {
|
|
|
1136
1051
|
})
|
|
1137
1052
|
.build();
|
|
1138
1053
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1139
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(
|
|
1054
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/>`));
|
|
1140
1055
|
});
|
|
1141
1056
|
it('should render developer layout with translated content', async () => {
|
|
1142
1057
|
const developerLayoutNode = {
|
|
@@ -1176,19 +1091,19 @@ describe('renderLayout', () => {
|
|
|
1176
1091
|
],
|
|
1177
1092
|
},
|
|
1178
1093
|
};
|
|
1179
|
-
const layout = new mocks_1.
|
|
1094
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
|
|
1180
1095
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1181
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(
|
|
1096
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`
|
|
1182
1097
|
<div class="top">
|
|
1183
1098
|
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-top"/>
|
|
1184
1099
|
</div>
|
|
1185
1100
|
<div class="side">
|
|
1186
1101
|
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-side"/>
|
|
1187
1102
|
</div>
|
|
1188
|
-
|
|
1103
|
+
`));
|
|
1189
1104
|
});
|
|
1190
1105
|
it('should render layout with no translations when language config is missing', async () => {
|
|
1191
|
-
const layout = new mocks_1.
|
|
1106
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1192
1107
|
.addNode({
|
|
1193
1108
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1194
1109
|
type: 'fragment',
|
|
@@ -1196,7 +1111,6 @@ describe('renderLayout', () => {
|
|
|
1196
1111
|
{
|
|
1197
1112
|
type: 'text',
|
|
1198
1113
|
value: 'English text',
|
|
1199
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1200
1114
|
},
|
|
1201
1115
|
],
|
|
1202
1116
|
i18n: {
|
|
@@ -1205,7 +1119,6 @@ describe('renderLayout', () => {
|
|
|
1205
1119
|
{
|
|
1206
1120
|
type: 'text',
|
|
1207
1121
|
value: 'French text',
|
|
1208
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1209
1122
|
},
|
|
1210
1123
|
],
|
|
1211
1124
|
},
|
|
@@ -1213,31 +1126,11 @@ describe('renderLayout', () => {
|
|
|
1213
1126
|
})
|
|
1214
1127
|
.build();
|
|
1215
1128
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config); // Using config without lang
|
|
1216
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('
|
|
1129
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml('English text'));
|
|
1217
1130
|
});
|
|
1218
1131
|
});
|
|
1219
1132
|
});
|
|
1220
1133
|
describe('Helper functions', () => {
|
|
1221
|
-
it('isDeveloperDefinedLayoutNode returns true for valid developer layouts', () => {
|
|
1222
|
-
const layoutNode = {
|
|
1223
|
-
type: 'layout',
|
|
1224
|
-
layout: {
|
|
1225
|
-
template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
|
|
1226
|
-
name: 'mock-dev-layout-with-classes',
|
|
1227
|
-
options: {},
|
|
1228
|
-
},
|
|
1229
|
-
content: {
|
|
1230
|
-
top: [],
|
|
1231
|
-
},
|
|
1232
|
-
};
|
|
1233
|
-
expect((0, page_contents_lib_1.isDeveloperDefinedLayoutNode)(layoutNode)).toEqual(true);
|
|
1234
|
-
});
|
|
1235
|
-
it('isDeveloperDefinedLayoutNode returns false for invalid developer layouts', () => {
|
|
1236
|
-
const layoutNode = {
|
|
1237
|
-
foo: 'bar',
|
|
1238
|
-
};
|
|
1239
|
-
expect((0, page_contents_lib_1.isDeveloperDefinedLayoutNode)(layoutNode)).toEqual(false);
|
|
1240
|
-
});
|
|
1241
1134
|
it('isCustomLayout returns true for valid custom layouts', () => {
|
|
1242
1135
|
const layout = new mocks_1.CustomLayoutBuilder({
|
|
1243
1136
|
rootWrapper: {
|
|
@@ -1397,8 +1290,8 @@ describe('translateLanguageNodes', () => {
|
|
|
1397
1290
|
default: {
|
|
1398
1291
|
node: {
|
|
1399
1292
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1400
|
-
type: '
|
|
1401
|
-
value: 'Default text',
|
|
1293
|
+
type: 'fragment',
|
|
1294
|
+
children: [{ type: 'text', value: 'Default text' }],
|
|
1402
1295
|
},
|
|
1403
1296
|
},
|
|
1404
1297
|
variants: [],
|
|
@@ -1429,7 +1322,6 @@ describe('translateLanguageNodes', () => {
|
|
|
1429
1322
|
{
|
|
1430
1323
|
type: 'text',
|
|
1431
1324
|
value: 'English text',
|
|
1432
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1433
1325
|
},
|
|
1434
1326
|
],
|
|
1435
1327
|
i18n: {
|
|
@@ -1438,7 +1330,6 @@ describe('translateLanguageNodes', () => {
|
|
|
1438
1330
|
{
|
|
1439
1331
|
type: 'text',
|
|
1440
1332
|
value: 'Spanish text',
|
|
1441
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1442
1333
|
},
|
|
1443
1334
|
],
|
|
1444
1335
|
},
|