@squiz/dx-page-contents-lib 1.80.0 → 1.81.1
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 +44 -44
- package/lib/formatted-text.js +9 -5
- package/lib/formatted-text.js.map +1 -1
- package/lib/layout-content.d.ts +44 -44
- package/lib/layouts/custom-layout.d.ts +5 -73
- package/lib/layouts/custom-layout.js +3 -34
- package/lib/layouts/custom-layout.js.map +1 -1
- package/lib/layouts/index.d.ts +3 -25
- package/lib/layouts/index.js +2 -4
- package/lib/layouts/index.js.map +1 -1
- package/lib/mocks/PageContentsHelpers.d.ts +4 -26
- package/lib/page-contents-lib.d.ts +7 -0
- package/lib/page-contents-lib.js +22 -6
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +560 -35
- package/lib/page-contents-lib.spec.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const zod_1 = require("zod");
|
|
4
3
|
const mocks_1 = require("./mocks");
|
|
5
4
|
const page_contents_lib_1 = require("./page-contents-lib");
|
|
6
5
|
const crypto_1 = require("crypto");
|
|
@@ -440,12 +439,12 @@ describe('assertIsPageLayout', () => {
|
|
|
440
439
|
});
|
|
441
440
|
});
|
|
442
441
|
describe('custom-layout', () => {
|
|
443
|
-
it('
|
|
442
|
+
it('passes with conflicting minNodes/maxNodes (validation removed)', () => {
|
|
444
443
|
const layout = {
|
|
445
444
|
name: 'custom-layout',
|
|
446
445
|
config: {
|
|
447
446
|
minNodes: 4,
|
|
448
|
-
maxNodes: 2,
|
|
447
|
+
maxNodes: 2, // This used to cause an error, but validation is removed
|
|
449
448
|
rootWrapper: {
|
|
450
449
|
tag: 'section',
|
|
451
450
|
},
|
|
@@ -454,15 +453,9 @@ describe('assertIsPageLayout', () => {
|
|
|
454
453
|
main: [],
|
|
455
454
|
},
|
|
456
455
|
};
|
|
457
|
-
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrowError(
|
|
458
|
-
{
|
|
459
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
460
|
-
message: 'maxNodes must be greater than minNodes',
|
|
461
|
-
path: ['config', 'maxNodes'],
|
|
462
|
-
},
|
|
463
|
-
]));
|
|
456
|
+
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrowError();
|
|
464
457
|
});
|
|
465
|
-
it('passes
|
|
458
|
+
it('passes with valid minNodes/maxNodes configuration', () => {
|
|
466
459
|
const layout = {
|
|
467
460
|
name: 'custom-layout',
|
|
468
461
|
config: {
|
|
@@ -478,7 +471,7 @@ describe('assertIsPageLayout', () => {
|
|
|
478
471
|
};
|
|
479
472
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrowError();
|
|
480
473
|
});
|
|
481
|
-
it('
|
|
474
|
+
it('passes when there is less content than config.minNodes (validation removed)', () => {
|
|
482
475
|
const layout = {
|
|
483
476
|
name: 'custom-layout',
|
|
484
477
|
config: {
|
|
@@ -488,21 +481,12 @@ describe('assertIsPageLayout', () => {
|
|
|
488
481
|
},
|
|
489
482
|
},
|
|
490
483
|
content: {
|
|
491
|
-
main: [],
|
|
484
|
+
main: [], // 0 nodes, less than minNodes but validation removed
|
|
492
485
|
},
|
|
493
486
|
};
|
|
494
|
-
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrowError(
|
|
495
|
-
{
|
|
496
|
-
code: zod_1.z.ZodIssueCode.too_small,
|
|
497
|
-
minimum: 1,
|
|
498
|
-
inclusive: true,
|
|
499
|
-
type: 'array',
|
|
500
|
-
message: 'Layout config requires a minimum number of content nodes',
|
|
501
|
-
path: ['content', 'main'],
|
|
502
|
-
},
|
|
503
|
-
]));
|
|
487
|
+
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrowError();
|
|
504
488
|
});
|
|
505
|
-
it('
|
|
489
|
+
it('passes when there is more content than config.maxNodes (validation removed)', () => {
|
|
506
490
|
const layout = {
|
|
507
491
|
name: 'custom-layout',
|
|
508
492
|
config: {
|
|
@@ -516,19 +500,10 @@ describe('assertIsPageLayout', () => {
|
|
|
516
500
|
main: [
|
|
517
501
|
{ type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
518
502
|
{ type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
|
|
519
|
-
],
|
|
503
|
+
], // 2 nodes, more than maxNodes but validation removed
|
|
520
504
|
},
|
|
521
505
|
};
|
|
522
|
-
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrowError(
|
|
523
|
-
{
|
|
524
|
-
code: zod_1.z.ZodIssueCode.too_big,
|
|
525
|
-
maximum: 1,
|
|
526
|
-
inclusive: true,
|
|
527
|
-
type: 'array',
|
|
528
|
-
message: 'Layout config supports a maximum number of content nodes',
|
|
529
|
-
path: ['content', 'main'],
|
|
530
|
-
},
|
|
531
|
-
]));
|
|
506
|
+
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrowError();
|
|
532
507
|
});
|
|
533
508
|
it('passes when there is more content than config.minNodes', () => {
|
|
534
509
|
const layout = {
|
|
@@ -2378,4 +2353,554 @@ describe('translatePageContents', () => {
|
|
|
2378
2353
|
expect(variationVariant).not.toHaveProperty('i18n');
|
|
2379
2354
|
});
|
|
2380
2355
|
});
|
|
2356
|
+
describe('translatePageContentsWithContent', () => {
|
|
2357
|
+
const mockPageContentsWithContent = {
|
|
2358
|
+
id: 'test-page-with-content-1',
|
|
2359
|
+
name: 'Test Page With Content',
|
|
2360
|
+
config: {
|
|
2361
|
+
languages: {
|
|
2362
|
+
fr: {
|
|
2363
|
+
fallbackToDefault: true,
|
|
2364
|
+
},
|
|
2365
|
+
es: {
|
|
2366
|
+
fallbackToDefault: false,
|
|
2367
|
+
},
|
|
2368
|
+
},
|
|
2369
|
+
},
|
|
2370
|
+
content: {
|
|
2371
|
+
main: [
|
|
2372
|
+
{
|
|
2373
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2374
|
+
type: 'fragment',
|
|
2375
|
+
children: [
|
|
2376
|
+
{
|
|
2377
|
+
type: 'text',
|
|
2378
|
+
value: 'English text',
|
|
2379
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2380
|
+
},
|
|
2381
|
+
],
|
|
2382
|
+
i18n: {
|
|
2383
|
+
fr: {
|
|
2384
|
+
children: [
|
|
2385
|
+
{
|
|
2386
|
+
type: 'text',
|
|
2387
|
+
value: 'French text',
|
|
2388
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2389
|
+
},
|
|
2390
|
+
],
|
|
2391
|
+
},
|
|
2392
|
+
},
|
|
2393
|
+
},
|
|
2394
|
+
{
|
|
2395
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2396
|
+
type: 'component',
|
|
2397
|
+
componentId: 'test/component/1.0.0',
|
|
2398
|
+
componentSet: 'test-set',
|
|
2399
|
+
componentType: 'edge',
|
|
2400
|
+
contentItem: { id: 'en-content' },
|
|
2401
|
+
i18n: {
|
|
2402
|
+
fr: { id: 'fr-content' },
|
|
2403
|
+
},
|
|
2404
|
+
},
|
|
2405
|
+
],
|
|
2406
|
+
},
|
|
2407
|
+
};
|
|
2408
|
+
it('should translate page contents with content to French when language config exists', () => {
|
|
2409
|
+
const pageContents = { ...mockPageContentsWithContent };
|
|
2410
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2411
|
+
// Check main zone
|
|
2412
|
+
const mainFragment = pageContents.content.main[0];
|
|
2413
|
+
const mainComponent = pageContents.content.main[1];
|
|
2414
|
+
expect(mainFragment.children[0].value).toBe('French text');
|
|
2415
|
+
expect(mainFragment).not.toHaveProperty('i18n');
|
|
2416
|
+
expect(mainComponent.contentItem).toEqual({ id: 'fr-content' });
|
|
2417
|
+
expect(mainComponent).not.toHaveProperty('i18n');
|
|
2418
|
+
});
|
|
2419
|
+
it('should fallback to default content when translation is not available and fallbackToDefault is true', () => {
|
|
2420
|
+
const pageContents = {
|
|
2421
|
+
...mockPageContentsWithContent,
|
|
2422
|
+
content: {
|
|
2423
|
+
main: [
|
|
2424
|
+
{
|
|
2425
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2426
|
+
type: 'fragment',
|
|
2427
|
+
children: [
|
|
2428
|
+
{
|
|
2429
|
+
type: 'text',
|
|
2430
|
+
value: 'English text',
|
|
2431
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2432
|
+
},
|
|
2433
|
+
],
|
|
2434
|
+
i18n: {
|
|
2435
|
+
// No French translation available
|
|
2436
|
+
},
|
|
2437
|
+
},
|
|
2438
|
+
],
|
|
2439
|
+
},
|
|
2440
|
+
};
|
|
2441
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2442
|
+
const fragment = pageContents.content.main[0];
|
|
2443
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2444
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2445
|
+
});
|
|
2446
|
+
it('should not fallback to default content when translation is not available and fallbackToDefault is false', () => {
|
|
2447
|
+
const pageContents = {
|
|
2448
|
+
...mockPageContentsWithContent,
|
|
2449
|
+
content: {
|
|
2450
|
+
main: [
|
|
2451
|
+
{
|
|
2452
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2453
|
+
type: 'fragment',
|
|
2454
|
+
children: [
|
|
2455
|
+
{
|
|
2456
|
+
type: 'text',
|
|
2457
|
+
value: 'English text',
|
|
2458
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2459
|
+
},
|
|
2460
|
+
],
|
|
2461
|
+
i18n: {
|
|
2462
|
+
// No Spanish translation available
|
|
2463
|
+
},
|
|
2464
|
+
},
|
|
2465
|
+
],
|
|
2466
|
+
},
|
|
2467
|
+
};
|
|
2468
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'es');
|
|
2469
|
+
// Should not be translated since fallbackToDefault is false for Spanish
|
|
2470
|
+
// The node should be removed from the array since no translation is available
|
|
2471
|
+
expect(pageContents.content.main).toHaveLength(0);
|
|
2472
|
+
});
|
|
2473
|
+
it('should handle page contents without language config', () => {
|
|
2474
|
+
const pageContents = {
|
|
2475
|
+
...mockPageContentsWithContent,
|
|
2476
|
+
config: undefined,
|
|
2477
|
+
content: {
|
|
2478
|
+
main: [
|
|
2479
|
+
{
|
|
2480
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2481
|
+
type: 'fragment',
|
|
2482
|
+
children: [
|
|
2483
|
+
{
|
|
2484
|
+
type: 'text',
|
|
2485
|
+
value: 'English text',
|
|
2486
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2487
|
+
},
|
|
2488
|
+
],
|
|
2489
|
+
i18n: {
|
|
2490
|
+
fr: {
|
|
2491
|
+
children: [
|
|
2492
|
+
{
|
|
2493
|
+
type: 'text',
|
|
2494
|
+
value: 'French text',
|
|
2495
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2496
|
+
},
|
|
2497
|
+
],
|
|
2498
|
+
},
|
|
2499
|
+
},
|
|
2500
|
+
},
|
|
2501
|
+
],
|
|
2502
|
+
},
|
|
2503
|
+
};
|
|
2504
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2505
|
+
// Should not translate since no language config exists
|
|
2506
|
+
// The i18n property should be removed but content preserved
|
|
2507
|
+
const fragment = pageContents.content.main[0];
|
|
2508
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2509
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2510
|
+
});
|
|
2511
|
+
it('should handle page contents with language config but no specific language', () => {
|
|
2512
|
+
const pageContents = {
|
|
2513
|
+
...mockPageContentsWithContent,
|
|
2514
|
+
config: {
|
|
2515
|
+
languages: {
|
|
2516
|
+
// No French config
|
|
2517
|
+
},
|
|
2518
|
+
},
|
|
2519
|
+
content: {
|
|
2520
|
+
main: [
|
|
2521
|
+
{
|
|
2522
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2523
|
+
type: 'fragment',
|
|
2524
|
+
children: [
|
|
2525
|
+
{
|
|
2526
|
+
type: 'text',
|
|
2527
|
+
value: 'English text',
|
|
2528
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2529
|
+
},
|
|
2530
|
+
],
|
|
2531
|
+
i18n: {
|
|
2532
|
+
fr: {
|
|
2533
|
+
children: [
|
|
2534
|
+
{
|
|
2535
|
+
type: 'text',
|
|
2536
|
+
value: 'French text',
|
|
2537
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2538
|
+
},
|
|
2539
|
+
],
|
|
2540
|
+
},
|
|
2541
|
+
},
|
|
2542
|
+
},
|
|
2543
|
+
],
|
|
2544
|
+
},
|
|
2545
|
+
};
|
|
2546
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2547
|
+
// Should not translate since no French language config exists
|
|
2548
|
+
// The i18n property should be removed but content preserved
|
|
2549
|
+
const fragment = pageContents.content.main[0];
|
|
2550
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2551
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2552
|
+
});
|
|
2553
|
+
it('should handle nested layout nodes in page contents with content property', () => {
|
|
2554
|
+
const pageContents = {
|
|
2555
|
+
...mockPageContentsWithContent,
|
|
2556
|
+
content: {
|
|
2557
|
+
main: [
|
|
2558
|
+
{
|
|
2559
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2560
|
+
type: 'layout',
|
|
2561
|
+
layout: {
|
|
2562
|
+
template: '<div>{{zones.inner}}</div>',
|
|
2563
|
+
name: 'nested-layout',
|
|
2564
|
+
options: {},
|
|
2565
|
+
},
|
|
2566
|
+
content: {
|
|
2567
|
+
inner: [
|
|
2568
|
+
{
|
|
2569
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2570
|
+
type: 'fragment',
|
|
2571
|
+
children: [
|
|
2572
|
+
{
|
|
2573
|
+
type: 'text',
|
|
2574
|
+
value: 'Nested English',
|
|
2575
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2576
|
+
},
|
|
2577
|
+
],
|
|
2578
|
+
i18n: {
|
|
2579
|
+
fr: {
|
|
2580
|
+
children: [
|
|
2581
|
+
{
|
|
2582
|
+
type: 'text',
|
|
2583
|
+
value: 'Nested French',
|
|
2584
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2585
|
+
},
|
|
2586
|
+
],
|
|
2587
|
+
},
|
|
2588
|
+
},
|
|
2589
|
+
},
|
|
2590
|
+
],
|
|
2591
|
+
},
|
|
2592
|
+
},
|
|
2593
|
+
],
|
|
2594
|
+
},
|
|
2595
|
+
};
|
|
2596
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2597
|
+
const layoutNode = pageContents.content.main[0];
|
|
2598
|
+
const nestedFragment = layoutNode.content.inner[0];
|
|
2599
|
+
expect(nestedFragment.children[0].value).toBe('Nested French');
|
|
2600
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
2601
|
+
});
|
|
2602
|
+
it('should handle page contents with empty content', () => {
|
|
2603
|
+
const pageContents = {
|
|
2604
|
+
...mockPageContentsWithContent,
|
|
2605
|
+
content: {
|
|
2606
|
+
main: [],
|
|
2607
|
+
},
|
|
2608
|
+
};
|
|
2609
|
+
expect(() => (0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr')).not.toThrow();
|
|
2610
|
+
});
|
|
2611
|
+
it('should handle page contents with no content property', () => {
|
|
2612
|
+
const pageContents = {
|
|
2613
|
+
...mockPageContentsWithContent,
|
|
2614
|
+
content: undefined,
|
|
2615
|
+
};
|
|
2616
|
+
expect(() => (0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr')).not.toThrow();
|
|
2617
|
+
});
|
|
2618
|
+
it('should handle mixed content types in content', () => {
|
|
2619
|
+
const pageContents = {
|
|
2620
|
+
...mockPageContentsWithContent,
|
|
2621
|
+
content: {
|
|
2622
|
+
main: [
|
|
2623
|
+
{
|
|
2624
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2625
|
+
type: 'fragment',
|
|
2626
|
+
children: [
|
|
2627
|
+
{
|
|
2628
|
+
type: 'text',
|
|
2629
|
+
value: 'English fragment',
|
|
2630
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2631
|
+
},
|
|
2632
|
+
],
|
|
2633
|
+
i18n: {
|
|
2634
|
+
fr: {
|
|
2635
|
+
children: [
|
|
2636
|
+
{
|
|
2637
|
+
type: 'text',
|
|
2638
|
+
value: 'French fragment',
|
|
2639
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2640
|
+
},
|
|
2641
|
+
],
|
|
2642
|
+
},
|
|
2643
|
+
},
|
|
2644
|
+
},
|
|
2645
|
+
{
|
|
2646
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2647
|
+
type: 'component',
|
|
2648
|
+
componentId: 'test/component/1.0.0',
|
|
2649
|
+
componentSet: 'test-set',
|
|
2650
|
+
componentType: 'edge',
|
|
2651
|
+
contentItem: { id: 'en-component' },
|
|
2652
|
+
i18n: {
|
|
2653
|
+
fr: { id: 'fr-component' },
|
|
2654
|
+
},
|
|
2655
|
+
},
|
|
2656
|
+
{
|
|
2657
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2658
|
+
type: 'variation',
|
|
2659
|
+
default: { node: null },
|
|
2660
|
+
variants: [],
|
|
2661
|
+
},
|
|
2662
|
+
],
|
|
2663
|
+
},
|
|
2664
|
+
};
|
|
2665
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2666
|
+
const mainContent = pageContents.content.main;
|
|
2667
|
+
const fragment = mainContent[0];
|
|
2668
|
+
const component = mainContent[1];
|
|
2669
|
+
const variation = mainContent[2];
|
|
2670
|
+
expect(fragment.children[0].value).toBe('French fragment');
|
|
2671
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2672
|
+
expect(component.contentItem).toEqual({ id: 'fr-component' });
|
|
2673
|
+
expect(component).not.toHaveProperty('i18n');
|
|
2674
|
+
// Variation should remain unchanged
|
|
2675
|
+
expect(variation.type).toBe('variation');
|
|
2676
|
+
});
|
|
2677
|
+
it('should handle language config with custom fallback settings', () => {
|
|
2678
|
+
const pageContents = {
|
|
2679
|
+
...mockPageContentsWithContent,
|
|
2680
|
+
config: {
|
|
2681
|
+
languages: {
|
|
2682
|
+
fr: {
|
|
2683
|
+
fallbackToDefault: false,
|
|
2684
|
+
},
|
|
2685
|
+
},
|
|
2686
|
+
},
|
|
2687
|
+
content: {
|
|
2688
|
+
main: [
|
|
2689
|
+
{
|
|
2690
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2691
|
+
type: 'fragment',
|
|
2692
|
+
children: [
|
|
2693
|
+
{
|
|
2694
|
+
type: 'text',
|
|
2695
|
+
value: 'English text',
|
|
2696
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2697
|
+
},
|
|
2698
|
+
],
|
|
2699
|
+
i18n: {
|
|
2700
|
+
// No French translation
|
|
2701
|
+
},
|
|
2702
|
+
},
|
|
2703
|
+
],
|
|
2704
|
+
},
|
|
2705
|
+
};
|
|
2706
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2707
|
+
// Should not be translated since fallbackToDefault is false and no translation exists
|
|
2708
|
+
// The node should be removed from the array since no translation is available
|
|
2709
|
+
expect(pageContents.content.main).toHaveLength(0);
|
|
2710
|
+
});
|
|
2711
|
+
it('should handle variant nodes with translatable default content', () => {
|
|
2712
|
+
const pageContents = {
|
|
2713
|
+
...mockPageContentsWithContent,
|
|
2714
|
+
content: {
|
|
2715
|
+
main: [
|
|
2716
|
+
{
|
|
2717
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2718
|
+
type: 'variation',
|
|
2719
|
+
default: {
|
|
2720
|
+
node: {
|
|
2721
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2722
|
+
type: 'fragment',
|
|
2723
|
+
children: [
|
|
2724
|
+
{
|
|
2725
|
+
type: 'text',
|
|
2726
|
+
value: 'Default English',
|
|
2727
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2728
|
+
},
|
|
2729
|
+
],
|
|
2730
|
+
i18n: {
|
|
2731
|
+
fr: {
|
|
2732
|
+
children: [
|
|
2733
|
+
{
|
|
2734
|
+
type: 'text',
|
|
2735
|
+
value: 'Default French',
|
|
2736
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2737
|
+
},
|
|
2738
|
+
],
|
|
2739
|
+
},
|
|
2740
|
+
},
|
|
2741
|
+
},
|
|
2742
|
+
},
|
|
2743
|
+
variants: [
|
|
2744
|
+
{
|
|
2745
|
+
conditions: { segment: { code: 'is-student' } },
|
|
2746
|
+
node: {
|
|
2747
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2748
|
+
type: 'fragment',
|
|
2749
|
+
children: [
|
|
2750
|
+
{
|
|
2751
|
+
type: 'text',
|
|
2752
|
+
value: 'Variant English',
|
|
2753
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2754
|
+
},
|
|
2755
|
+
],
|
|
2756
|
+
i18n: {
|
|
2757
|
+
fr: {
|
|
2758
|
+
children: [
|
|
2759
|
+
{
|
|
2760
|
+
type: 'text',
|
|
2761
|
+
value: 'Variant French',
|
|
2762
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2763
|
+
},
|
|
2764
|
+
],
|
|
2765
|
+
},
|
|
2766
|
+
},
|
|
2767
|
+
},
|
|
2768
|
+
},
|
|
2769
|
+
],
|
|
2770
|
+
},
|
|
2771
|
+
],
|
|
2772
|
+
},
|
|
2773
|
+
};
|
|
2774
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2775
|
+
const variation = pageContents.content.main[0];
|
|
2776
|
+
const defaultNode = variation.default.node;
|
|
2777
|
+
const variantNode = variation.variants[0].node;
|
|
2778
|
+
expect(defaultNode.children[0].value).toBe('Default French');
|
|
2779
|
+
expect(defaultNode).not.toHaveProperty('i18n');
|
|
2780
|
+
expect(variantNode.children[0].value).toBe('Variant French');
|
|
2781
|
+
expect(variantNode).not.toHaveProperty('i18n');
|
|
2782
|
+
});
|
|
2783
|
+
it('should handle nested layout nodes in page contents with content', () => {
|
|
2784
|
+
const pageContents = {
|
|
2785
|
+
...mockPageContentsWithContent,
|
|
2786
|
+
content: {
|
|
2787
|
+
main: [
|
|
2788
|
+
{
|
|
2789
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2790
|
+
type: 'layout',
|
|
2791
|
+
layout: {
|
|
2792
|
+
template: '<div>{{zones.inner}}</div>',
|
|
2793
|
+
name: 'nested-layout',
|
|
2794
|
+
options: {},
|
|
2795
|
+
},
|
|
2796
|
+
content: {
|
|
2797
|
+
inner: [
|
|
2798
|
+
{
|
|
2799
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2800
|
+
type: 'fragment',
|
|
2801
|
+
children: [
|
|
2802
|
+
{
|
|
2803
|
+
type: 'text',
|
|
2804
|
+
value: 'Nested English',
|
|
2805
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2806
|
+
},
|
|
2807
|
+
],
|
|
2808
|
+
i18n: {
|
|
2809
|
+
fr: {
|
|
2810
|
+
children: [
|
|
2811
|
+
{
|
|
2812
|
+
type: 'text',
|
|
2813
|
+
value: 'Nested French',
|
|
2814
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2815
|
+
},
|
|
2816
|
+
],
|
|
2817
|
+
},
|
|
2818
|
+
},
|
|
2819
|
+
},
|
|
2820
|
+
],
|
|
2821
|
+
},
|
|
2822
|
+
},
|
|
2823
|
+
],
|
|
2824
|
+
},
|
|
2825
|
+
};
|
|
2826
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2827
|
+
const layoutNode = pageContents.content.main[0];
|
|
2828
|
+
const nestedFragment = layoutNode.content.inner[0];
|
|
2829
|
+
expect(nestedFragment.children[0].value).toBe('Nested French');
|
|
2830
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
2831
|
+
});
|
|
2832
|
+
it('should handle multiple content zones with different translation scenarios', () => {
|
|
2833
|
+
const pageContents = {
|
|
2834
|
+
...mockPageContentsWithContent,
|
|
2835
|
+
content: {
|
|
2836
|
+
header: [
|
|
2837
|
+
{
|
|
2838
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2839
|
+
type: 'fragment',
|
|
2840
|
+
children: [
|
|
2841
|
+
{
|
|
2842
|
+
type: 'text',
|
|
2843
|
+
value: 'Header English',
|
|
2844
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2845
|
+
},
|
|
2846
|
+
],
|
|
2847
|
+
i18n: {
|
|
2848
|
+
fr: {
|
|
2849
|
+
children: [
|
|
2850
|
+
{
|
|
2851
|
+
type: 'text',
|
|
2852
|
+
value: 'Header French',
|
|
2853
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2854
|
+
},
|
|
2855
|
+
],
|
|
2856
|
+
},
|
|
2857
|
+
},
|
|
2858
|
+
},
|
|
2859
|
+
],
|
|
2860
|
+
main: [
|
|
2861
|
+
{
|
|
2862
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2863
|
+
type: 'component',
|
|
2864
|
+
componentId: 'test/component/1.0.0',
|
|
2865
|
+
componentSet: 'test-set',
|
|
2866
|
+
componentType: 'edge',
|
|
2867
|
+
contentItem: { id: 'main-en' },
|
|
2868
|
+
i18n: {
|
|
2869
|
+
fr: { id: 'main-fr' },
|
|
2870
|
+
},
|
|
2871
|
+
},
|
|
2872
|
+
],
|
|
2873
|
+
footer: [
|
|
2874
|
+
{
|
|
2875
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2876
|
+
type: 'fragment',
|
|
2877
|
+
children: [
|
|
2878
|
+
{
|
|
2879
|
+
type: 'text',
|
|
2880
|
+
value: 'Footer English',
|
|
2881
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2882
|
+
},
|
|
2883
|
+
],
|
|
2884
|
+
i18n: {
|
|
2885
|
+
// No French translation
|
|
2886
|
+
},
|
|
2887
|
+
},
|
|
2888
|
+
],
|
|
2889
|
+
},
|
|
2890
|
+
};
|
|
2891
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2892
|
+
// Check header zone
|
|
2893
|
+
const headerFragment = pageContents.content.header[0];
|
|
2894
|
+
expect(headerFragment.children[0].value).toBe('Header French');
|
|
2895
|
+
expect(headerFragment).not.toHaveProperty('i18n');
|
|
2896
|
+
// Check main zone
|
|
2897
|
+
const mainComponent = pageContents.content.main[0];
|
|
2898
|
+
expect(mainComponent.contentItem).toEqual({ id: 'main-fr' });
|
|
2899
|
+
expect(mainComponent).not.toHaveProperty('i18n');
|
|
2900
|
+
// Check footer zone - should fallback to English since fallbackToDefault is true
|
|
2901
|
+
const footerFragment = pageContents.content.footer[0];
|
|
2902
|
+
expect(footerFragment.children[0].value).toBe('Footer English');
|
|
2903
|
+
expect(footerFragment).not.toHaveProperty('i18n');
|
|
2904
|
+
});
|
|
2905
|
+
});
|
|
2381
2906
|
//# sourceMappingURL=page-contents-lib.spec.js.map
|