@squiz/dx-page-contents-lib 1.78.1 → 1.80.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 +302 -510
- package/lib/layout-content.js +40 -24
- package/lib/layout-content.js.map +1 -1
- package/lib/layout-content.spec.js +67 -10
- package/lib/layout-content.spec.js.map +1 -1
- package/lib/layouts/custom-layout.d.ts +6 -1064
- package/lib/layouts/index.d.ts +25 -4665
- package/lib/layouts/raw.layout.d.ts +5 -933
- package/lib/layouts/single-column.layout.d.ts +5 -933
- package/lib/layouts/two-column.layout.d.ts +10 -1866
- package/lib/mocks/PageContentsHelpers.d.ts +58 -6333
- 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 +88 -36
- package/lib/mocks/PageContentsMocks.js.map +1 -1
- package/lib/page-contents-lib.d.ts +24 -242
- package/lib/page-contents-lib.js +146 -64
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +1382 -798
- 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
|
@@ -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,126 @@ 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
|
});
|
|
132
|
+
it('should set nodeId on top level nodes', () => {
|
|
133
|
+
const layoutWithoutNodeId = {
|
|
134
|
+
type: 'layout',
|
|
135
|
+
layout: {
|
|
136
|
+
name: 'my-layout__dev',
|
|
137
|
+
options: {},
|
|
138
|
+
},
|
|
139
|
+
content: {
|
|
140
|
+
main: [
|
|
141
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Hello' }] },
|
|
142
|
+
{ type: 'text', value: 'World' },
|
|
143
|
+
],
|
|
144
|
+
sidebar: [
|
|
145
|
+
{ type: 'component', componentId: 'my-component', componentSet: 'my-set', contentItem: { id: '123' } },
|
|
146
|
+
],
|
|
147
|
+
footer: [
|
|
148
|
+
{
|
|
149
|
+
type: 'variation',
|
|
150
|
+
default: { node: { type: 'fragment', children: [{ type: 'text', value: 'Default' }] } },
|
|
151
|
+
variants: [{ node: { type: 'fragment', children: [{ type: 'text', value: 'Variant' }] }, conditions: {} }],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
const content = {
|
|
157
|
+
// @ts-expect-error should error since is not parsed yet
|
|
158
|
+
'my-zone': [layoutWithoutNodeId],
|
|
159
|
+
};
|
|
160
|
+
const result = (0, page_contents_lib_1.assertIsContentStructure)(content);
|
|
161
|
+
expect(result).toEqual({
|
|
162
|
+
'my-zone': [
|
|
163
|
+
{
|
|
164
|
+
type: 'layout',
|
|
165
|
+
layout: {
|
|
166
|
+
name: 'my-layout__dev',
|
|
167
|
+
options: {},
|
|
168
|
+
},
|
|
169
|
+
nodeId: expect.any(String),
|
|
170
|
+
content: {
|
|
171
|
+
main: [
|
|
172
|
+
{ type: 'fragment', nodeId: expect.any(String), children: [{ type: 'text', value: 'Hello' }] },
|
|
173
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'World' }], nodeId: expect.any(String) },
|
|
174
|
+
],
|
|
175
|
+
sidebar: [
|
|
176
|
+
{
|
|
177
|
+
type: 'component',
|
|
178
|
+
nodeId: expect.any(String),
|
|
179
|
+
componentId: 'my-component',
|
|
180
|
+
componentSet: 'my-set',
|
|
181
|
+
contentItem: { id: '123' },
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
footer: [
|
|
185
|
+
{
|
|
186
|
+
type: 'variation',
|
|
187
|
+
nodeId: expect.any(String),
|
|
188
|
+
default: {
|
|
189
|
+
node: {
|
|
190
|
+
type: 'fragment',
|
|
191
|
+
nodeId: expect.any(String),
|
|
192
|
+
children: [{ type: 'text', value: 'Default' }],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
variants: [
|
|
196
|
+
{
|
|
197
|
+
node: {
|
|
198
|
+
type: 'fragment',
|
|
199
|
+
nodeId: expect.any(String),
|
|
200
|
+
children: [{ type: 'text', value: 'Variant' }],
|
|
201
|
+
},
|
|
202
|
+
conditions: {},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
});
|
|
130
212
|
});
|
|
131
213
|
describe('assertIsPageLayout', () => {
|
|
132
|
-
describe('
|
|
133
|
-
it('should validate a
|
|
214
|
+
describe('layout-raw', () => {
|
|
215
|
+
it('should validate a layout-raw layout', () => {
|
|
134
216
|
const layout = {
|
|
135
|
-
name: '
|
|
217
|
+
name: 'layout-raw',
|
|
136
218
|
content: {
|
|
137
219
|
main: [mocks_1.VALID_CONTENT_NODES.component],
|
|
138
220
|
},
|
|
139
221
|
};
|
|
140
222
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
141
223
|
});
|
|
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
224
|
it.each(['text', 'component', 'matrix-image', 'variation'])('should not allow children on %s node', (nodeType) => {
|
|
153
225
|
const layout = {
|
|
154
|
-
name: '
|
|
226
|
+
name: 'layout-raw',
|
|
155
227
|
content: {
|
|
156
228
|
main: [
|
|
157
229
|
{
|
|
158
|
-
|
|
159
|
-
children: [
|
|
230
|
+
type: 'fragment',
|
|
231
|
+
children: [
|
|
232
|
+
{
|
|
233
|
+
...mocks_1.VALID_CONTENT_NODES[nodeType],
|
|
234
|
+
children: [],
|
|
235
|
+
},
|
|
236
|
+
],
|
|
160
237
|
},
|
|
161
238
|
],
|
|
162
239
|
},
|
|
163
240
|
};
|
|
164
241
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrow();
|
|
165
242
|
});
|
|
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
243
|
it('should allow variation nodes with no content', () => {
|
|
182
244
|
const layout = {
|
|
183
|
-
name: '
|
|
245
|
+
name: 'layout-raw',
|
|
184
246
|
content: {
|
|
185
247
|
main: [mocks_1.VALID_CONTENT_NODES.variation],
|
|
186
248
|
},
|
|
@@ -189,7 +251,7 @@ describe('assertIsPageLayout', () => {
|
|
|
189
251
|
});
|
|
190
252
|
it('should allow variation nodes with content', () => {
|
|
191
253
|
const layout = {
|
|
192
|
-
name: '
|
|
254
|
+
name: 'layout-raw',
|
|
193
255
|
content: {
|
|
194
256
|
main: [
|
|
195
257
|
{
|
|
@@ -198,16 +260,26 @@ describe('assertIsPageLayout', () => {
|
|
|
198
260
|
default: {
|
|
199
261
|
node: {
|
|
200
262
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
201
|
-
type: '
|
|
202
|
-
|
|
263
|
+
type: 'fragment',
|
|
264
|
+
children: [
|
|
265
|
+
{
|
|
266
|
+
type: 'text',
|
|
267
|
+
value: 'Default content',
|
|
268
|
+
},
|
|
269
|
+
],
|
|
203
270
|
},
|
|
204
271
|
},
|
|
205
272
|
variants: [
|
|
206
273
|
{
|
|
207
274
|
node: {
|
|
208
275
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
209
|
-
type: '
|
|
210
|
-
|
|
276
|
+
type: 'fragment',
|
|
277
|
+
children: [
|
|
278
|
+
{
|
|
279
|
+
type: 'text',
|
|
280
|
+
value: 'Variant content',
|
|
281
|
+
},
|
|
282
|
+
],
|
|
211
283
|
},
|
|
212
284
|
conditions: {
|
|
213
285
|
segment: {
|
|
@@ -224,7 +296,7 @@ describe('assertIsPageLayout', () => {
|
|
|
224
296
|
});
|
|
225
297
|
it('should not allow variation nodes with no variants', () => {
|
|
226
298
|
const layout = {
|
|
227
|
-
name: '
|
|
299
|
+
name: 'layout-raw',
|
|
228
300
|
content: {
|
|
229
301
|
main: [
|
|
230
302
|
{
|
|
@@ -245,7 +317,7 @@ describe('assertIsPageLayout', () => {
|
|
|
245
317
|
['experiment', { experiment: { id: 'experiment-1', variant: 'A' } }],
|
|
246
318
|
])('should not allow variants with duplicate %s condition', (description, conditions) => {
|
|
247
319
|
const layout = {
|
|
248
|
-
name: '
|
|
320
|
+
name: 'layout-raw',
|
|
249
321
|
content: {
|
|
250
322
|
main: [
|
|
251
323
|
{
|
|
@@ -258,16 +330,26 @@ describe('assertIsPageLayout', () => {
|
|
|
258
330
|
{
|
|
259
331
|
node: {
|
|
260
332
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
261
|
-
type: '
|
|
262
|
-
|
|
333
|
+
type: 'fragment',
|
|
334
|
+
children: [
|
|
335
|
+
{
|
|
336
|
+
type: 'text',
|
|
337
|
+
value: 'Variant content 1',
|
|
338
|
+
},
|
|
339
|
+
],
|
|
263
340
|
},
|
|
264
341
|
conditions,
|
|
265
342
|
},
|
|
266
343
|
{
|
|
267
344
|
node: {
|
|
268
345
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
269
|
-
type: '
|
|
270
|
-
|
|
346
|
+
type: 'fragment',
|
|
347
|
+
children: [
|
|
348
|
+
{
|
|
349
|
+
type: 'text',
|
|
350
|
+
value: 'Variant content 2',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
271
353
|
},
|
|
272
354
|
conditions,
|
|
273
355
|
},
|
|
@@ -292,7 +374,7 @@ describe('assertIsPageLayout', () => {
|
|
|
292
374
|
],
|
|
293
375
|
])('should allow variants with non-duplication %s conditions', (description, firstConditions, secondConditions) => {
|
|
294
376
|
const layout = {
|
|
295
|
-
name: '
|
|
377
|
+
name: 'layout-raw',
|
|
296
378
|
content: {
|
|
297
379
|
main: [
|
|
298
380
|
{
|
|
@@ -305,16 +387,26 @@ describe('assertIsPageLayout', () => {
|
|
|
305
387
|
{
|
|
306
388
|
node: {
|
|
307
389
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
308
|
-
type: '
|
|
309
|
-
|
|
390
|
+
type: 'fragment',
|
|
391
|
+
children: [
|
|
392
|
+
{
|
|
393
|
+
type: 'text',
|
|
394
|
+
value: 'Variant content 1',
|
|
395
|
+
},
|
|
396
|
+
],
|
|
310
397
|
},
|
|
311
398
|
conditions: firstConditions,
|
|
312
399
|
},
|
|
313
400
|
{
|
|
314
401
|
node: {
|
|
315
402
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
316
|
-
type: '
|
|
317
|
-
|
|
403
|
+
type: 'fragment',
|
|
404
|
+
children: [
|
|
405
|
+
{
|
|
406
|
+
type: 'text',
|
|
407
|
+
value: 'Variant content 2',
|
|
408
|
+
},
|
|
409
|
+
],
|
|
318
410
|
},
|
|
319
411
|
conditions: secondConditions,
|
|
320
412
|
},
|
|
@@ -325,6 +417,27 @@ describe('assertIsPageLayout', () => {
|
|
|
325
417
|
};
|
|
326
418
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
327
419
|
});
|
|
420
|
+
it('should allow FormattedText nodes at the top level but wrap them in a fragment node', () => {
|
|
421
|
+
const layout = {
|
|
422
|
+
name: 'layout-raw',
|
|
423
|
+
content: {
|
|
424
|
+
// @ts-expect-error should error since tag is not a valid top level node
|
|
425
|
+
main: [mocks_1.VALID_CONTENT_NODES.tag],
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
expect((0, page_contents_lib_1.assertIsPageLayout)(layout)).toEqual({
|
|
429
|
+
name: 'layout-raw',
|
|
430
|
+
content: {
|
|
431
|
+
main: [
|
|
432
|
+
{
|
|
433
|
+
type: 'fragment',
|
|
434
|
+
children: [mocks_1.VALID_CONTENT_NODES.tag],
|
|
435
|
+
nodeId: expect.any(String),
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
});
|
|
328
441
|
});
|
|
329
442
|
describe('custom-layout', () => {
|
|
330
443
|
it('errors when config.minNodes is greater than config.maxNodes', () => {
|
|
@@ -401,8 +514,8 @@ describe('assertIsPageLayout', () => {
|
|
|
401
514
|
},
|
|
402
515
|
content: {
|
|
403
516
|
main: [
|
|
404
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
405
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
517
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
518
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
406
519
|
],
|
|
407
520
|
},
|
|
408
521
|
};
|
|
@@ -428,8 +541,8 @@ describe('assertIsPageLayout', () => {
|
|
|
428
541
|
},
|
|
429
542
|
content: {
|
|
430
543
|
main: [
|
|
431
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
432
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
544
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
545
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
433
546
|
],
|
|
434
547
|
},
|
|
435
548
|
};
|
|
@@ -447,8 +560,8 @@ describe('assertIsPageLayout', () => {
|
|
|
447
560
|
},
|
|
448
561
|
content: {
|
|
449
562
|
main: [
|
|
450
|
-
{ type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
451
|
-
{ type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
|
|
563
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
564
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
452
565
|
],
|
|
453
566
|
},
|
|
454
567
|
};
|
|
@@ -466,56 +579,24 @@ describe('PageLayoutContentResolver', () => {
|
|
|
466
579
|
it('should resolve nested component nodes', async () => {
|
|
467
580
|
const layoutContent = [
|
|
468
581
|
{
|
|
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',
|
|
582
|
+
type: 'variation',
|
|
583
|
+
default: {
|
|
584
|
+
node: mocks_1.VALID_CONTENT_NODES.component,
|
|
585
|
+
},
|
|
491
586
|
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
|
-
],
|
|
587
|
+
variants: [],
|
|
501
588
|
},
|
|
502
589
|
];
|
|
503
590
|
const resolver = new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver });
|
|
504
591
|
const resolvedContent = await resolver.resolve(layoutContent);
|
|
505
592
|
expect(resolvedContent).toEqual([
|
|
506
593
|
{
|
|
507
|
-
type: '
|
|
508
|
-
tag: 'div',
|
|
594
|
+
type: 'variation',
|
|
509
595
|
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
|
-
],
|
|
596
|
+
default: {
|
|
597
|
+
node: expect.objectContaining({ contentItem: mocks_1.mockContentItem }),
|
|
598
|
+
},
|
|
599
|
+
variants: [],
|
|
519
600
|
},
|
|
520
601
|
]);
|
|
521
602
|
});
|
|
@@ -560,16 +641,16 @@ describe('resolveLayout', () => {
|
|
|
560
641
|
},
|
|
561
642
|
});
|
|
562
643
|
});
|
|
563
|
-
it('should resolve a
|
|
644
|
+
it('should resolve a layout-raw layout', async () => {
|
|
564
645
|
const layout = {
|
|
565
|
-
name: '
|
|
646
|
+
name: 'layout-raw',
|
|
566
647
|
content: {
|
|
567
648
|
main: [mocks_1.VALID_CONTENT_NODES.component],
|
|
568
649
|
},
|
|
569
650
|
};
|
|
570
651
|
const resolvedLayout = await (0, page_contents_lib_1.resolveLayout)(layout, new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver }));
|
|
571
652
|
expect(resolvedLayout).toEqual({
|
|
572
|
-
name: '
|
|
653
|
+
name: 'layout-raw',
|
|
573
654
|
content: {
|
|
574
655
|
main: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
|
|
575
656
|
},
|
|
@@ -602,23 +683,6 @@ describe('resolveLayout', () => {
|
|
|
602
683
|
},
|
|
603
684
|
});
|
|
604
685
|
});
|
|
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
686
|
it('should return the layout if does not match resolver', async () => {
|
|
623
687
|
const layout = {
|
|
624
688
|
// @ts-expect-error not a layout name
|
|
@@ -637,24 +701,22 @@ describe('renderLayout', () => {
|
|
|
637
701
|
it.each([
|
|
638
702
|
[
|
|
639
703
|
'component',
|
|
640
|
-
`<
|
|
704
|
+
`<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/>`,
|
|
641
705
|
],
|
|
642
|
-
['tag', '<div
|
|
643
|
-
['text', '
|
|
706
|
+
['tag', '<div></div>'],
|
|
707
|
+
['text', 'test'],
|
|
644
708
|
])('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();
|
|
709
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(mockNodeFactory.createNode(nodeType)).build();
|
|
648
710
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
649
711
|
expect(result).toBe(expectedHtml);
|
|
650
712
|
});
|
|
651
713
|
it('should render a page layout with multiple types of nodes', async () => {
|
|
652
|
-
const layout = new mocks_1.
|
|
714
|
+
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
653
715
|
.addNode(mockNodeFactory.createNode('component'))
|
|
654
716
|
.addNode(mockNodeFactory.createNode('tag'))
|
|
655
717
|
.build();
|
|
656
718
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
657
|
-
expect(result).toBe(`<
|
|
719
|
+
expect(result).toBe(`<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/><div></div>`);
|
|
658
720
|
});
|
|
659
721
|
it.each([['span', 'div', 'nav', 'article', 'aside', 'header', 'footer']])('should render a page custom-layout with a %s tag replaced', async (tag) => {
|
|
660
722
|
const layout = new mocks_1.CustomLayoutBuilder({
|
|
@@ -690,6 +752,23 @@ describe('renderLayout', () => {
|
|
|
690
752
|
layout: {
|
|
691
753
|
template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
|
|
692
754
|
name: 'mock-dev-layout-with-classes',
|
|
755
|
+
zones: {
|
|
756
|
+
top: {
|
|
757
|
+
displayName: 'Top Zone',
|
|
758
|
+
description: 'Top Zone Description',
|
|
759
|
+
minNodes: 0,
|
|
760
|
+
},
|
|
761
|
+
bottom: {
|
|
762
|
+
displayName: 'Bottom Zone',
|
|
763
|
+
description: 'Bottom Zone Description',
|
|
764
|
+
minNodes: 0,
|
|
765
|
+
},
|
|
766
|
+
side: {
|
|
767
|
+
displayName: 'Side Zone',
|
|
768
|
+
description: 'Side Zone Description',
|
|
769
|
+
minNodes: 0,
|
|
770
|
+
},
|
|
771
|
+
},
|
|
693
772
|
options: {},
|
|
694
773
|
},
|
|
695
774
|
content: {
|
|
@@ -721,6 +800,23 @@ describe('renderLayout', () => {
|
|
|
721
800
|
template: '<div class="container custom-class">{{zones.top</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
|
|
722
801
|
name: 'mock-dev-layout-with-classes',
|
|
723
802
|
options: {},
|
|
803
|
+
zones: {
|
|
804
|
+
top: {
|
|
805
|
+
displayName: 'Top Zone',
|
|
806
|
+
description: 'Top Zone Description',
|
|
807
|
+
minNodes: 0,
|
|
808
|
+
},
|
|
809
|
+
bottom: {
|
|
810
|
+
displayName: 'Bottom Zone',
|
|
811
|
+
description: 'Bottom Zone Description',
|
|
812
|
+
minNodes: 0,
|
|
813
|
+
},
|
|
814
|
+
side: {
|
|
815
|
+
displayName: 'Side Zone',
|
|
816
|
+
description: 'Side Zone Description',
|
|
817
|
+
minNodes: 0,
|
|
818
|
+
},
|
|
819
|
+
},
|
|
724
820
|
},
|
|
725
821
|
content: {
|
|
726
822
|
top: [mockBuilder.createNodeWithId('component', 'top-component')],
|
|
@@ -742,70 +838,30 @@ describe('renderLayout', () => {
|
|
|
742
838
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
743
839
|
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
840
|
});
|
|
745
|
-
it('should render a developer layout node inside a
|
|
841
|
+
it('should render a developer layout node inside a layout-raw layout', async () => {
|
|
746
842
|
const mockBuilder = new mocks_1.MockNodeFactory();
|
|
747
843
|
const developerLayoutNode = {
|
|
748
844
|
type: 'layout',
|
|
749
845
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
750
846
|
layout: {
|
|
751
847
|
template: '<div class="dev-layout">{{zones.content}}</div>',
|
|
752
|
-
name: 'dev-layout-in-
|
|
848
|
+
name: 'dev-layout-in-layout-raw',
|
|
849
|
+
zones: {
|
|
850
|
+
content: {
|
|
851
|
+
displayName: 'Content Zone',
|
|
852
|
+
description: 'Content Zone Description',
|
|
853
|
+
minNodes: 0,
|
|
854
|
+
},
|
|
855
|
+
},
|
|
753
856
|
options: {},
|
|
754
857
|
},
|
|
755
858
|
content: {
|
|
756
859
|
content: [mockBuilder.createNodeWithId('component', 'nested-component')],
|
|
757
860
|
},
|
|
758
861
|
};
|
|
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
|
-
};
|
|
862
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
|
|
796
863
|
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>`));
|
|
864
|
+
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
865
|
});
|
|
810
866
|
it('should render a developer layout node with text nodes inside a layout-raw layout', async () => {
|
|
811
867
|
const developerLayoutNode = {
|
|
@@ -815,10 +871,24 @@ describe('renderLayout', () => {
|
|
|
815
871
|
template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
|
|
816
872
|
name: 'article-layout',
|
|
817
873
|
options: {},
|
|
874
|
+
zones: {
|
|
875
|
+
title: {
|
|
876
|
+
displayName: 'Title Zone',
|
|
877
|
+
description: 'Title Zone Description',
|
|
878
|
+
minNodes: 1,
|
|
879
|
+
},
|
|
880
|
+
body: {
|
|
881
|
+
displayName: 'Body Zone',
|
|
882
|
+
description: 'Body Zone Description',
|
|
883
|
+
minNodes: 1,
|
|
884
|
+
},
|
|
885
|
+
},
|
|
818
886
|
},
|
|
819
887
|
content: {
|
|
820
|
-
title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
|
|
821
|
-
body: [
|
|
888
|
+
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
889
|
+
body: [
|
|
890
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
891
|
+
],
|
|
822
892
|
},
|
|
823
893
|
};
|
|
824
894
|
const layout = {
|
|
@@ -839,6 +909,13 @@ describe('renderLayout', () => {
|
|
|
839
909
|
template: '<div class="inner-layout">{{zones.innerContent}}</div>',
|
|
840
910
|
name: 'inner-dev-layout',
|
|
841
911
|
options: {},
|
|
912
|
+
zones: {
|
|
913
|
+
innerContent: {
|
|
914
|
+
displayName: 'Inner Content Zone',
|
|
915
|
+
description: 'Inner Content Zone Description',
|
|
916
|
+
minNodes: 0,
|
|
917
|
+
},
|
|
918
|
+
},
|
|
842
919
|
},
|
|
843
920
|
content: {
|
|
844
921
|
innerContent: [mockBuilder.createNodeWithId('component', 'inner-component')],
|
|
@@ -851,20 +928,26 @@ describe('renderLayout', () => {
|
|
|
851
928
|
template: '<div class="outer-layout">{{zones.outerContent}}</div>',
|
|
852
929
|
name: 'outer-dev-layout',
|
|
853
930
|
options: {},
|
|
931
|
+
zones: {
|
|
932
|
+
outerContent: {
|
|
933
|
+
displayName: 'Outer Content Zone',
|
|
934
|
+
description: 'Outer Content Zone Description',
|
|
935
|
+
minNodes: 0,
|
|
936
|
+
},
|
|
937
|
+
},
|
|
854
938
|
},
|
|
855
939
|
content: {
|
|
856
940
|
outerContent: [innerLayoutNode],
|
|
857
941
|
},
|
|
858
942
|
};
|
|
859
|
-
const layout = new mocks_1.
|
|
943
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayoutNode).build();
|
|
860
944
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
861
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(
|
|
945
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`
|
|
862
946
|
<div class="outer-layout">
|
|
863
947
|
<div class="inner-layout">
|
|
864
948
|
<esi:include src="${config.componentRootUrl}/r/inner-component?_componentSet=my-component-set&_contentItemId=123"/>
|
|
865
949
|
</div>
|
|
866
|
-
</div
|
|
867
|
-
</div>`));
|
|
950
|
+
</div>`));
|
|
868
951
|
});
|
|
869
952
|
it('should handle deeply nested layout nodes', async () => {
|
|
870
953
|
const mockBuilder = new mocks_1.MockNodeFactory();
|
|
@@ -874,6 +957,13 @@ describe('renderLayout', () => {
|
|
|
874
957
|
layout: {
|
|
875
958
|
template: '<section class="level-3">{{zones.content}}</section>',
|
|
876
959
|
name: 'level-3-layout',
|
|
960
|
+
zones: {
|
|
961
|
+
content: {
|
|
962
|
+
displayName: 'Content Zone',
|
|
963
|
+
description: 'Content Zone Description',
|
|
964
|
+
minNodes: 0,
|
|
965
|
+
},
|
|
966
|
+
},
|
|
877
967
|
options: {},
|
|
878
968
|
},
|
|
879
969
|
content: {
|
|
@@ -886,6 +976,13 @@ describe('renderLayout', () => {
|
|
|
886
976
|
layout: {
|
|
887
977
|
template: '<article class="level-2">{{zones.nestedContent}}</article>',
|
|
888
978
|
name: 'level-2-layout',
|
|
979
|
+
zones: {
|
|
980
|
+
nestedContent: {
|
|
981
|
+
displayName: 'Nested Content Zone',
|
|
982
|
+
description: 'Nested Content Zone Description',
|
|
983
|
+
minNodes: 0,
|
|
984
|
+
},
|
|
985
|
+
},
|
|
889
986
|
options: {},
|
|
890
987
|
},
|
|
891
988
|
content: {
|
|
@@ -899,6 +996,13 @@ describe('renderLayout', () => {
|
|
|
899
996
|
template: '<div class="level-1">{{zones.rootContent}}</div>',
|
|
900
997
|
name: 'level-1-layout',
|
|
901
998
|
options: {},
|
|
999
|
+
zones: {
|
|
1000
|
+
rootContent: {
|
|
1001
|
+
displayName: 'Inner Content Zone',
|
|
1002
|
+
description: 'Inner Content Zone Description',
|
|
1003
|
+
minNodes: 0,
|
|
1004
|
+
},
|
|
1005
|
+
},
|
|
902
1006
|
},
|
|
903
1007
|
content: {
|
|
904
1008
|
rootContent: [level2Layout],
|
|
@@ -928,9 +1032,21 @@ describe('renderLayout', () => {
|
|
|
928
1032
|
template: '<div class="inner-mixed"><h2>{{zones.heading}}</h2><div>{{zones.content}}</div></div>',
|
|
929
1033
|
name: 'inner-mixed-layout',
|
|
930
1034
|
options: {},
|
|
1035
|
+
zones: {
|
|
1036
|
+
heading: {
|
|
1037
|
+
displayName: 'Heading Zone',
|
|
1038
|
+
description: 'Heading Zone Description',
|
|
1039
|
+
minNodes: 0,
|
|
1040
|
+
},
|
|
1041
|
+
content: {
|
|
1042
|
+
displayName: 'Content Zone',
|
|
1043
|
+
description: 'Content Zone Description',
|
|
1044
|
+
minNodes: 0,
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
931
1047
|
},
|
|
932
1048
|
content: {
|
|
933
|
-
heading: [{ type: 'text', value: 'Inner Heading', nodeId: (0, crypto_1.randomUUID)() }],
|
|
1049
|
+
heading: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner Heading' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
934
1050
|
content: [mockBuilder.createNodeWithId('component', 'inner-mixed-component')],
|
|
935
1051
|
},
|
|
936
1052
|
};
|
|
@@ -941,16 +1057,29 @@ describe('renderLayout', () => {
|
|
|
941
1057
|
template: '<div class="outer-mixed"><div class="intro">{{zones.intro}}</div><div class="main">{{zones.main}}</div></div>',
|
|
942
1058
|
name: 'outer-mixed-layout',
|
|
943
1059
|
options: {},
|
|
1060
|
+
zones: {
|
|
1061
|
+
intro: {
|
|
1062
|
+
displayName: 'Intro Zone',
|
|
1063
|
+
description: 'Intro Zone Description',
|
|
1064
|
+
minNodes: 0,
|
|
1065
|
+
},
|
|
1066
|
+
main: {
|
|
1067
|
+
displayName: 'Main Zone',
|
|
1068
|
+
description: 'Main Zone Description',
|
|
1069
|
+
minNodes: 0,
|
|
1070
|
+
},
|
|
1071
|
+
},
|
|
944
1072
|
},
|
|
945
1073
|
content: {
|
|
946
|
-
intro: [
|
|
1074
|
+
intro: [
|
|
1075
|
+
{ type: 'fragment', children: [{ type: 'text', value: '<p>Introduction text</p>' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
1076
|
+
],
|
|
947
1077
|
main: [innerLayout],
|
|
948
1078
|
},
|
|
949
1079
|
};
|
|
950
|
-
const layout = new mocks_1.
|
|
1080
|
+
const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayout).build();
|
|
951
1081
|
const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
|
|
952
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="
|
|
953
|
-
<div class="outer-mixed">
|
|
1082
|
+
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-mixed">
|
|
954
1083
|
<div class="intro"><p>Introduction text</p></div>
|
|
955
1084
|
<div class="main">
|
|
956
1085
|
<div class="inner-mixed">
|
|
@@ -960,8 +1089,21 @@ describe('renderLayout', () => {
|
|
|
960
1089
|
</div>
|
|
961
1090
|
</div>
|
|
962
1091
|
</div>
|
|
963
|
-
</div
|
|
964
|
-
|
|
1092
|
+
</div>`));
|
|
1093
|
+
});
|
|
1094
|
+
it('should add HTML comments for all content nodes in preview mode', async () => {
|
|
1095
|
+
const layout = {
|
|
1096
|
+
name: 'layout-raw',
|
|
1097
|
+
content: {
|
|
1098
|
+
main: [mocks_1.VALID_CONTENT_NODES.component, mocks_1.VALID_CONTENT_NODES.fragment],
|
|
1099
|
+
},
|
|
1100
|
+
};
|
|
1101
|
+
const result = normalizeHtml(await (0, page_contents_lib_1.renderLayout)(layout, { ...config, isPreview: true }));
|
|
1102
|
+
expect(result).toContain(`<!-- start:component:${mocks_1.VALID_CONTENT_NODES.component.componentId}:${mocks_1.VALID_CONTENT_NODES.component.nodeId} -->`);
|
|
1103
|
+
expect(result).toContain(`<!-- end:component:${mocks_1.VALID_CONTENT_NODES.component.componentId}:${mocks_1.VALID_CONTENT_NODES.component.nodeId} -->`);
|
|
1104
|
+
expect(result).toContain(`<!-- start:fragment:text:${mocks_1.VALID_CONTENT_NODES.fragment.nodeId} -->`);
|
|
1105
|
+
expect(result).toContain(`<!-- end:fragment:text:${mocks_1.VALID_CONTENT_NODES.fragment.nodeId} -->`);
|
|
1106
|
+
expect(result).toMatchInlineSnapshot(`"<!-- start:component:my-component-1:${mocks_1.VALID_CONTENT_NODES.component.nodeId} --><esi:include src="https://mock.url/__dxp/service/components-render/r/my-component-1?_componentSet=my-component-set&_contentItemId=123&_previewBlockIndex=0"/><!-- end:component:my-component-1:${mocks_1.VALID_CONTENT_NODES.component.nodeId} --><!-- start:fragment:text:${mocks_1.VALID_CONTENT_NODES.fragment.nodeId} --><!-- end:fragment:text:${mocks_1.VALID_CONTENT_NODES.fragment.nodeId} -->"`);
|
|
965
1107
|
});
|
|
966
1108
|
it('should add HTML comments for developer defined layouts in preview mode', async () => {
|
|
967
1109
|
const developerLayoutNode = {
|
|
@@ -971,10 +1113,24 @@ describe('renderLayout', () => {
|
|
|
971
1113
|
template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
|
|
972
1114
|
name: 'article-layout',
|
|
973
1115
|
options: {},
|
|
1116
|
+
zones: {
|
|
1117
|
+
title: {
|
|
1118
|
+
displayName: 'Title Zone',
|
|
1119
|
+
description: 'Title Zone Description',
|
|
1120
|
+
minNodes: 1,
|
|
1121
|
+
},
|
|
1122
|
+
body: {
|
|
1123
|
+
displayName: 'Body Zone',
|
|
1124
|
+
description: 'Body Zone Description',
|
|
1125
|
+
minNodes: 1,
|
|
1126
|
+
},
|
|
1127
|
+
},
|
|
974
1128
|
},
|
|
975
1129
|
content: {
|
|
976
|
-
title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
|
|
977
|
-
body: [
|
|
1130
|
+
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
1131
|
+
body: [
|
|
1132
|
+
{ type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
1133
|
+
],
|
|
978
1134
|
},
|
|
979
1135
|
};
|
|
980
1136
|
const contentPage = {
|
|
@@ -983,8 +1139,17 @@ describe('renderLayout', () => {
|
|
|
983
1139
|
main: [developerLayoutNode],
|
|
984
1140
|
},
|
|
985
1141
|
};
|
|
986
|
-
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
|
|
987
|
-
expect(
|
|
1142
|
+
const result = normalizeHtml(await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true }));
|
|
1143
|
+
expect(result).toContain(`<!-- start:layout:article-layout:${developerLayoutNode.nodeId} -->`);
|
|
1144
|
+
expect(result).toContain(`<!-- end:layout:article-layout:${developerLayoutNode.nodeId} -->`);
|
|
1145
|
+
expect(result).toContain(`<!-- start:zone:title:${developerLayoutNode.nodeId} -->`);
|
|
1146
|
+
expect(result).toContain(`<!-- end:zone:title:${developerLayoutNode.nodeId} -->`);
|
|
1147
|
+
expect(result).toContain(`<!-- start:zone:body:${developerLayoutNode.nodeId} -->`);
|
|
1148
|
+
expect(result).toContain(`<!-- end:zone:body:${developerLayoutNode.nodeId} -->`);
|
|
1149
|
+
expect(result).toContain(`<!-- start:fragment:text:${developerLayoutNode.content.title[0].nodeId} -->`);
|
|
1150
|
+
expect(result).toContain(`<!-- end:fragment:text:${developerLayoutNode.content.title[0].nodeId} -->`);
|
|
1151
|
+
expect(result).toContain(`<!-- start:fragment:text:${developerLayoutNode.content.body[0].nodeId} -->`);
|
|
1152
|
+
expect(result).toContain(`<!-- end:fragment:text:${developerLayoutNode.content.body[0].nodeId} -->`);
|
|
988
1153
|
});
|
|
989
1154
|
it('should use the correct nodeId in the HTML comments for nested layouts', async () => {
|
|
990
1155
|
const innerLayoutNode = {
|
|
@@ -994,9 +1159,16 @@ describe('renderLayout', () => {
|
|
|
994
1159
|
template: '<div class="inner-layout">{{zones.content}}</div>',
|
|
995
1160
|
name: 'inner-layout',
|
|
996
1161
|
options: {},
|
|
1162
|
+
zones: {
|
|
1163
|
+
content: {
|
|
1164
|
+
displayName: 'Content Zone',
|
|
1165
|
+
description: 'Content Zone Description',
|
|
1166
|
+
minNodes: 0,
|
|
1167
|
+
},
|
|
1168
|
+
},
|
|
997
1169
|
},
|
|
998
1170
|
content: {
|
|
999
|
-
content: [{ type: 'text', value: 'Inner content', nodeId: (0, crypto_1.randomUUID)() }],
|
|
1171
|
+
content: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner content' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
1000
1172
|
},
|
|
1001
1173
|
};
|
|
1002
1174
|
const developerLayoutNode = {
|
|
@@ -1006,6 +1178,13 @@ describe('renderLayout', () => {
|
|
|
1006
1178
|
template: '<div class="outer-layout">{{zones.content}}</div>',
|
|
1007
1179
|
name: 'outer-layout',
|
|
1008
1180
|
options: {},
|
|
1181
|
+
zones: {
|
|
1182
|
+
content: {
|
|
1183
|
+
displayName: 'Content Zone',
|
|
1184
|
+
description: 'Content Zone Description',
|
|
1185
|
+
minNodes: 0,
|
|
1186
|
+
},
|
|
1187
|
+
},
|
|
1009
1188
|
},
|
|
1010
1189
|
content: {
|
|
1011
1190
|
content: [innerLayoutNode],
|
|
@@ -1018,7 +1197,8 @@ describe('renderLayout', () => {
|
|
|
1018
1197
|
},
|
|
1019
1198
|
};
|
|
1020
1199
|
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
|
|
1021
|
-
const
|
|
1200
|
+
const innerContentOutput = `<!-- start:fragment:text:${innerLayoutNode.content.content[0].nodeId} -->Inner content<!-- end:fragment:text:${innerLayoutNode.content.content[0].nodeId} -->`;
|
|
1201
|
+
const expectedInnerHtml = `<!-- start:layout:inner-layout:${innerLayoutNode.nodeId} --><div class="inner-layout"><!-- start:zone:content:${innerLayoutNode.nodeId} -->${innerContentOutput}<!-- end:zone:content:${innerLayoutNode.nodeId} --></div><!-- end:layout:inner-layout:${innerLayoutNode.nodeId} -->`;
|
|
1022
1202
|
expect(normalizeHtml(result)).toBe(normalizeHtml(`<!-- start:layout:outer-layout:${developerLayoutNode.nodeId} --><div class="outer-layout"><!-- start:zone:content:${developerLayoutNode.nodeId} -->${expectedInnerHtml}<!-- end:zone:content:${developerLayoutNode.nodeId} --></div><!-- end:layout:outer-layout:${developerLayoutNode.nodeId} -->`));
|
|
1023
1203
|
});
|
|
1024
1204
|
it('should allow fragment nodes in layout content', async () => {
|
|
@@ -1029,12 +1209,19 @@ describe('renderLayout', () => {
|
|
|
1029
1209
|
template: '<div class="outer-layout">{{zones.content}}</div>',
|
|
1030
1210
|
name: 'outer-layout',
|
|
1031
1211
|
options: {},
|
|
1212
|
+
zones: {
|
|
1213
|
+
content: {
|
|
1214
|
+
displayName: 'Content Zone',
|
|
1215
|
+
description: 'Content Zone Description',
|
|
1216
|
+
minNodes: 0,
|
|
1217
|
+
},
|
|
1218
|
+
},
|
|
1032
1219
|
},
|
|
1033
1220
|
content: {
|
|
1034
1221
|
content: [
|
|
1035
1222
|
{
|
|
1036
1223
|
type: 'fragment',
|
|
1037
|
-
children: [{ type: 'text', value: 'Fragment content'
|
|
1224
|
+
children: [{ type: 'text', value: 'Fragment content' }],
|
|
1038
1225
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1039
1226
|
},
|
|
1040
1227
|
],
|
|
@@ -1049,195 +1236,51 @@ describe('renderLayout', () => {
|
|
|
1049
1236
|
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, config);
|
|
1050
1237
|
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-layout">Fragment content</div>`));
|
|
1051
1238
|
});
|
|
1052
|
-
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
children: [
|
|
1066
|
-
{
|
|
1067
|
-
type: 'text',
|
|
1068
|
-
value: 'English text',
|
|
1069
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1239
|
+
it('should add preview demarcation comments for layout zones that are not present in the content', async () => {
|
|
1240
|
+
const developerLayoutNode = {
|
|
1241
|
+
type: 'layout',
|
|
1242
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1243
|
+
layout: {
|
|
1244
|
+
template: '<div class="outer-layout"><div>{{zones.content}}</div><div>{{zones.emptyZone}}</div></div>',
|
|
1245
|
+
name: 'outer-layout',
|
|
1246
|
+
options: {},
|
|
1247
|
+
zones: {
|
|
1248
|
+
content: {
|
|
1249
|
+
displayName: 'Content Zone',
|
|
1250
|
+
description: 'Content Zone Description',
|
|
1251
|
+
minNodes: 0,
|
|
1070
1252
|
},
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
{
|
|
1076
|
-
type: 'text',
|
|
1077
|
-
value: 'French text',
|
|
1078
|
-
},
|
|
1079
|
-
],
|
|
1253
|
+
emptyZone: {
|
|
1254
|
+
displayName: 'Empty Zone',
|
|
1255
|
+
description: 'Empty Zone Description',
|
|
1256
|
+
minNodes: 0,
|
|
1080
1257
|
},
|
|
1081
1258
|
},
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">French text</div>'));
|
|
1086
|
-
});
|
|
1087
|
-
it('should render translated component nodes', async () => {
|
|
1088
|
-
const layout = new mocks_1.PageSingleColumLayoutBuilder()
|
|
1089
|
-
.addNode({
|
|
1090
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1091
|
-
type: 'component',
|
|
1092
|
-
componentId: 'test/component/1.0.0',
|
|
1093
|
-
componentSet: 'test-set',
|
|
1094
|
-
componentType: 'server',
|
|
1095
|
-
contentItem: { id: 'en-content' },
|
|
1096
|
-
i18n: {
|
|
1097
|
-
fr: { id: 'fr-content' },
|
|
1098
|
-
},
|
|
1099
|
-
})
|
|
1100
|
-
.build();
|
|
1101
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1102
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container"><esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/></div>`));
|
|
1103
|
-
});
|
|
1104
|
-
it('should render mixed translated and untranslated nodes', async () => {
|
|
1105
|
-
const layout = new mocks_1.PageSingleColumLayoutBuilder()
|
|
1106
|
-
.addNode({
|
|
1107
|
-
// Translated fragment
|
|
1108
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1109
|
-
type: 'fragment',
|
|
1110
|
-
children: [
|
|
1259
|
+
},
|
|
1260
|
+
content: {
|
|
1261
|
+
content: [
|
|
1111
1262
|
{
|
|
1112
|
-
type: '
|
|
1113
|
-
value: '
|
|
1263
|
+
type: 'fragment',
|
|
1264
|
+
children: [{ type: 'text', value: 'Fragment content' }],
|
|
1114
1265
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1115
1266
|
},
|
|
1116
1267
|
],
|
|
1117
|
-
i18n: {
|
|
1118
|
-
fr: {
|
|
1119
|
-
children: [
|
|
1120
|
-
{
|
|
1121
|
-
type: 'text',
|
|
1122
|
-
value: 'French text',
|
|
1123
|
-
},
|
|
1124
|
-
],
|
|
1125
|
-
},
|
|
1126
|
-
},
|
|
1127
|
-
})
|
|
1128
|
-
.addNode({
|
|
1129
|
-
// Untranslated component
|
|
1130
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1131
|
-
type: 'component',
|
|
1132
|
-
componentId: 'test/component/1.0.0',
|
|
1133
|
-
componentSet: 'test-set',
|
|
1134
|
-
componentType: 'server',
|
|
1135
|
-
contentItem: { id: 'en-content' },
|
|
1136
|
-
})
|
|
1137
|
-
.build();
|
|
1138
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1139
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/></div>`));
|
|
1140
|
-
});
|
|
1141
|
-
it('should render developer layout with translated content', async () => {
|
|
1142
|
-
const developerLayoutNode = {
|
|
1143
|
-
type: 'layout',
|
|
1144
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1145
|
-
layout: {
|
|
1146
|
-
template: '<div class="top">{{zones.top}}</div><div class="side">{{zones.side}}</div>',
|
|
1147
|
-
name: 'article-layout',
|
|
1148
|
-
options: {},
|
|
1149
|
-
},
|
|
1150
|
-
content: {
|
|
1151
|
-
top: [
|
|
1152
|
-
{
|
|
1153
|
-
type: 'component',
|
|
1154
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1155
|
-
componentId: 'test/component/1.0.0',
|
|
1156
|
-
componentSet: 'test-set',
|
|
1157
|
-
componentType: 'server',
|
|
1158
|
-
contentItem: { id: 'en-top' },
|
|
1159
|
-
i18n: {
|
|
1160
|
-
fr: { id: 'fr-top' },
|
|
1161
|
-
},
|
|
1162
|
-
},
|
|
1163
|
-
],
|
|
1164
|
-
side: [
|
|
1165
|
-
{
|
|
1166
|
-
type: 'component',
|
|
1167
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1168
|
-
componentId: 'test/component/1.0.0',
|
|
1169
|
-
componentSet: 'test-set',
|
|
1170
|
-
componentType: 'server',
|
|
1171
|
-
contentItem: { id: 'en-side' },
|
|
1172
|
-
i18n: {
|
|
1173
|
-
fr: { id: 'fr-side' },
|
|
1174
|
-
},
|
|
1175
|
-
},
|
|
1176
|
-
],
|
|
1177
|
-
},
|
|
1178
|
-
};
|
|
1179
|
-
const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(developerLayoutNode).build();
|
|
1180
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1181
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
|
|
1182
|
-
<div class="top">
|
|
1183
|
-
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-top"/>
|
|
1184
|
-
</div>
|
|
1185
|
-
<div class="side">
|
|
1186
|
-
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-side"/>
|
|
1187
|
-
</div>
|
|
1188
|
-
</div>`));
|
|
1189
|
-
});
|
|
1190
|
-
it('should render layout with no translations when language config is missing', async () => {
|
|
1191
|
-
const layout = new mocks_1.PageSingleColumLayoutBuilder()
|
|
1192
|
-
.addNode({
|
|
1193
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1194
|
-
type: 'fragment',
|
|
1195
|
-
children: [
|
|
1196
|
-
{
|
|
1197
|
-
type: 'text',
|
|
1198
|
-
value: 'English text',
|
|
1199
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1200
|
-
},
|
|
1201
|
-
],
|
|
1202
|
-
i18n: {
|
|
1203
|
-
fr: {
|
|
1204
|
-
children: [
|
|
1205
|
-
{
|
|
1206
|
-
type: 'text',
|
|
1207
|
-
value: 'French text',
|
|
1208
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1209
|
-
},
|
|
1210
|
-
],
|
|
1211
|
-
},
|
|
1212
|
-
},
|
|
1213
|
-
})
|
|
1214
|
-
.build();
|
|
1215
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, config); // Using config without lang
|
|
1216
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">English text</div>'));
|
|
1217
|
-
});
|
|
1218
|
-
});
|
|
1219
|
-
});
|
|
1220
|
-
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
1268
|
},
|
|
1269
|
+
};
|
|
1270
|
+
const contentPage = {
|
|
1271
|
+
name: 'layout-raw',
|
|
1229
1272
|
content: {
|
|
1230
|
-
|
|
1273
|
+
main: [developerLayoutNode],
|
|
1231
1274
|
},
|
|
1232
1275
|
};
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
};
|
|
1239
|
-
expect((0, page_contents_lib_1.isDeveloperDefinedLayoutNode)(layoutNode)).toEqual(false);
|
|
1276
|
+
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
|
|
1277
|
+
expect(result).toContain(`<!-- start:zone:content:${developerLayoutNode.nodeId} -->`);
|
|
1278
|
+
expect(result).toContain(`<!-- start:fragment:text:${developerLayoutNode.content.content[0].nodeId} -->Fragment content<!-- end:fragment:text:${developerLayoutNode.content.content[0].nodeId} -->`);
|
|
1279
|
+
expect(result).toContain(`<!-- end:zone:content:${developerLayoutNode.nodeId} -->`);
|
|
1280
|
+
expect(result).toContain(`<!-- start:zone:emptyZone:${developerLayoutNode.nodeId} --><!-- end:zone:emptyZone:${developerLayoutNode.nodeId} -->`);
|
|
1240
1281
|
});
|
|
1282
|
+
});
|
|
1283
|
+
describe('Helper functions', () => {
|
|
1241
1284
|
it('isCustomLayout returns true for valid custom layouts', () => {
|
|
1242
1285
|
const layout = new mocks_1.CustomLayoutBuilder({
|
|
1243
1286
|
rootWrapper: {
|
|
@@ -1257,541 +1300,1082 @@ describe('Helper functions', () => {
|
|
|
1257
1300
|
expect((0, page_contents_lib_1.isCustomLayout)(layout)).toEqual(false);
|
|
1258
1301
|
});
|
|
1259
1302
|
});
|
|
1260
|
-
describe('
|
|
1261
|
-
const
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1303
|
+
describe('translatePageContents', () => {
|
|
1304
|
+
const mockPageContents = {
|
|
1305
|
+
id: 'test-page-1',
|
|
1306
|
+
name: 'Test Page',
|
|
1307
|
+
config: {
|
|
1308
|
+
languages: {
|
|
1309
|
+
fr: {
|
|
1310
|
+
fallbackToDefault: true,
|
|
1311
|
+
},
|
|
1312
|
+
es: {
|
|
1313
|
+
fallbackToDefault: false,
|
|
1314
|
+
},
|
|
1315
|
+
},
|
|
1266
1316
|
},
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1317
|
+
layouts: [
|
|
1318
|
+
{
|
|
1319
|
+
name: 'single-column',
|
|
1320
|
+
content: {
|
|
1321
|
+
main: [
|
|
1322
|
+
{
|
|
1323
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1324
|
+
type: 'fragment',
|
|
1325
|
+
children: [
|
|
1326
|
+
{
|
|
1327
|
+
type: 'text',
|
|
1328
|
+
value: 'English text',
|
|
1329
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1330
|
+
},
|
|
1331
|
+
],
|
|
1332
|
+
i18n: {
|
|
1333
|
+
fr: {
|
|
1334
|
+
children: [
|
|
1335
|
+
{
|
|
1336
|
+
type: 'text',
|
|
1337
|
+
value: 'French text',
|
|
1338
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1339
|
+
},
|
|
1340
|
+
],
|
|
1341
|
+
},
|
|
1281
1342
|
},
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1346
|
+
type: 'component',
|
|
1347
|
+
componentId: 'test/component/1.0.0',
|
|
1348
|
+
componentSet: 'test-set',
|
|
1349
|
+
componentType: 'edge',
|
|
1350
|
+
contentItem: { id: 'en-content' },
|
|
1351
|
+
i18n: {
|
|
1352
|
+
fr: { id: 'fr-content' },
|
|
1291
1353
|
},
|
|
1292
1354
|
},
|
|
1293
|
-
|
|
1294
|
-
|
|
1355
|
+
],
|
|
1356
|
+
},
|
|
1295
1357
|
},
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1358
|
+
{
|
|
1359
|
+
name: 'two-column',
|
|
1360
|
+
content: {
|
|
1361
|
+
left: [
|
|
1362
|
+
{
|
|
1363
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1364
|
+
type: 'fragment',
|
|
1365
|
+
children: [
|
|
1366
|
+
{
|
|
1367
|
+
type: 'text',
|
|
1368
|
+
value: 'Left English',
|
|
1369
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1370
|
+
},
|
|
1371
|
+
],
|
|
1372
|
+
i18n: {
|
|
1373
|
+
fr: {
|
|
1374
|
+
children: [
|
|
1375
|
+
{
|
|
1376
|
+
type: 'text',
|
|
1377
|
+
value: 'Left French',
|
|
1378
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1379
|
+
},
|
|
1380
|
+
],
|
|
1381
|
+
},
|
|
1382
|
+
},
|
|
1383
|
+
},
|
|
1384
|
+
],
|
|
1385
|
+
right: [
|
|
1386
|
+
{
|
|
1387
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1388
|
+
type: 'component',
|
|
1389
|
+
componentId: 'test/component/1.0.0',
|
|
1390
|
+
componentSet: 'test-set',
|
|
1391
|
+
componentType: 'edge',
|
|
1392
|
+
contentItem: { id: 'right-en-content' },
|
|
1393
|
+
i18n: {
|
|
1394
|
+
fr: { id: 'right-fr-content' },
|
|
1395
|
+
},
|
|
1396
|
+
},
|
|
1397
|
+
],
|
|
1398
|
+
},
|
|
1399
|
+
},
|
|
1400
|
+
],
|
|
1401
|
+
};
|
|
1402
|
+
it('should translate page contents to French when language config exists', () => {
|
|
1403
|
+
const pageContents = { ...mockPageContents };
|
|
1404
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1405
|
+
// Check first layout (single-column)
|
|
1406
|
+
const firstLayout = pageContents.layouts[0];
|
|
1407
|
+
const firstFragment = firstLayout.content.main[0];
|
|
1408
|
+
const firstComponent = firstLayout.content.main[1];
|
|
1409
|
+
expect(firstFragment.children[0].value).toBe('French text');
|
|
1410
|
+
expect(firstFragment).not.toHaveProperty('i18n');
|
|
1411
|
+
expect(firstComponent.contentItem).toEqual({ id: 'fr-content' });
|
|
1412
|
+
expect(firstComponent).not.toHaveProperty('i18n');
|
|
1413
|
+
// Check second layout (two-column)
|
|
1414
|
+
const secondLayout = pageContents.layouts[1];
|
|
1415
|
+
const leftFragment = secondLayout.content.left[0];
|
|
1416
|
+
const rightComponent = secondLayout.content.right[0];
|
|
1417
|
+
expect(leftFragment.children[0].value).toBe('Left French');
|
|
1418
|
+
expect(leftFragment).not.toHaveProperty('i18n');
|
|
1419
|
+
expect(rightComponent.contentItem).toEqual({ id: 'right-fr-content' });
|
|
1420
|
+
expect(rightComponent).not.toHaveProperty('i18n');
|
|
1300
1421
|
});
|
|
1301
|
-
it('should
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
children: [
|
|
1422
|
+
it('should fallback to default content when translation is not available and fallbackToDefault is true', () => {
|
|
1423
|
+
const pageContents = {
|
|
1424
|
+
...mockPageContents,
|
|
1425
|
+
layouts: [
|
|
1426
|
+
{
|
|
1427
|
+
name: 'single-column',
|
|
1428
|
+
content: {
|
|
1429
|
+
main: [
|
|
1310
1430
|
{
|
|
1311
|
-
type: 'text',
|
|
1312
|
-
value: 'English text',
|
|
1313
1431
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1314
|
-
|
|
1315
|
-
],
|
|
1316
|
-
i18n: {
|
|
1317
|
-
fr: {
|
|
1432
|
+
type: 'fragment',
|
|
1318
1433
|
children: [
|
|
1319
1434
|
{
|
|
1320
1435
|
type: 'text',
|
|
1321
|
-
value: '
|
|
1436
|
+
value: 'English text',
|
|
1322
1437
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1323
1438
|
},
|
|
1324
1439
|
],
|
|
1440
|
+
i18n: {
|
|
1441
|
+
// No French translation available
|
|
1442
|
+
},
|
|
1325
1443
|
},
|
|
1326
|
-
|
|
1327
|
-
},
|
|
1328
|
-
],
|
|
1329
|
-
},
|
|
1330
|
-
};
|
|
1331
|
-
(0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
|
|
1332
|
-
expect(layout.content.main[0].children[0].value).toBe('French text');
|
|
1333
|
-
});
|
|
1334
|
-
it('should translate component nodes when translation is available', () => {
|
|
1335
|
-
const layout = {
|
|
1336
|
-
name: 'layout-raw',
|
|
1337
|
-
content: {
|
|
1338
|
-
main: [
|
|
1339
|
-
{
|
|
1340
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1341
|
-
type: 'component',
|
|
1342
|
-
componentId: 'test/component/1.0.0',
|
|
1343
|
-
componentSet: 'test-set',
|
|
1344
|
-
componentType: 'edge',
|
|
1345
|
-
contentItem: { id: 'en-content' },
|
|
1346
|
-
i18n: {
|
|
1347
|
-
fr: { id: 'fr-content' },
|
|
1348
|
-
},
|
|
1444
|
+
],
|
|
1349
1445
|
},
|
|
1350
|
-
|
|
1351
|
-
|
|
1446
|
+
},
|
|
1447
|
+
],
|
|
1352
1448
|
};
|
|
1353
|
-
(0, page_contents_lib_1.
|
|
1354
|
-
|
|
1449
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1450
|
+
const fragment = pageContents.layouts[0].content.main[0];
|
|
1451
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
1452
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
1355
1453
|
});
|
|
1356
|
-
it('should fallback to default content when translation is not available and
|
|
1357
|
-
const
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
children: [
|
|
1454
|
+
it('should not fallback to default content when translation is not available and fallbackToDefault is false', () => {
|
|
1455
|
+
const pageContents = {
|
|
1456
|
+
...mockPageContents,
|
|
1457
|
+
layouts: [
|
|
1458
|
+
{
|
|
1459
|
+
name: 'single-column',
|
|
1460
|
+
content: {
|
|
1461
|
+
main: [
|
|
1365
1462
|
{
|
|
1366
|
-
type: 'text',
|
|
1367
|
-
value: 'English text',
|
|
1368
1463
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1369
|
-
|
|
1370
|
-
],
|
|
1371
|
-
i18n: {
|
|
1372
|
-
es: {
|
|
1464
|
+
type: 'fragment',
|
|
1373
1465
|
children: [
|
|
1374
1466
|
{
|
|
1375
1467
|
type: 'text',
|
|
1376
|
-
value: '
|
|
1468
|
+
value: 'English text',
|
|
1377
1469
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1378
1470
|
},
|
|
1379
1471
|
],
|
|
1472
|
+
i18n: {
|
|
1473
|
+
// No Spanish translation available
|
|
1474
|
+
},
|
|
1380
1475
|
},
|
|
1381
|
-
|
|
1382
|
-
},
|
|
1383
|
-
],
|
|
1384
|
-
},
|
|
1385
|
-
};
|
|
1386
|
-
(0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
|
|
1387
|
-
expect(layout.content.main[0].children[0].value).toBe('English text');
|
|
1388
|
-
});
|
|
1389
|
-
it('should skip translation for non-translatable node types', () => {
|
|
1390
|
-
const layout = {
|
|
1391
|
-
name: 'layout-raw',
|
|
1392
|
-
content: {
|
|
1393
|
-
main: [
|
|
1394
|
-
{
|
|
1395
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1396
|
-
type: 'variation',
|
|
1397
|
-
default: {
|
|
1398
|
-
node: {
|
|
1399
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1400
|
-
type: 'text',
|
|
1401
|
-
value: 'Default text',
|
|
1402
|
-
},
|
|
1403
|
-
},
|
|
1404
|
-
variants: [],
|
|
1476
|
+
],
|
|
1405
1477
|
},
|
|
1406
|
-
|
|
1407
|
-
|
|
1478
|
+
},
|
|
1479
|
+
],
|
|
1408
1480
|
};
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1481
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'es');
|
|
1482
|
+
// Should not be translated since fallbackToDefault is false for Spanish
|
|
1483
|
+
// The node should be removed from the array since no translation is available
|
|
1484
|
+
expect(pageContents.layouts[0].content.main).toHaveLength(0);
|
|
1412
1485
|
});
|
|
1413
|
-
it('should
|
|
1414
|
-
const
|
|
1415
|
-
...
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
name: 'layout-raw',
|
|
1423
|
-
content: {
|
|
1424
|
-
main: [
|
|
1425
|
-
{
|
|
1426
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1427
|
-
type: 'fragment',
|
|
1428
|
-
children: [
|
|
1486
|
+
it('should handle page contents without language config', () => {
|
|
1487
|
+
const pageContents = {
|
|
1488
|
+
...mockPageContents,
|
|
1489
|
+
config: undefined,
|
|
1490
|
+
layouts: [
|
|
1491
|
+
{
|
|
1492
|
+
name: 'single-column',
|
|
1493
|
+
content: {
|
|
1494
|
+
main: [
|
|
1429
1495
|
{
|
|
1430
|
-
type: 'text',
|
|
1431
|
-
value: 'English text',
|
|
1432
1496
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1433
|
-
|
|
1434
|
-
],
|
|
1435
|
-
i18n: {
|
|
1436
|
-
es: {
|
|
1497
|
+
type: 'fragment',
|
|
1437
1498
|
children: [
|
|
1438
1499
|
{
|
|
1439
1500
|
type: 'text',
|
|
1440
|
-
value: '
|
|
1501
|
+
value: 'English text',
|
|
1441
1502
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1442
1503
|
},
|
|
1443
1504
|
],
|
|
1505
|
+
i18n: {
|
|
1506
|
+
fr: {
|
|
1507
|
+
children: [
|
|
1508
|
+
{
|
|
1509
|
+
type: 'text',
|
|
1510
|
+
value: 'French text',
|
|
1511
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1512
|
+
},
|
|
1513
|
+
],
|
|
1514
|
+
},
|
|
1515
|
+
},
|
|
1444
1516
|
},
|
|
1445
|
-
|
|
1517
|
+
],
|
|
1446
1518
|
},
|
|
1447
|
-
|
|
1448
|
-
|
|
1519
|
+
},
|
|
1520
|
+
],
|
|
1449
1521
|
};
|
|
1450
|
-
(0, page_contents_lib_1.
|
|
1451
|
-
|
|
1522
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1523
|
+
// Should not translate since no language config exists
|
|
1524
|
+
// The i18n property should be removed but content preserved
|
|
1525
|
+
const fragment = pageContents.layouts[0].content.main[0];
|
|
1526
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
1527
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
1452
1528
|
});
|
|
1453
|
-
it('should
|
|
1454
|
-
const
|
|
1455
|
-
...
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1529
|
+
it('should handle page contents with language config but no specific language', () => {
|
|
1530
|
+
const pageContents = {
|
|
1531
|
+
...mockPageContents,
|
|
1532
|
+
config: {
|
|
1533
|
+
languages: {
|
|
1534
|
+
// No French config
|
|
1535
|
+
},
|
|
1459
1536
|
},
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
{
|
|
1466
|
-
// has both "fr" and "jp" translations
|
|
1467
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1468
|
-
type: 'fragment',
|
|
1469
|
-
children: [
|
|
1537
|
+
layouts: [
|
|
1538
|
+
{
|
|
1539
|
+
name: 'single-column',
|
|
1540
|
+
content: {
|
|
1541
|
+
main: [
|
|
1470
1542
|
{
|
|
1471
|
-
type: 'text',
|
|
1472
|
-
value: 'English text 1',
|
|
1473
1543
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1474
|
-
|
|
1475
|
-
],
|
|
1476
|
-
i18n: {
|
|
1477
|
-
fr: {
|
|
1544
|
+
type: 'fragment',
|
|
1478
1545
|
children: [
|
|
1479
1546
|
{
|
|
1480
1547
|
type: 'text',
|
|
1481
|
-
value: '
|
|
1548
|
+
value: 'English text',
|
|
1482
1549
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1483
1550
|
},
|
|
1484
1551
|
],
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1552
|
+
i18n: {
|
|
1553
|
+
fr: {
|
|
1554
|
+
children: [
|
|
1555
|
+
{
|
|
1556
|
+
type: 'text',
|
|
1557
|
+
value: 'French text',
|
|
1558
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1559
|
+
},
|
|
1560
|
+
],
|
|
1492
1561
|
},
|
|
1493
|
-
|
|
1562
|
+
},
|
|
1494
1563
|
},
|
|
1495
|
-
|
|
1564
|
+
],
|
|
1496
1565
|
},
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1566
|
+
},
|
|
1567
|
+
],
|
|
1568
|
+
};
|
|
1569
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1570
|
+
// Should not translate since no French language config exists
|
|
1571
|
+
// The i18n property should be removed but content preserved
|
|
1572
|
+
const fragment = pageContents.layouts[0].content.main[0];
|
|
1573
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
1574
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
1575
|
+
});
|
|
1576
|
+
it('should handle nested layout nodes in page contents', () => {
|
|
1577
|
+
const pageContents = {
|
|
1578
|
+
...mockPageContents,
|
|
1579
|
+
layouts: [
|
|
1580
|
+
{
|
|
1581
|
+
name: 'single-column',
|
|
1582
|
+
content: {
|
|
1583
|
+
main: [
|
|
1502
1584
|
{
|
|
1503
|
-
type: 'text',
|
|
1504
|
-
value: 'English text 2',
|
|
1505
1585
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1586
|
+
type: 'layout',
|
|
1587
|
+
layout: {
|
|
1588
|
+
template: '<div>{{zones.inner}}</div>',
|
|
1589
|
+
name: 'nested-layout',
|
|
1590
|
+
options: {},
|
|
1591
|
+
},
|
|
1592
|
+
content: {
|
|
1593
|
+
inner: [
|
|
1594
|
+
{
|
|
1595
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1596
|
+
type: 'fragment',
|
|
1597
|
+
children: [
|
|
1598
|
+
{
|
|
1599
|
+
type: 'text',
|
|
1600
|
+
value: 'Nested English',
|
|
1601
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1602
|
+
},
|
|
1603
|
+
],
|
|
1604
|
+
i18n: {
|
|
1605
|
+
fr: {
|
|
1606
|
+
children: [
|
|
1607
|
+
{
|
|
1608
|
+
type: 'text',
|
|
1609
|
+
value: 'Nested French',
|
|
1610
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1611
|
+
},
|
|
1612
|
+
],
|
|
1613
|
+
},
|
|
1614
|
+
},
|
|
1615
|
+
},
|
|
1616
|
+
],
|
|
1617
|
+
},
|
|
1506
1618
|
},
|
|
1507
1619
|
],
|
|
1508
|
-
|
|
1509
|
-
|
|
1620
|
+
},
|
|
1621
|
+
},
|
|
1622
|
+
],
|
|
1623
|
+
};
|
|
1624
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1625
|
+
const layoutNode = pageContents.layouts[0].content.main[0];
|
|
1626
|
+
const nestedFragment = layoutNode.content.inner[0];
|
|
1627
|
+
expect(nestedFragment.children[0].value).toBe('Nested French');
|
|
1628
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
1629
|
+
});
|
|
1630
|
+
it('should handle page contents with no layouts', () => {
|
|
1631
|
+
const pageContents = {
|
|
1632
|
+
...mockPageContents,
|
|
1633
|
+
layouts: [],
|
|
1634
|
+
};
|
|
1635
|
+
expect(() => (0, page_contents_lib_1.translatePageContents)(pageContents, 'fr')).not.toThrow();
|
|
1636
|
+
});
|
|
1637
|
+
it('should handle page contents with empty layout content', () => {
|
|
1638
|
+
const pageContents = {
|
|
1639
|
+
...mockPageContents,
|
|
1640
|
+
layouts: [
|
|
1641
|
+
{
|
|
1642
|
+
name: 'single-column',
|
|
1643
|
+
content: {
|
|
1644
|
+
main: [],
|
|
1645
|
+
},
|
|
1646
|
+
},
|
|
1647
|
+
],
|
|
1648
|
+
};
|
|
1649
|
+
expect(() => (0, page_contents_lib_1.translatePageContents)(pageContents, 'fr')).not.toThrow();
|
|
1650
|
+
});
|
|
1651
|
+
it('should handle mixed content types in layouts', () => {
|
|
1652
|
+
const pageContents = {
|
|
1653
|
+
...mockPageContents,
|
|
1654
|
+
layouts: [
|
|
1655
|
+
{
|
|
1656
|
+
name: 'single-column',
|
|
1657
|
+
content: {
|
|
1658
|
+
main: [
|
|
1659
|
+
{
|
|
1660
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1661
|
+
type: 'fragment',
|
|
1510
1662
|
children: [
|
|
1511
1663
|
{
|
|
1512
1664
|
type: 'text',
|
|
1513
|
-
value: '
|
|
1665
|
+
value: 'English fragment',
|
|
1514
1666
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1515
1667
|
},
|
|
1516
1668
|
],
|
|
1669
|
+
i18n: {
|
|
1670
|
+
fr: {
|
|
1671
|
+
children: [
|
|
1672
|
+
{
|
|
1673
|
+
type: 'text',
|
|
1674
|
+
value: 'French fragment',
|
|
1675
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1676
|
+
},
|
|
1677
|
+
],
|
|
1678
|
+
},
|
|
1679
|
+
},
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1683
|
+
type: 'component',
|
|
1684
|
+
componentId: 'test/component/1.0.0',
|
|
1685
|
+
componentSet: 'test-set',
|
|
1686
|
+
componentType: 'edge',
|
|
1687
|
+
contentItem: { id: 'en-component' },
|
|
1688
|
+
i18n: {
|
|
1689
|
+
fr: { id: 'fr-component' },
|
|
1690
|
+
},
|
|
1517
1691
|
},
|
|
1518
|
-
},
|
|
1519
|
-
},
|
|
1520
|
-
{
|
|
1521
|
-
// has no translations
|
|
1522
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1523
|
-
type: 'fragment',
|
|
1524
|
-
children: [
|
|
1525
1692
|
{
|
|
1526
|
-
type: 'text',
|
|
1527
|
-
value: 'English text 3',
|
|
1528
1693
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1694
|
+
type: 'variation',
|
|
1695
|
+
default: { node: null },
|
|
1696
|
+
variants: [],
|
|
1529
1697
|
},
|
|
1530
1698
|
],
|
|
1531
1699
|
},
|
|
1532
|
-
|
|
1533
|
-
|
|
1700
|
+
},
|
|
1701
|
+
],
|
|
1534
1702
|
};
|
|
1535
|
-
(0, page_contents_lib_1.
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1703
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1704
|
+
const mainContent = pageContents.layouts[0].content.main;
|
|
1705
|
+
const fragment = mainContent[0];
|
|
1706
|
+
const component = mainContent[1];
|
|
1707
|
+
const variation = mainContent[2];
|
|
1708
|
+
expect(fragment.children[0].value).toBe('French fragment');
|
|
1709
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
1710
|
+
expect(component.contentItem).toEqual({ id: 'fr-component' });
|
|
1711
|
+
expect(component).not.toHaveProperty('i18n');
|
|
1712
|
+
// Variation should remain unchanged
|
|
1713
|
+
expect(variation.type).toBe('variation');
|
|
1540
1714
|
});
|
|
1541
|
-
it('should
|
|
1542
|
-
const
|
|
1543
|
-
...
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1715
|
+
it('should handle language config with custom fallback settings', () => {
|
|
1716
|
+
const pageContents = {
|
|
1717
|
+
...mockPageContents,
|
|
1718
|
+
config: {
|
|
1719
|
+
languages: {
|
|
1720
|
+
fr: {
|
|
1721
|
+
fallbackToDefault: false,
|
|
1722
|
+
},
|
|
1723
|
+
},
|
|
1547
1724
|
},
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
{
|
|
1554
|
-
// has both "fr" and "jp" translations
|
|
1555
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1556
|
-
type: 'fragment',
|
|
1557
|
-
children: [
|
|
1725
|
+
layouts: [
|
|
1726
|
+
{
|
|
1727
|
+
name: 'single-column',
|
|
1728
|
+
content: {
|
|
1729
|
+
main: [
|
|
1558
1730
|
{
|
|
1559
|
-
type: 'text',
|
|
1560
|
-
value: 'English text 1',
|
|
1561
1731
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1562
|
-
|
|
1563
|
-
],
|
|
1564
|
-
i18n: {
|
|
1565
|
-
fr: {
|
|
1732
|
+
type: 'fragment',
|
|
1566
1733
|
children: [
|
|
1567
1734
|
{
|
|
1568
1735
|
type: 'text',
|
|
1569
|
-
value: '
|
|
1736
|
+
value: 'English text',
|
|
1570
1737
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1571
1738
|
},
|
|
1572
1739
|
],
|
|
1740
|
+
i18n: {
|
|
1741
|
+
// No French translation
|
|
1742
|
+
},
|
|
1573
1743
|
},
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1744
|
+
],
|
|
1745
|
+
},
|
|
1746
|
+
},
|
|
1747
|
+
],
|
|
1748
|
+
};
|
|
1749
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1750
|
+
// Should not be translated since fallbackToDefault is false and no translation exists
|
|
1751
|
+
// The node should be removed from the array since no translation is available
|
|
1752
|
+
expect(pageContents.layouts[0].content.main).toHaveLength(0);
|
|
1753
|
+
});
|
|
1754
|
+
it('should handle variant nodes with translatable default content', () => {
|
|
1755
|
+
const pageContents = {
|
|
1756
|
+
...mockPageContents,
|
|
1757
|
+
layouts: [
|
|
1758
|
+
{
|
|
1759
|
+
name: 'single-column',
|
|
1760
|
+
content: {
|
|
1761
|
+
main: [
|
|
1762
|
+
{
|
|
1763
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1764
|
+
type: 'variation',
|
|
1765
|
+
default: {
|
|
1766
|
+
node: {
|
|
1579
1767
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1768
|
+
type: 'fragment',
|
|
1769
|
+
children: [
|
|
1770
|
+
{
|
|
1771
|
+
type: 'text',
|
|
1772
|
+
value: 'Default English',
|
|
1773
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1774
|
+
},
|
|
1775
|
+
],
|
|
1776
|
+
i18n: {
|
|
1777
|
+
fr: {
|
|
1778
|
+
children: [
|
|
1779
|
+
{
|
|
1780
|
+
type: 'text',
|
|
1781
|
+
value: 'Default French',
|
|
1782
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1783
|
+
},
|
|
1784
|
+
],
|
|
1785
|
+
},
|
|
1786
|
+
},
|
|
1787
|
+
},
|
|
1788
|
+
},
|
|
1789
|
+
variants: [
|
|
1790
|
+
{
|
|
1791
|
+
conditions: { segment: { code: 'is-student' } },
|
|
1792
|
+
node: {
|
|
1793
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1794
|
+
type: 'fragment',
|
|
1795
|
+
children: [
|
|
1796
|
+
{
|
|
1797
|
+
type: 'text',
|
|
1798
|
+
value: 'Variant English',
|
|
1799
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1800
|
+
},
|
|
1801
|
+
],
|
|
1802
|
+
i18n: {
|
|
1803
|
+
fr: {
|
|
1804
|
+
children: [
|
|
1805
|
+
{
|
|
1806
|
+
type: 'text',
|
|
1807
|
+
value: 'Variant French',
|
|
1808
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1809
|
+
},
|
|
1810
|
+
],
|
|
1811
|
+
},
|
|
1812
|
+
},
|
|
1813
|
+
},
|
|
1580
1814
|
},
|
|
1581
1815
|
],
|
|
1582
1816
|
},
|
|
1583
|
-
|
|
1817
|
+
],
|
|
1584
1818
|
},
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1819
|
+
},
|
|
1820
|
+
],
|
|
1821
|
+
};
|
|
1822
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1823
|
+
const variation = pageContents.layouts[0].content.main[0];
|
|
1824
|
+
const defaultNode = variation.default.node;
|
|
1825
|
+
const variantNode = variation.variants[0].node;
|
|
1826
|
+
expect(defaultNode.children[0].value).toBe('Default French');
|
|
1827
|
+
expect(defaultNode).not.toHaveProperty('i18n');
|
|
1828
|
+
expect(variantNode.children[0].value).toBe('Variant French');
|
|
1829
|
+
expect(variantNode).not.toHaveProperty('i18n');
|
|
1830
|
+
});
|
|
1831
|
+
it('should handle variant nodes with translatable component content', () => {
|
|
1832
|
+
const pageContents = {
|
|
1833
|
+
...mockPageContents,
|
|
1834
|
+
layouts: [
|
|
1835
|
+
{
|
|
1836
|
+
name: 'single-column',
|
|
1837
|
+
content: {
|
|
1838
|
+
main: [
|
|
1590
1839
|
{
|
|
1591
|
-
type: 'text',
|
|
1592
|
-
value: 'English text 2',
|
|
1593
1840
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
fr: {
|
|
1598
|
-
children: [
|
|
1599
|
-
{
|
|
1600
|
-
type: 'text',
|
|
1601
|
-
value: 'French text 2',
|
|
1841
|
+
type: 'variation',
|
|
1842
|
+
default: {
|
|
1843
|
+
node: {
|
|
1602
1844
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1845
|
+
type: 'component',
|
|
1846
|
+
componentId: 'test/component/1.0.0',
|
|
1847
|
+
componentSet: 'test-set',
|
|
1848
|
+
componentType: 'edge',
|
|
1849
|
+
contentItem: { id: 'default-en' },
|
|
1850
|
+
i18n: {
|
|
1851
|
+
fr: { id: 'default-fr' },
|
|
1852
|
+
},
|
|
1853
|
+
},
|
|
1854
|
+
},
|
|
1855
|
+
variants: [
|
|
1856
|
+
{
|
|
1857
|
+
conditions: { experiment: { id: 'exp-1', variant: 'A' } },
|
|
1858
|
+
node: {
|
|
1859
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1860
|
+
type: 'component',
|
|
1861
|
+
componentId: 'test/component/1.0.0',
|
|
1862
|
+
componentSet: 'test-set',
|
|
1863
|
+
componentType: 'edge',
|
|
1864
|
+
contentItem: { id: 'variant-en' },
|
|
1865
|
+
i18n: {
|
|
1866
|
+
fr: { id: 'variant-fr' },
|
|
1867
|
+
},
|
|
1868
|
+
},
|
|
1603
1869
|
},
|
|
1604
1870
|
],
|
|
1605
1871
|
},
|
|
1606
|
-
|
|
1872
|
+
],
|
|
1607
1873
|
},
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1874
|
+
},
|
|
1875
|
+
],
|
|
1876
|
+
};
|
|
1877
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1878
|
+
const variation = pageContents.layouts[0].content.main[0];
|
|
1879
|
+
const defaultNode = variation.default.node;
|
|
1880
|
+
const variantNode = variation.variants[0].node;
|
|
1881
|
+
expect(defaultNode.contentItem).toEqual({ id: 'default-fr' });
|
|
1882
|
+
expect(defaultNode).not.toHaveProperty('i18n');
|
|
1883
|
+
expect(variantNode.contentItem).toEqual({ id: 'variant-fr' });
|
|
1884
|
+
expect(variantNode).not.toHaveProperty('i18n');
|
|
1885
|
+
});
|
|
1886
|
+
it('should handle variant nodes with nested layout content', () => {
|
|
1887
|
+
const pageContents = {
|
|
1888
|
+
...mockPageContents,
|
|
1889
|
+
layouts: [
|
|
1890
|
+
{
|
|
1891
|
+
name: 'single-column',
|
|
1892
|
+
content: {
|
|
1893
|
+
main: [
|
|
1613
1894
|
{
|
|
1614
|
-
type: 'text',
|
|
1615
|
-
value: 'English text 3',
|
|
1616
1895
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1896
|
+
type: 'variation',
|
|
1897
|
+
default: {
|
|
1898
|
+
node: {
|
|
1899
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1900
|
+
type: 'layout',
|
|
1901
|
+
layout: {
|
|
1902
|
+
template: '<div>{{zones.content}}</div>',
|
|
1903
|
+
name: 'nested-layout',
|
|
1904
|
+
options: {},
|
|
1905
|
+
},
|
|
1906
|
+
content: {
|
|
1907
|
+
content: [
|
|
1908
|
+
{
|
|
1909
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1910
|
+
type: 'fragment',
|
|
1911
|
+
children: [
|
|
1912
|
+
{
|
|
1913
|
+
type: 'text',
|
|
1914
|
+
value: 'Nested Default English',
|
|
1915
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1916
|
+
},
|
|
1917
|
+
],
|
|
1918
|
+
i18n: {
|
|
1919
|
+
fr: {
|
|
1920
|
+
children: [
|
|
1921
|
+
{
|
|
1922
|
+
type: 'text',
|
|
1923
|
+
value: 'Nested Default French',
|
|
1924
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1925
|
+
},
|
|
1926
|
+
],
|
|
1927
|
+
},
|
|
1928
|
+
},
|
|
1929
|
+
},
|
|
1930
|
+
],
|
|
1931
|
+
},
|
|
1932
|
+
},
|
|
1933
|
+
},
|
|
1934
|
+
variants: [
|
|
1935
|
+
{
|
|
1936
|
+
conditions: { segment: { code: 'is-premium' } },
|
|
1937
|
+
node: {
|
|
1938
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1939
|
+
type: 'layout',
|
|
1940
|
+
layout: {
|
|
1941
|
+
template: '<section>{{zones.content}}</section>',
|
|
1942
|
+
name: 'premium-layout',
|
|
1943
|
+
options: {},
|
|
1944
|
+
},
|
|
1945
|
+
content: {
|
|
1946
|
+
content: [
|
|
1947
|
+
{
|
|
1948
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1949
|
+
type: 'component',
|
|
1950
|
+
componentId: 'premium/component/1.0.0',
|
|
1951
|
+
componentSet: 'premium-set',
|
|
1952
|
+
componentType: 'edge',
|
|
1953
|
+
contentItem: { id: 'premium-en' },
|
|
1954
|
+
i18n: {
|
|
1955
|
+
fr: { id: 'premium-fr' },
|
|
1956
|
+
},
|
|
1957
|
+
},
|
|
1958
|
+
],
|
|
1959
|
+
},
|
|
1960
|
+
},
|
|
1961
|
+
},
|
|
1962
|
+
],
|
|
1617
1963
|
},
|
|
1618
1964
|
],
|
|
1619
1965
|
},
|
|
1620
|
-
|
|
1621
|
-
|
|
1966
|
+
},
|
|
1967
|
+
],
|
|
1622
1968
|
};
|
|
1623
|
-
(0, page_contents_lib_1.
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1969
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
1970
|
+
const variation = pageContents.layouts[0].content.main[0];
|
|
1971
|
+
const defaultLayout = variation.default.node;
|
|
1972
|
+
const variantLayout = variation.variants[0].node;
|
|
1973
|
+
// Check default layout content
|
|
1974
|
+
const defaultFragment = defaultLayout.content.content[0];
|
|
1975
|
+
expect(defaultFragment.children[0].value).toBe('Nested Default French');
|
|
1976
|
+
expect(defaultFragment).not.toHaveProperty('i18n');
|
|
1977
|
+
// Check variant layout content
|
|
1978
|
+
const variantComponent = variantLayout.content.content[0];
|
|
1979
|
+
expect(variantComponent.contentItem).toEqual({ id: 'premium-fr' });
|
|
1980
|
+
expect(variantComponent).not.toHaveProperty('i18n');
|
|
1627
1981
|
});
|
|
1628
|
-
it('should
|
|
1629
|
-
const
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
children: [
|
|
1982
|
+
it('should handle variant nodes with fallback behavior', () => {
|
|
1983
|
+
const pageContents = {
|
|
1984
|
+
...mockPageContents,
|
|
1985
|
+
layouts: [
|
|
1633
1986
|
{
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1987
|
+
name: 'single-column',
|
|
1988
|
+
content: {
|
|
1989
|
+
main: [
|
|
1990
|
+
{
|
|
1991
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1992
|
+
type: 'variation',
|
|
1993
|
+
default: {
|
|
1994
|
+
node: {
|
|
1995
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1996
|
+
type: 'fragment',
|
|
1997
|
+
children: [
|
|
1998
|
+
{
|
|
1999
|
+
type: 'text',
|
|
2000
|
+
value: 'Default English',
|
|
2001
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2002
|
+
},
|
|
2003
|
+
],
|
|
2004
|
+
i18n: {
|
|
2005
|
+
// No French translation
|
|
2006
|
+
},
|
|
2007
|
+
},
|
|
2008
|
+
},
|
|
2009
|
+
variants: [
|
|
2010
|
+
{
|
|
2011
|
+
conditions: { segment: { code: 'is-student' } },
|
|
2012
|
+
node: {
|
|
2013
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2014
|
+
type: 'fragment',
|
|
2015
|
+
children: [
|
|
2016
|
+
{
|
|
2017
|
+
type: 'text',
|
|
2018
|
+
value: 'Variant English',
|
|
2019
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2020
|
+
},
|
|
2021
|
+
],
|
|
2022
|
+
i18n: {
|
|
2023
|
+
fr: {
|
|
2024
|
+
children: [
|
|
2025
|
+
{
|
|
2026
|
+
type: 'text',
|
|
2027
|
+
value: 'Variant French',
|
|
2028
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2029
|
+
},
|
|
2030
|
+
],
|
|
2031
|
+
},
|
|
2032
|
+
},
|
|
2033
|
+
},
|
|
2034
|
+
},
|
|
2035
|
+
],
|
|
2036
|
+
},
|
|
2037
|
+
],
|
|
2038
|
+
},
|
|
1637
2039
|
},
|
|
1638
2040
|
],
|
|
1639
|
-
i18n: {
|
|
1640
|
-
fr: {
|
|
1641
|
-
children: [
|
|
1642
|
-
{
|
|
1643
|
-
type: 'text',
|
|
1644
|
-
value: 'French text',
|
|
1645
|
-
},
|
|
1646
|
-
],
|
|
1647
|
-
},
|
|
1648
|
-
},
|
|
1649
2041
|
};
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
2042
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
2043
|
+
const variation = pageContents.layouts[0].content.main[0];
|
|
2044
|
+
const defaultNode = variation.default.node;
|
|
2045
|
+
const variantNode = variation.variants[0].node;
|
|
2046
|
+
// Default should fallback to English since fallbackToDefault is true
|
|
2047
|
+
expect(defaultNode.children[0].value).toBe('Default English');
|
|
2048
|
+
expect(defaultNode).not.toHaveProperty('i18n');
|
|
2049
|
+
// Variant should be translated
|
|
2050
|
+
expect(variantNode.children[0].value).toBe('Variant French');
|
|
2051
|
+
expect(variantNode).not.toHaveProperty('i18n');
|
|
2052
|
+
});
|
|
2053
|
+
it('should handle variant nodes with no fallback when translation missing', () => {
|
|
2054
|
+
const pageContents = {
|
|
2055
|
+
...mockPageContents,
|
|
2056
|
+
config: {
|
|
2057
|
+
languages: {
|
|
2058
|
+
fr: {
|
|
2059
|
+
fallbackToDefault: false,
|
|
1665
2060
|
},
|
|
1666
|
-
|
|
2061
|
+
},
|
|
1667
2062
|
},
|
|
1668
|
-
|
|
1669
|
-
(0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
|
|
1670
|
-
// Verify the content inside the layout node is translated
|
|
1671
|
-
const layoutNode = layout.content.main[0];
|
|
1672
|
-
const translatedFragment = layoutNode.content.content[0];
|
|
1673
|
-
expect(translatedFragment.children[0].value).toBe('French text');
|
|
1674
|
-
});
|
|
1675
|
-
it('should translate multiple content sections in layout nodes', () => {
|
|
1676
|
-
const fragmentNode = {
|
|
1677
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1678
|
-
type: 'fragment',
|
|
1679
|
-
children: [
|
|
2063
|
+
layouts: [
|
|
1680
2064
|
{
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
2065
|
+
name: 'single-column',
|
|
2066
|
+
content: {
|
|
2067
|
+
main: [
|
|
2068
|
+
{
|
|
2069
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2070
|
+
type: 'variation',
|
|
2071
|
+
default: {
|
|
2072
|
+
node: {
|
|
2073
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2074
|
+
type: 'fragment',
|
|
2075
|
+
children: [
|
|
2076
|
+
{
|
|
2077
|
+
type: 'text',
|
|
2078
|
+
value: 'Default English',
|
|
2079
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2080
|
+
},
|
|
2081
|
+
],
|
|
2082
|
+
i18n: {
|
|
2083
|
+
// No French translation
|
|
2084
|
+
},
|
|
2085
|
+
},
|
|
2086
|
+
},
|
|
2087
|
+
variants: [
|
|
2088
|
+
{
|
|
2089
|
+
conditions: { segment: { code: 'is-student' } },
|
|
2090
|
+
node: {
|
|
2091
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2092
|
+
type: 'fragment',
|
|
2093
|
+
children: [
|
|
2094
|
+
{
|
|
2095
|
+
type: 'text',
|
|
2096
|
+
value: 'Variant English',
|
|
2097
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2098
|
+
},
|
|
2099
|
+
],
|
|
2100
|
+
i18n: {
|
|
2101
|
+
// No French translation
|
|
2102
|
+
},
|
|
2103
|
+
},
|
|
2104
|
+
},
|
|
2105
|
+
],
|
|
2106
|
+
},
|
|
2107
|
+
],
|
|
2108
|
+
},
|
|
1684
2109
|
},
|
|
1685
2110
|
],
|
|
1686
|
-
i18n: {
|
|
1687
|
-
fr: {
|
|
1688
|
-
children: [
|
|
1689
|
-
{
|
|
1690
|
-
type: 'text',
|
|
1691
|
-
value: 'French Title',
|
|
1692
|
-
},
|
|
1693
|
-
],
|
|
1694
|
-
},
|
|
1695
|
-
},
|
|
1696
2111
|
};
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
2112
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
2113
|
+
const variation = pageContents.layouts[0].content.main[0];
|
|
2114
|
+
// Both default and variant should be removed since no translations exist and fallbackToDefault is false
|
|
2115
|
+
expect(variation.default.node).toBeNull();
|
|
2116
|
+
expect(variation.variants[0].node).toBeNull();
|
|
2117
|
+
});
|
|
2118
|
+
it('should handle layout nodes with translatable content in multiple zones', () => {
|
|
2119
|
+
const pageContents = {
|
|
2120
|
+
...mockPageContents,
|
|
2121
|
+
layouts: [
|
|
2122
|
+
{
|
|
2123
|
+
name: 'single-column',
|
|
2124
|
+
content: {
|
|
2125
|
+
main: [
|
|
2126
|
+
{
|
|
2127
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2128
|
+
type: 'layout',
|
|
2129
|
+
layout: {
|
|
2130
|
+
template: '<div class="container"><header>{{zones.header}}</header><main>{{zones.main}}</main></div>',
|
|
2131
|
+
name: 'multi-zone-layout',
|
|
2132
|
+
options: {},
|
|
2133
|
+
},
|
|
2134
|
+
content: {
|
|
2135
|
+
header: [
|
|
2136
|
+
{
|
|
2137
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2138
|
+
type: 'fragment',
|
|
2139
|
+
children: [
|
|
2140
|
+
{
|
|
2141
|
+
type: 'text',
|
|
2142
|
+
value: 'Header English',
|
|
2143
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2144
|
+
},
|
|
2145
|
+
],
|
|
2146
|
+
i18n: {
|
|
2147
|
+
fr: {
|
|
2148
|
+
children: [
|
|
2149
|
+
{
|
|
2150
|
+
type: 'text',
|
|
2151
|
+
value: 'Header French',
|
|
2152
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2153
|
+
},
|
|
2154
|
+
],
|
|
2155
|
+
},
|
|
2156
|
+
},
|
|
2157
|
+
},
|
|
2158
|
+
],
|
|
2159
|
+
main: [
|
|
2160
|
+
{
|
|
2161
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2162
|
+
type: 'component',
|
|
2163
|
+
componentId: 'test/component/1.0.0',
|
|
2164
|
+
componentSet: 'test-set',
|
|
2165
|
+
componentType: 'edge',
|
|
2166
|
+
contentItem: { id: 'main-en' },
|
|
2167
|
+
i18n: {
|
|
2168
|
+
fr: { id: 'main-fr' },
|
|
2169
|
+
},
|
|
2170
|
+
},
|
|
2171
|
+
],
|
|
2172
|
+
},
|
|
2173
|
+
},
|
|
2174
|
+
],
|
|
1724
2175
|
},
|
|
1725
|
-
|
|
1726
|
-
|
|
2176
|
+
},
|
|
2177
|
+
],
|
|
1727
2178
|
};
|
|
1728
|
-
(0, page_contents_lib_1.
|
|
1729
|
-
|
|
1730
|
-
const
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
expect(
|
|
1734
|
-
expect(
|
|
2179
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
2180
|
+
const layoutNode = pageContents.layouts[0].content.main[0];
|
|
2181
|
+
const headerFragment = layoutNode.content.header[0];
|
|
2182
|
+
const mainComponent = layoutNode.content.main[0];
|
|
2183
|
+
expect(headerFragment.children[0].value).toBe('Header French');
|
|
2184
|
+
expect(headerFragment).not.toHaveProperty('i18n');
|
|
2185
|
+
expect(mainComponent.contentItem).toEqual({ id: 'main-fr' });
|
|
2186
|
+
expect(mainComponent).not.toHaveProperty('i18n');
|
|
1735
2187
|
});
|
|
1736
|
-
it('should handle nested layout nodes with
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
children: [
|
|
2188
|
+
it('should handle deeply nested layout nodes with translatable content', () => {
|
|
2189
|
+
const pageContents = {
|
|
2190
|
+
...mockPageContents,
|
|
2191
|
+
layouts: [
|
|
1741
2192
|
{
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
2193
|
+
name: 'single-column',
|
|
2194
|
+
content: {
|
|
2195
|
+
main: [
|
|
2196
|
+
{
|
|
2197
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2198
|
+
type: 'layout',
|
|
2199
|
+
layout: {
|
|
2200
|
+
template: '<div class="outer">{{zones.content}}</div>',
|
|
2201
|
+
name: 'outer-layout',
|
|
2202
|
+
options: {},
|
|
2203
|
+
},
|
|
2204
|
+
content: {
|
|
2205
|
+
content: [
|
|
2206
|
+
{
|
|
2207
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2208
|
+
type: 'layout',
|
|
2209
|
+
layout: {
|
|
2210
|
+
template: '<section class="inner">{{zones.content}}</section>',
|
|
2211
|
+
name: 'inner-layout',
|
|
2212
|
+
options: {},
|
|
2213
|
+
},
|
|
2214
|
+
content: {
|
|
2215
|
+
content: [
|
|
2216
|
+
{
|
|
2217
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2218
|
+
type: 'fragment',
|
|
2219
|
+
children: [
|
|
2220
|
+
{
|
|
2221
|
+
type: 'text',
|
|
2222
|
+
value: 'Deeply Nested English',
|
|
2223
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2224
|
+
},
|
|
2225
|
+
],
|
|
2226
|
+
i18n: {
|
|
2227
|
+
fr: {
|
|
2228
|
+
children: [
|
|
2229
|
+
{
|
|
2230
|
+
type: 'text',
|
|
2231
|
+
value: 'Deeply Nested French',
|
|
2232
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2233
|
+
},
|
|
2234
|
+
],
|
|
2235
|
+
},
|
|
2236
|
+
},
|
|
2237
|
+
},
|
|
2238
|
+
],
|
|
2239
|
+
},
|
|
2240
|
+
},
|
|
2241
|
+
],
|
|
2242
|
+
},
|
|
2243
|
+
},
|
|
2244
|
+
],
|
|
2245
|
+
},
|
|
1745
2246
|
},
|
|
1746
2247
|
],
|
|
1747
|
-
i18n: {
|
|
1748
|
-
fr: {
|
|
1749
|
-
children: [
|
|
1750
|
-
{
|
|
1751
|
-
type: 'text',
|
|
1752
|
-
value: 'French text',
|
|
1753
|
-
},
|
|
1754
|
-
],
|
|
1755
|
-
},
|
|
1756
|
-
},
|
|
1757
|
-
};
|
|
1758
|
-
const innerLayoutNode = {
|
|
1759
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1760
|
-
type: 'layout',
|
|
1761
|
-
layout: {
|
|
1762
|
-
template: '<div>{{zones.inner}}</div>',
|
|
1763
|
-
name: 'inner-layout',
|
|
1764
|
-
options: {},
|
|
1765
|
-
},
|
|
1766
|
-
content: {
|
|
1767
|
-
inner: [fragmentNode],
|
|
1768
|
-
},
|
|
1769
2248
|
};
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
2249
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
2250
|
+
const outerLayout = pageContents.layouts[0].content.main[0];
|
|
2251
|
+
const innerLayout = outerLayout.content.content[0];
|
|
2252
|
+
const nestedFragment = innerLayout.content.content[0];
|
|
2253
|
+
expect(nestedFragment.children[0].value).toBe('Deeply Nested French');
|
|
2254
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
2255
|
+
});
|
|
2256
|
+
it('should handle layout nodes with mixed content types and translations', () => {
|
|
2257
|
+
var _a, _b, _c;
|
|
2258
|
+
const pageContents = {
|
|
2259
|
+
...mockPageContents,
|
|
2260
|
+
layouts: [
|
|
2261
|
+
{
|
|
2262
|
+
name: 'single-column',
|
|
2263
|
+
content: {
|
|
2264
|
+
main: [
|
|
2265
|
+
{
|
|
2266
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2267
|
+
type: 'layout',
|
|
2268
|
+
layout: {
|
|
2269
|
+
template: '<div class="mixed-content">{{zones.content}}</div>',
|
|
2270
|
+
name: 'mixed-layout',
|
|
2271
|
+
options: {},
|
|
2272
|
+
},
|
|
2273
|
+
content: {
|
|
2274
|
+
content: [
|
|
2275
|
+
{
|
|
2276
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2277
|
+
type: 'fragment',
|
|
2278
|
+
children: [
|
|
2279
|
+
{
|
|
2280
|
+
type: 'text',
|
|
2281
|
+
value: 'Fragment English',
|
|
2282
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2283
|
+
},
|
|
2284
|
+
],
|
|
2285
|
+
i18n: {
|
|
2286
|
+
fr: {
|
|
2287
|
+
children: [
|
|
2288
|
+
{
|
|
2289
|
+
type: 'text',
|
|
2290
|
+
value: 'Fragment French',
|
|
2291
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2292
|
+
},
|
|
2293
|
+
],
|
|
2294
|
+
},
|
|
2295
|
+
},
|
|
2296
|
+
},
|
|
2297
|
+
{
|
|
2298
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2299
|
+
type: 'component',
|
|
2300
|
+
componentId: 'test/component/1.0.0',
|
|
2301
|
+
componentSet: 'test-set',
|
|
2302
|
+
componentType: 'edge',
|
|
2303
|
+
contentItem: { id: 'component-en' },
|
|
2304
|
+
i18n: {
|
|
2305
|
+
fr: { id: 'component-fr' },
|
|
2306
|
+
},
|
|
2307
|
+
},
|
|
2308
|
+
{
|
|
2309
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2310
|
+
type: 'variation',
|
|
2311
|
+
default: {
|
|
2312
|
+
node: {
|
|
2313
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2314
|
+
type: 'fragment',
|
|
2315
|
+
children: [
|
|
2316
|
+
{
|
|
2317
|
+
type: 'text',
|
|
2318
|
+
value: 'Variation Default English',
|
|
2319
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2320
|
+
},
|
|
2321
|
+
],
|
|
2322
|
+
i18n: {
|
|
2323
|
+
fr: {
|
|
2324
|
+
children: [
|
|
2325
|
+
{
|
|
2326
|
+
type: 'text',
|
|
2327
|
+
value: 'Variation Default French',
|
|
2328
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2329
|
+
},
|
|
2330
|
+
],
|
|
2331
|
+
},
|
|
2332
|
+
},
|
|
2333
|
+
},
|
|
2334
|
+
},
|
|
2335
|
+
variants: [
|
|
2336
|
+
{
|
|
2337
|
+
conditions: { segment: { code: 'is-premium' } },
|
|
2338
|
+
node: {
|
|
2339
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2340
|
+
type: 'component',
|
|
2341
|
+
componentId: 'premium/component/1.0.0',
|
|
2342
|
+
componentSet: 'premium-set',
|
|
2343
|
+
componentType: 'edge',
|
|
2344
|
+
contentItem: { id: 'premium-variant-en' },
|
|
2345
|
+
i18n: {
|
|
2346
|
+
fr: { id: 'premium-variant-fr' },
|
|
2347
|
+
},
|
|
2348
|
+
},
|
|
2349
|
+
},
|
|
2350
|
+
],
|
|
2351
|
+
},
|
|
2352
|
+
],
|
|
2353
|
+
},
|
|
2354
|
+
},
|
|
2355
|
+
],
|
|
1785
2356
|
},
|
|
1786
|
-
|
|
1787
|
-
|
|
2357
|
+
},
|
|
2358
|
+
],
|
|
1788
2359
|
};
|
|
1789
|
-
(0, page_contents_lib_1.
|
|
1790
|
-
|
|
1791
|
-
const
|
|
1792
|
-
const
|
|
1793
|
-
const
|
|
1794
|
-
|
|
2360
|
+
(0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
|
|
2361
|
+
const layoutNode = pageContents.layouts[0].content.main[0];
|
|
2362
|
+
const content = layoutNode.content.content;
|
|
2363
|
+
const fragment = content[0];
|
|
2364
|
+
const component = content[1];
|
|
2365
|
+
const variation = content[2];
|
|
2366
|
+
// Check fragment translation
|
|
2367
|
+
expect(fragment.children[0].value).toBe('Fragment French');
|
|
2368
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2369
|
+
// Check component translation
|
|
2370
|
+
expect(component.contentItem).toEqual({ id: 'component-fr' });
|
|
2371
|
+
expect(component).not.toHaveProperty('i18n');
|
|
2372
|
+
// Check variation translation
|
|
2373
|
+
const variationDefault = (_a = variation.default) === null || _a === void 0 ? void 0 : _a.node;
|
|
2374
|
+
const variationVariant = (_c = (_b = variation.variants) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.node;
|
|
2375
|
+
expect(variationDefault.children[0].value).toBe('Variation Default French');
|
|
2376
|
+
expect(variationDefault).not.toHaveProperty('i18n');
|
|
2377
|
+
expect(variationVariant.contentItem).toEqual({ id: 'premium-variant-fr' });
|
|
2378
|
+
expect(variationVariant).not.toHaveProperty('i18n');
|
|
1795
2379
|
});
|
|
1796
2380
|
});
|
|
1797
2381
|
//# sourceMappingURL=page-contents-lib.spec.js.map
|