@squiz/dx-page-contents-lib 1.79.0 → 1.81.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/layout-content.d.ts +13 -27
- package/lib/layout-content.js +12 -2
- package/lib/layout-content.js.map +1 -1
- package/lib/layout-content.spec.js +18 -0
- package/lib/layout-content.spec.js.map +1 -1
- package/lib/layouts/custom-layout.d.ts +4 -12
- package/lib/layouts/index.d.ts +51 -18
- package/lib/layouts/index.js +6 -0
- package/lib/layouts/index.js.map +1 -1
- package/lib/layouts/raw.layout.d.ts +3 -9
- package/lib/layouts/single-column.layout.d.ts +22 -0
- package/lib/layouts/single-column.layout.js +15 -0
- package/lib/layouts/single-column.layout.js.map +1 -0
- package/lib/layouts/two-column.layout.d.ts +27 -0
- package/lib/layouts/two-column.layout.js +16 -0
- package/lib/layouts/two-column.layout.js.map +1 -0
- package/lib/mocks/PageContentsHelpers.d.ts +76 -29
- package/lib/mocks/PageContentsMocks.js +34 -0
- package/lib/mocks/PageContentsMocks.js.map +1 -1
- package/lib/page-contents-lib.d.ts +16 -8
- package/lib/page-contents-lib.js +164 -48
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +1745 -502
- package/lib/page-contents-lib.spec.js.map +1 -1
- package/package.json +1 -1
|
@@ -129,6 +129,86 @@ describe('assertIsContentStructure', () => {
|
|
|
129
129
|
];
|
|
130
130
|
expect(() => (0, page_contents_lib_1.assertIsContentStructure)(content)).not.toThrow();
|
|
131
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
|
+
});
|
|
132
212
|
});
|
|
133
213
|
describe('assertIsPageLayout', () => {
|
|
134
214
|
describe('layout-raw', () => {
|
|
@@ -337,6 +417,27 @@ describe('assertIsPageLayout', () => {
|
|
|
337
417
|
};
|
|
338
418
|
expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
|
|
339
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
|
+
});
|
|
340
441
|
});
|
|
341
442
|
describe('custom-layout', () => {
|
|
342
443
|
it('errors when config.minNodes is greater than config.maxNodes', () => {
|
|
@@ -651,6 +752,23 @@ describe('renderLayout', () => {
|
|
|
651
752
|
layout: {
|
|
652
753
|
template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
|
|
653
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
|
+
},
|
|
654
772
|
options: {},
|
|
655
773
|
},
|
|
656
774
|
content: {
|
|
@@ -682,6 +800,23 @@ describe('renderLayout', () => {
|
|
|
682
800
|
template: '<div class="container custom-class">{{zones.top</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
|
|
683
801
|
name: 'mock-dev-layout-with-classes',
|
|
684
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
|
+
},
|
|
685
820
|
},
|
|
686
821
|
content: {
|
|
687
822
|
top: [mockBuilder.createNodeWithId('component', 'top-component')],
|
|
@@ -711,6 +846,13 @@ describe('renderLayout', () => {
|
|
|
711
846
|
layout: {
|
|
712
847
|
template: '<div class="dev-layout">{{zones.content}}</div>',
|
|
713
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
|
+
},
|
|
714
856
|
options: {},
|
|
715
857
|
},
|
|
716
858
|
content: {
|
|
@@ -729,6 +871,18 @@ describe('renderLayout', () => {
|
|
|
729
871
|
template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
|
|
730
872
|
name: 'article-layout',
|
|
731
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
|
+
},
|
|
732
886
|
},
|
|
733
887
|
content: {
|
|
734
888
|
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
@@ -755,6 +909,13 @@ describe('renderLayout', () => {
|
|
|
755
909
|
template: '<div class="inner-layout">{{zones.innerContent}}</div>',
|
|
756
910
|
name: 'inner-dev-layout',
|
|
757
911
|
options: {},
|
|
912
|
+
zones: {
|
|
913
|
+
innerContent: {
|
|
914
|
+
displayName: 'Inner Content Zone',
|
|
915
|
+
description: 'Inner Content Zone Description',
|
|
916
|
+
minNodes: 0,
|
|
917
|
+
},
|
|
918
|
+
},
|
|
758
919
|
},
|
|
759
920
|
content: {
|
|
760
921
|
innerContent: [mockBuilder.createNodeWithId('component', 'inner-component')],
|
|
@@ -767,6 +928,13 @@ describe('renderLayout', () => {
|
|
|
767
928
|
template: '<div class="outer-layout">{{zones.outerContent}}</div>',
|
|
768
929
|
name: 'outer-dev-layout',
|
|
769
930
|
options: {},
|
|
931
|
+
zones: {
|
|
932
|
+
outerContent: {
|
|
933
|
+
displayName: 'Outer Content Zone',
|
|
934
|
+
description: 'Outer Content Zone Description',
|
|
935
|
+
minNodes: 0,
|
|
936
|
+
},
|
|
937
|
+
},
|
|
770
938
|
},
|
|
771
939
|
content: {
|
|
772
940
|
outerContent: [innerLayoutNode],
|
|
@@ -789,6 +957,13 @@ describe('renderLayout', () => {
|
|
|
789
957
|
layout: {
|
|
790
958
|
template: '<section class="level-3">{{zones.content}}</section>',
|
|
791
959
|
name: 'level-3-layout',
|
|
960
|
+
zones: {
|
|
961
|
+
content: {
|
|
962
|
+
displayName: 'Content Zone',
|
|
963
|
+
description: 'Content Zone Description',
|
|
964
|
+
minNodes: 0,
|
|
965
|
+
},
|
|
966
|
+
},
|
|
792
967
|
options: {},
|
|
793
968
|
},
|
|
794
969
|
content: {
|
|
@@ -801,6 +976,13 @@ describe('renderLayout', () => {
|
|
|
801
976
|
layout: {
|
|
802
977
|
template: '<article class="level-2">{{zones.nestedContent}}</article>',
|
|
803
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
|
+
},
|
|
804
986
|
options: {},
|
|
805
987
|
},
|
|
806
988
|
content: {
|
|
@@ -814,6 +996,13 @@ describe('renderLayout', () => {
|
|
|
814
996
|
template: '<div class="level-1">{{zones.rootContent}}</div>',
|
|
815
997
|
name: 'level-1-layout',
|
|
816
998
|
options: {},
|
|
999
|
+
zones: {
|
|
1000
|
+
rootContent: {
|
|
1001
|
+
displayName: 'Inner Content Zone',
|
|
1002
|
+
description: 'Inner Content Zone Description',
|
|
1003
|
+
minNodes: 0,
|
|
1004
|
+
},
|
|
1005
|
+
},
|
|
817
1006
|
},
|
|
818
1007
|
content: {
|
|
819
1008
|
rootContent: [level2Layout],
|
|
@@ -843,6 +1032,18 @@ describe('renderLayout', () => {
|
|
|
843
1032
|
template: '<div class="inner-mixed"><h2>{{zones.heading}}</h2><div>{{zones.content}}</div></div>',
|
|
844
1033
|
name: 'inner-mixed-layout',
|
|
845
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
|
+
},
|
|
846
1047
|
},
|
|
847
1048
|
content: {
|
|
848
1049
|
heading: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner Heading' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
@@ -856,6 +1057,18 @@ describe('renderLayout', () => {
|
|
|
856
1057
|
template: '<div class="outer-mixed"><div class="intro">{{zones.intro}}</div><div class="main">{{zones.main}}</div></div>',
|
|
857
1058
|
name: 'outer-mixed-layout',
|
|
858
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
|
+
},
|
|
859
1072
|
},
|
|
860
1073
|
content: {
|
|
861
1074
|
intro: [
|
|
@@ -878,6 +1091,20 @@ describe('renderLayout', () => {
|
|
|
878
1091
|
</div>
|
|
879
1092
|
</div>`));
|
|
880
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} -->"`);
|
|
1107
|
+
});
|
|
881
1108
|
it('should add HTML comments for developer defined layouts in preview mode', async () => {
|
|
882
1109
|
const developerLayoutNode = {
|
|
883
1110
|
type: 'layout',
|
|
@@ -886,6 +1113,18 @@ describe('renderLayout', () => {
|
|
|
886
1113
|
template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
|
|
887
1114
|
name: 'article-layout',
|
|
888
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
|
+
},
|
|
889
1128
|
},
|
|
890
1129
|
content: {
|
|
891
1130
|
title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
@@ -900,8 +1139,17 @@ describe('renderLayout', () => {
|
|
|
900
1139
|
main: [developerLayoutNode],
|
|
901
1140
|
},
|
|
902
1141
|
};
|
|
903
|
-
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
|
|
904
|
-
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} -->`);
|
|
905
1153
|
});
|
|
906
1154
|
it('should use the correct nodeId in the HTML comments for nested layouts', async () => {
|
|
907
1155
|
const innerLayoutNode = {
|
|
@@ -911,6 +1159,13 @@ describe('renderLayout', () => {
|
|
|
911
1159
|
template: '<div class="inner-layout">{{zones.content}}</div>',
|
|
912
1160
|
name: 'inner-layout',
|
|
913
1161
|
options: {},
|
|
1162
|
+
zones: {
|
|
1163
|
+
content: {
|
|
1164
|
+
displayName: 'Content Zone',
|
|
1165
|
+
description: 'Content Zone Description',
|
|
1166
|
+
minNodes: 0,
|
|
1167
|
+
},
|
|
1168
|
+
},
|
|
914
1169
|
},
|
|
915
1170
|
content: {
|
|
916
1171
|
content: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner content' }], nodeId: (0, crypto_1.randomUUID)() }],
|
|
@@ -923,6 +1178,13 @@ describe('renderLayout', () => {
|
|
|
923
1178
|
template: '<div class="outer-layout">{{zones.content}}</div>',
|
|
924
1179
|
name: 'outer-layout',
|
|
925
1180
|
options: {},
|
|
1181
|
+
zones: {
|
|
1182
|
+
content: {
|
|
1183
|
+
displayName: 'Content Zone',
|
|
1184
|
+
description: 'Content Zone Description',
|
|
1185
|
+
minNodes: 0,
|
|
1186
|
+
},
|
|
1187
|
+
},
|
|
926
1188
|
},
|
|
927
1189
|
content: {
|
|
928
1190
|
content: [innerLayoutNode],
|
|
@@ -935,7 +1197,8 @@ describe('renderLayout', () => {
|
|
|
935
1197
|
},
|
|
936
1198
|
};
|
|
937
1199
|
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
|
|
938
|
-
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} -->`;
|
|
939
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} -->`));
|
|
940
1203
|
});
|
|
941
1204
|
it('should allow fragment nodes in layout content', async () => {
|
|
@@ -946,6 +1209,13 @@ describe('renderLayout', () => {
|
|
|
946
1209
|
template: '<div class="outer-layout">{{zones.content}}</div>',
|
|
947
1210
|
name: 'outer-layout',
|
|
948
1211
|
options: {},
|
|
1212
|
+
zones: {
|
|
1213
|
+
content: {
|
|
1214
|
+
displayName: 'Content Zone',
|
|
1215
|
+
description: 'Content Zone Description',
|
|
1216
|
+
minNodes: 0,
|
|
1217
|
+
},
|
|
1218
|
+
},
|
|
949
1219
|
},
|
|
950
1220
|
content: {
|
|
951
1221
|
content: [
|
|
@@ -966,168 +1236,48 @@ describe('renderLayout', () => {
|
|
|
966
1236
|
const result = await (0, page_contents_lib_1.renderLayout)(contentPage, config);
|
|
967
1237
|
expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-layout">Fragment content</div>`));
|
|
968
1238
|
});
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
children: [
|
|
983
|
-
{
|
|
984
|
-
type: 'text',
|
|
985
|
-
value: 'English text',
|
|
986
|
-
},
|
|
987
|
-
],
|
|
988
|
-
i18n: {
|
|
989
|
-
fr: {
|
|
990
|
-
children: [
|
|
991
|
-
{
|
|
992
|
-
type: 'text',
|
|
993
|
-
value: 'French text',
|
|
994
|
-
},
|
|
995
|
-
],
|
|
996
|
-
},
|
|
997
|
-
},
|
|
998
|
-
})
|
|
999
|
-
.build();
|
|
1000
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1001
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('French text'));
|
|
1002
|
-
});
|
|
1003
|
-
it('should render translated component nodes', async () => {
|
|
1004
|
-
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1005
|
-
.addNode({
|
|
1006
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1007
|
-
type: 'component',
|
|
1008
|
-
componentId: 'test/component/1.0.0',
|
|
1009
|
-
componentSet: 'test-set',
|
|
1010
|
-
componentType: 'server',
|
|
1011
|
-
contentItem: { id: 'en-content' },
|
|
1012
|
-
i18n: {
|
|
1013
|
-
fr: { id: 'fr-content' },
|
|
1014
|
-
},
|
|
1015
|
-
})
|
|
1016
|
-
.build();
|
|
1017
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1018
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/>`));
|
|
1019
|
-
});
|
|
1020
|
-
it('should render mixed translated and untranslated nodes', async () => {
|
|
1021
|
-
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1022
|
-
.addNode({
|
|
1023
|
-
// Translated fragment
|
|
1024
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1025
|
-
type: 'fragment',
|
|
1026
|
-
children: [
|
|
1027
|
-
{
|
|
1028
|
-
type: 'text',
|
|
1029
|
-
value: 'English text',
|
|
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,
|
|
1030
1252
|
},
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
{
|
|
1036
|
-
type: 'text',
|
|
1037
|
-
value: 'French text',
|
|
1038
|
-
},
|
|
1039
|
-
],
|
|
1253
|
+
emptyZone: {
|
|
1254
|
+
displayName: 'Empty Zone',
|
|
1255
|
+
description: 'Empty Zone Description',
|
|
1256
|
+
minNodes: 0,
|
|
1040
1257
|
},
|
|
1041
1258
|
},
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1046
|
-
type: 'component',
|
|
1047
|
-
componentId: 'test/component/1.0.0',
|
|
1048
|
-
componentSet: 'test-set',
|
|
1049
|
-
componentType: 'server',
|
|
1050
|
-
contentItem: { id: 'en-content' },
|
|
1051
|
-
})
|
|
1052
|
-
.build();
|
|
1053
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1054
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/>`));
|
|
1055
|
-
});
|
|
1056
|
-
it('should render developer layout with translated content', async () => {
|
|
1057
|
-
const developerLayoutNode = {
|
|
1058
|
-
type: 'layout',
|
|
1059
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1060
|
-
layout: {
|
|
1061
|
-
template: '<div class="top">{{zones.top}}</div><div class="side">{{zones.side}}</div>',
|
|
1062
|
-
name: 'article-layout',
|
|
1063
|
-
options: {},
|
|
1064
|
-
},
|
|
1065
|
-
content: {
|
|
1066
|
-
top: [
|
|
1067
|
-
{
|
|
1068
|
-
type: 'component',
|
|
1069
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1070
|
-
componentId: 'test/component/1.0.0',
|
|
1071
|
-
componentSet: 'test-set',
|
|
1072
|
-
componentType: 'server',
|
|
1073
|
-
contentItem: { id: 'en-top' },
|
|
1074
|
-
i18n: {
|
|
1075
|
-
fr: { id: 'fr-top' },
|
|
1076
|
-
},
|
|
1077
|
-
},
|
|
1078
|
-
],
|
|
1079
|
-
side: [
|
|
1080
|
-
{
|
|
1081
|
-
type: 'component',
|
|
1082
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1083
|
-
componentId: 'test/component/1.0.0',
|
|
1084
|
-
componentSet: 'test-set',
|
|
1085
|
-
componentType: 'server',
|
|
1086
|
-
contentItem: { id: 'en-side' },
|
|
1087
|
-
i18n: {
|
|
1088
|
-
fr: { id: 'fr-side' },
|
|
1089
|
-
},
|
|
1090
|
-
},
|
|
1091
|
-
],
|
|
1092
|
-
},
|
|
1093
|
-
};
|
|
1094
|
-
const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
|
|
1095
|
-
const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
|
|
1096
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml(`
|
|
1097
|
-
<div class="top">
|
|
1098
|
-
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-top"/>
|
|
1099
|
-
</div>
|
|
1100
|
-
<div class="side">
|
|
1101
|
-
<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-side"/>
|
|
1102
|
-
</div>
|
|
1103
|
-
`));
|
|
1104
|
-
});
|
|
1105
|
-
it('should render layout with no translations when language config is missing', async () => {
|
|
1106
|
-
const layout = new mocks_1.PageRawLayoutBuilder()
|
|
1107
|
-
.addNode({
|
|
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' }],
|
|
1265
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1114
1266
|
},
|
|
1115
1267
|
],
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
expect(normalizeHtml(result)).toBe(normalizeHtml('English text'));
|
|
1130
|
-
});
|
|
1268
|
+
},
|
|
1269
|
+
};
|
|
1270
|
+
const contentPage = {
|
|
1271
|
+
name: 'layout-raw',
|
|
1272
|
+
content: {
|
|
1273
|
+
main: [developerLayoutNode],
|
|
1274
|
+
},
|
|
1275
|
+
};
|
|
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} -->`);
|
|
1131
1281
|
});
|
|
1132
1282
|
});
|
|
1133
1283
|
describe('Helper functions', () => {
|
|
@@ -1150,169 +1300,1177 @@ describe('Helper functions', () => {
|
|
|
1150
1300
|
expect((0, page_contents_lib_1.isCustomLayout)(layout)).toEqual(false);
|
|
1151
1301
|
});
|
|
1152
1302
|
});
|
|
1153
|
-
describe('
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
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
|
+
},
|
|
1159
1316
|
},
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
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
|
+
},
|
|
1174
1342
|
},
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
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' },
|
|
1184
1353
|
},
|
|
1185
1354
|
},
|
|
1186
|
-
|
|
1187
|
-
|
|
1355
|
+
],
|
|
1356
|
+
},
|
|
1188
1357
|
},
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
{
|
|
1204
|
-
|
|
1205
|
-
|
|
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');
|
|
1421
|
+
});
|
|
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: [
|
|
1430
|
+
{
|
|
1206
1431
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1432
|
+
type: 'fragment',
|
|
1433
|
+
children: [
|
|
1434
|
+
{
|
|
1435
|
+
type: 'text',
|
|
1436
|
+
value: 'English text',
|
|
1437
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1438
|
+
},
|
|
1439
|
+
],
|
|
1440
|
+
i18n: {
|
|
1441
|
+
// No French translation available
|
|
1442
|
+
},
|
|
1207
1443
|
},
|
|
1208
1444
|
],
|
|
1209
|
-
|
|
1210
|
-
|
|
1445
|
+
},
|
|
1446
|
+
},
|
|
1447
|
+
],
|
|
1448
|
+
};
|
|
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');
|
|
1453
|
+
});
|
|
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: [
|
|
1462
|
+
{
|
|
1463
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1464
|
+
type: 'fragment',
|
|
1211
1465
|
children: [
|
|
1212
1466
|
{
|
|
1213
1467
|
type: 'text',
|
|
1214
|
-
value: '
|
|
1468
|
+
value: 'English text',
|
|
1215
1469
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1216
1470
|
},
|
|
1217
1471
|
],
|
|
1472
|
+
i18n: {
|
|
1473
|
+
// No Spanish translation available
|
|
1474
|
+
},
|
|
1218
1475
|
},
|
|
1219
|
-
|
|
1476
|
+
],
|
|
1220
1477
|
},
|
|
1221
|
-
|
|
1222
|
-
|
|
1478
|
+
},
|
|
1479
|
+
],
|
|
1223
1480
|
};
|
|
1224
|
-
(0, page_contents_lib_1.
|
|
1225
|
-
|
|
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);
|
|
1226
1485
|
});
|
|
1227
|
-
it('should
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
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: [
|
|
1495
|
+
{
|
|
1496
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1497
|
+
type: 'fragment',
|
|
1498
|
+
children: [
|
|
1499
|
+
{
|
|
1500
|
+
type: 'text',
|
|
1501
|
+
value: 'English text',
|
|
1502
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1503
|
+
},
|
|
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
|
+
},
|
|
1516
|
+
},
|
|
1517
|
+
],
|
|
1242
1518
|
},
|
|
1243
|
-
|
|
1519
|
+
},
|
|
1520
|
+
],
|
|
1521
|
+
};
|
|
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');
|
|
1528
|
+
});
|
|
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
|
+
},
|
|
1244
1536
|
},
|
|
1537
|
+
layouts: [
|
|
1538
|
+
{
|
|
1539
|
+
name: 'single-column',
|
|
1540
|
+
content: {
|
|
1541
|
+
main: [
|
|
1542
|
+
{
|
|
1543
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1544
|
+
type: 'fragment',
|
|
1545
|
+
children: [
|
|
1546
|
+
{
|
|
1547
|
+
type: 'text',
|
|
1548
|
+
value: 'English text',
|
|
1549
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1550
|
+
},
|
|
1551
|
+
],
|
|
1552
|
+
i18n: {
|
|
1553
|
+
fr: {
|
|
1554
|
+
children: [
|
|
1555
|
+
{
|
|
1556
|
+
type: 'text',
|
|
1557
|
+
value: 'French text',
|
|
1558
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1559
|
+
},
|
|
1560
|
+
],
|
|
1561
|
+
},
|
|
1562
|
+
},
|
|
1563
|
+
},
|
|
1564
|
+
],
|
|
1565
|
+
},
|
|
1566
|
+
},
|
|
1567
|
+
],
|
|
1245
1568
|
};
|
|
1246
|
-
(0, page_contents_lib_1.
|
|
1247
|
-
|
|
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');
|
|
1248
1575
|
});
|
|
1249
|
-
it('should
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
children: [
|
|
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: [
|
|
1258
1584
|
{
|
|
1259
|
-
type: 'text',
|
|
1260
|
-
value: 'English text',
|
|
1261
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
|
+
},
|
|
1262
1618
|
},
|
|
1263
1619
|
],
|
|
1264
|
-
|
|
1265
|
-
|
|
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',
|
|
1266
1662
|
children: [
|
|
1267
1663
|
{
|
|
1268
1664
|
type: 'text',
|
|
1269
|
-
value: '
|
|
1665
|
+
value: 'English fragment',
|
|
1270
1666
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1271
1667
|
},
|
|
1272
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
|
+
},
|
|
1273
1680
|
},
|
|
1274
|
-
|
|
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
|
+
},
|
|
1691
|
+
},
|
|
1692
|
+
{
|
|
1693
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1694
|
+
type: 'variation',
|
|
1695
|
+
default: { node: null },
|
|
1696
|
+
variants: [],
|
|
1697
|
+
},
|
|
1698
|
+
],
|
|
1275
1699
|
},
|
|
1276
|
-
|
|
1700
|
+
},
|
|
1701
|
+
],
|
|
1702
|
+
};
|
|
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');
|
|
1714
|
+
});
|
|
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
|
+
},
|
|
1277
1724
|
},
|
|
1725
|
+
layouts: [
|
|
1726
|
+
{
|
|
1727
|
+
name: 'single-column',
|
|
1728
|
+
content: {
|
|
1729
|
+
main: [
|
|
1730
|
+
{
|
|
1731
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1732
|
+
type: 'fragment',
|
|
1733
|
+
children: [
|
|
1734
|
+
{
|
|
1735
|
+
type: 'text',
|
|
1736
|
+
value: 'English text',
|
|
1737
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1738
|
+
},
|
|
1739
|
+
],
|
|
1740
|
+
i18n: {
|
|
1741
|
+
// No French translation
|
|
1742
|
+
},
|
|
1743
|
+
},
|
|
1744
|
+
],
|
|
1745
|
+
},
|
|
1746
|
+
},
|
|
1747
|
+
],
|
|
1278
1748
|
};
|
|
1279
|
-
(0, page_contents_lib_1.
|
|
1280
|
-
|
|
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);
|
|
1281
1753
|
});
|
|
1282
|
-
it('should
|
|
1283
|
-
const
|
|
1284
|
-
|
|
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: {
|
|
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
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
],
|
|
1816
|
+
},
|
|
1817
|
+
],
|
|
1818
|
+
},
|
|
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: [
|
|
1839
|
+
{
|
|
1840
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1841
|
+
type: 'variation',
|
|
1842
|
+
default: {
|
|
1843
|
+
node: {
|
|
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
|
+
},
|
|
1869
|
+
},
|
|
1870
|
+
],
|
|
1871
|
+
},
|
|
1872
|
+
],
|
|
1873
|
+
},
|
|
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: [
|
|
1894
|
+
{
|
|
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
|
+
],
|
|
1963
|
+
},
|
|
1964
|
+
],
|
|
1965
|
+
},
|
|
1966
|
+
},
|
|
1967
|
+
],
|
|
1968
|
+
};
|
|
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');
|
|
1981
|
+
});
|
|
1982
|
+
it('should handle variant nodes with fallback behavior', () => {
|
|
1983
|
+
const pageContents = {
|
|
1984
|
+
...mockPageContents,
|
|
1985
|
+
layouts: [
|
|
1986
|
+
{
|
|
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
|
+
},
|
|
2039
|
+
},
|
|
2040
|
+
],
|
|
2041
|
+
};
|
|
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,
|
|
2060
|
+
},
|
|
2061
|
+
},
|
|
2062
|
+
},
|
|
2063
|
+
layouts: [
|
|
2064
|
+
{
|
|
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
|
+
},
|
|
2109
|
+
},
|
|
2110
|
+
],
|
|
2111
|
+
};
|
|
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
|
+
],
|
|
2175
|
+
},
|
|
2176
|
+
},
|
|
2177
|
+
],
|
|
2178
|
+
};
|
|
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');
|
|
2187
|
+
});
|
|
2188
|
+
it('should handle deeply nested layout nodes with translatable content', () => {
|
|
2189
|
+
const pageContents = {
|
|
2190
|
+
...mockPageContents,
|
|
2191
|
+
layouts: [
|
|
2192
|
+
{
|
|
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
|
+
},
|
|
2246
|
+
},
|
|
2247
|
+
],
|
|
2248
|
+
};
|
|
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
|
+
],
|
|
2356
|
+
},
|
|
2357
|
+
},
|
|
2358
|
+
],
|
|
2359
|
+
};
|
|
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');
|
|
2379
|
+
});
|
|
2380
|
+
});
|
|
2381
|
+
describe('translatePageContentsWithContent', () => {
|
|
2382
|
+
const mockPageContentsWithContent = {
|
|
2383
|
+
id: 'test-page-with-content-1',
|
|
2384
|
+
name: 'Test Page With Content',
|
|
2385
|
+
config: {
|
|
2386
|
+
languages: {
|
|
2387
|
+
fr: {
|
|
2388
|
+
fallbackToDefault: true,
|
|
2389
|
+
},
|
|
2390
|
+
es: {
|
|
2391
|
+
fallbackToDefault: false,
|
|
2392
|
+
},
|
|
2393
|
+
},
|
|
2394
|
+
},
|
|
2395
|
+
content: {
|
|
2396
|
+
main: [
|
|
2397
|
+
{
|
|
2398
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2399
|
+
type: 'fragment',
|
|
2400
|
+
children: [
|
|
2401
|
+
{
|
|
2402
|
+
type: 'text',
|
|
2403
|
+
value: 'English text',
|
|
2404
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2405
|
+
},
|
|
2406
|
+
],
|
|
2407
|
+
i18n: {
|
|
2408
|
+
fr: {
|
|
2409
|
+
children: [
|
|
2410
|
+
{
|
|
2411
|
+
type: 'text',
|
|
2412
|
+
value: 'French text',
|
|
2413
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2414
|
+
},
|
|
2415
|
+
],
|
|
2416
|
+
},
|
|
2417
|
+
},
|
|
2418
|
+
},
|
|
2419
|
+
{
|
|
2420
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2421
|
+
type: 'component',
|
|
2422
|
+
componentId: 'test/component/1.0.0',
|
|
2423
|
+
componentSet: 'test-set',
|
|
2424
|
+
componentType: 'edge',
|
|
2425
|
+
contentItem: { id: 'en-content' },
|
|
2426
|
+
i18n: {
|
|
2427
|
+
fr: { id: 'fr-content' },
|
|
2428
|
+
},
|
|
2429
|
+
},
|
|
2430
|
+
],
|
|
2431
|
+
},
|
|
2432
|
+
};
|
|
2433
|
+
it('should translate page contents with content to French when language config exists', () => {
|
|
2434
|
+
const pageContents = { ...mockPageContentsWithContent };
|
|
2435
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2436
|
+
// Check main zone
|
|
2437
|
+
const mainFragment = pageContents.content.main[0];
|
|
2438
|
+
const mainComponent = pageContents.content.main[1];
|
|
2439
|
+
expect(mainFragment.children[0].value).toBe('French text');
|
|
2440
|
+
expect(mainFragment).not.toHaveProperty('i18n');
|
|
2441
|
+
expect(mainComponent.contentItem).toEqual({ id: 'fr-content' });
|
|
2442
|
+
expect(mainComponent).not.toHaveProperty('i18n');
|
|
2443
|
+
});
|
|
2444
|
+
it('should fallback to default content when translation is not available and fallbackToDefault is true', () => {
|
|
2445
|
+
const pageContents = {
|
|
2446
|
+
...mockPageContentsWithContent,
|
|
1285
2447
|
content: {
|
|
1286
2448
|
main: [
|
|
1287
2449
|
{
|
|
1288
2450
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1289
|
-
type: '
|
|
1290
|
-
|
|
1291
|
-
|
|
2451
|
+
type: 'fragment',
|
|
2452
|
+
children: [
|
|
2453
|
+
{
|
|
2454
|
+
type: 'text',
|
|
2455
|
+
value: 'English text',
|
|
1292
2456
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1293
|
-
type: 'fragment',
|
|
1294
|
-
children: [{ type: 'text', value: 'Default text' }],
|
|
1295
2457
|
},
|
|
2458
|
+
],
|
|
2459
|
+
i18n: {
|
|
2460
|
+
// No French translation available
|
|
1296
2461
|
},
|
|
1297
|
-
variants: [],
|
|
1298
2462
|
},
|
|
1299
2463
|
],
|
|
1300
2464
|
},
|
|
1301
2465
|
};
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
expect(
|
|
2466
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2467
|
+
const fragment = pageContents.content.main[0];
|
|
2468
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2469
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
1305
2470
|
});
|
|
1306
|
-
it('should not
|
|
1307
|
-
const
|
|
1308
|
-
...
|
|
1309
|
-
lang: {
|
|
1310
|
-
code: 'fr',
|
|
1311
|
-
fallbackToDefault: false,
|
|
1312
|
-
},
|
|
1313
|
-
};
|
|
1314
|
-
const layout = {
|
|
1315
|
-
name: 'layout-raw',
|
|
2471
|
+
it('should not fallback to default content when translation is not available and fallbackToDefault is false', () => {
|
|
2472
|
+
const pageContents = {
|
|
2473
|
+
...mockPageContentsWithContent,
|
|
1316
2474
|
content: {
|
|
1317
2475
|
main: [
|
|
1318
2476
|
{
|
|
@@ -1322,77 +2480,76 @@ describe('translateLanguageNodes', () => {
|
|
|
1322
2480
|
{
|
|
1323
2481
|
type: 'text',
|
|
1324
2482
|
value: 'English text',
|
|
2483
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1325
2484
|
},
|
|
1326
2485
|
],
|
|
1327
2486
|
i18n: {
|
|
1328
|
-
|
|
1329
|
-
children: [
|
|
1330
|
-
{
|
|
1331
|
-
type: 'text',
|
|
1332
|
-
value: 'Spanish text',
|
|
1333
|
-
},
|
|
1334
|
-
],
|
|
1335
|
-
},
|
|
2487
|
+
// No Spanish translation available
|
|
1336
2488
|
},
|
|
1337
2489
|
},
|
|
1338
2490
|
],
|
|
1339
2491
|
},
|
|
1340
2492
|
};
|
|
1341
|
-
(0, page_contents_lib_1.
|
|
1342
|
-
|
|
2493
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'es');
|
|
2494
|
+
// Should not be translated since fallbackToDefault is false for Spanish
|
|
2495
|
+
// The node should be removed from the array since no translation is available
|
|
2496
|
+
expect(pageContents.content.main).toHaveLength(0);
|
|
1343
2497
|
});
|
|
1344
|
-
it('should
|
|
1345
|
-
const
|
|
1346
|
-
...
|
|
1347
|
-
|
|
1348
|
-
code: 'jp',
|
|
1349
|
-
fallbackToDefault: true,
|
|
1350
|
-
},
|
|
1351
|
-
};
|
|
1352
|
-
const layout = {
|
|
1353
|
-
name: 'layout-raw',
|
|
2498
|
+
it('should handle page contents without language config', () => {
|
|
2499
|
+
const pageContents = {
|
|
2500
|
+
...mockPageContentsWithContent,
|
|
2501
|
+
config: undefined,
|
|
1354
2502
|
content: {
|
|
1355
2503
|
main: [
|
|
1356
2504
|
{
|
|
1357
|
-
// has both "fr" and "jp" translations
|
|
1358
2505
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1359
2506
|
type: 'fragment',
|
|
1360
2507
|
children: [
|
|
1361
2508
|
{
|
|
1362
2509
|
type: 'text',
|
|
1363
|
-
value: 'English text
|
|
1364
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1365
|
-
},
|
|
1366
|
-
],
|
|
1367
|
-
i18n: {
|
|
1368
|
-
fr: {
|
|
1369
|
-
children: [
|
|
1370
|
-
{
|
|
1371
|
-
type: 'text',
|
|
1372
|
-
value: 'French text 1',
|
|
1373
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1374
|
-
},
|
|
1375
|
-
],
|
|
2510
|
+
value: 'English text',
|
|
2511
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
1376
2512
|
},
|
|
1377
|
-
|
|
2513
|
+
],
|
|
2514
|
+
i18n: {
|
|
2515
|
+
fr: {
|
|
1378
2516
|
children: [
|
|
1379
2517
|
{
|
|
1380
2518
|
type: 'text',
|
|
1381
|
-
value: '
|
|
2519
|
+
value: 'French text',
|
|
1382
2520
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1383
2521
|
},
|
|
1384
2522
|
],
|
|
1385
2523
|
},
|
|
1386
2524
|
},
|
|
1387
2525
|
},
|
|
2526
|
+
],
|
|
2527
|
+
},
|
|
2528
|
+
};
|
|
2529
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2530
|
+
// Should not translate since no language config exists
|
|
2531
|
+
// The i18n property should be removed but content preserved
|
|
2532
|
+
const fragment = pageContents.content.main[0];
|
|
2533
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2534
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2535
|
+
});
|
|
2536
|
+
it('should handle page contents with language config but no specific language', () => {
|
|
2537
|
+
const pageContents = {
|
|
2538
|
+
...mockPageContentsWithContent,
|
|
2539
|
+
config: {
|
|
2540
|
+
languages: {
|
|
2541
|
+
// No French config
|
|
2542
|
+
},
|
|
2543
|
+
},
|
|
2544
|
+
content: {
|
|
2545
|
+
main: [
|
|
1388
2546
|
{
|
|
1389
|
-
// has "fr" translation but no "jp" translation
|
|
1390
2547
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1391
2548
|
type: 'fragment',
|
|
1392
2549
|
children: [
|
|
1393
2550
|
{
|
|
1394
2551
|
type: 'text',
|
|
1395
|
-
value: 'English text
|
|
2552
|
+
value: 'English text',
|
|
1396
2553
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1397
2554
|
},
|
|
1398
2555
|
],
|
|
@@ -1401,54 +2558,100 @@ describe('translateLanguageNodes', () => {
|
|
|
1401
2558
|
children: [
|
|
1402
2559
|
{
|
|
1403
2560
|
type: 'text',
|
|
1404
|
-
value: 'French text
|
|
2561
|
+
value: 'French text',
|
|
1405
2562
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1406
2563
|
},
|
|
1407
2564
|
],
|
|
1408
2565
|
},
|
|
1409
2566
|
},
|
|
1410
2567
|
},
|
|
2568
|
+
],
|
|
2569
|
+
},
|
|
2570
|
+
};
|
|
2571
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2572
|
+
// Should not translate since no French language config exists
|
|
2573
|
+
// The i18n property should be removed but content preserved
|
|
2574
|
+
const fragment = pageContents.content.main[0];
|
|
2575
|
+
expect(fragment.children[0].value).toBe('English text');
|
|
2576
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2577
|
+
});
|
|
2578
|
+
it('should handle nested layout nodes in page contents with content property', () => {
|
|
2579
|
+
const pageContents = {
|
|
2580
|
+
...mockPageContentsWithContent,
|
|
2581
|
+
content: {
|
|
2582
|
+
main: [
|
|
1411
2583
|
{
|
|
1412
|
-
// has no translations
|
|
1413
2584
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1414
|
-
type: '
|
|
1415
|
-
|
|
1416
|
-
{
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
2585
|
+
type: 'layout',
|
|
2586
|
+
layout: {
|
|
2587
|
+
template: '<div>{{zones.inner}}</div>',
|
|
2588
|
+
name: 'nested-layout',
|
|
2589
|
+
options: {},
|
|
2590
|
+
},
|
|
2591
|
+
content: {
|
|
2592
|
+
inner: [
|
|
2593
|
+
{
|
|
2594
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2595
|
+
type: 'fragment',
|
|
2596
|
+
children: [
|
|
2597
|
+
{
|
|
2598
|
+
type: 'text',
|
|
2599
|
+
value: 'Nested English',
|
|
2600
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2601
|
+
},
|
|
2602
|
+
],
|
|
2603
|
+
i18n: {
|
|
2604
|
+
fr: {
|
|
2605
|
+
children: [
|
|
2606
|
+
{
|
|
2607
|
+
type: 'text',
|
|
2608
|
+
value: 'Nested French',
|
|
2609
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2610
|
+
},
|
|
2611
|
+
],
|
|
2612
|
+
},
|
|
2613
|
+
},
|
|
2614
|
+
},
|
|
2615
|
+
],
|
|
2616
|
+
},
|
|
1422
2617
|
},
|
|
1423
2618
|
],
|
|
1424
2619
|
},
|
|
1425
2620
|
};
|
|
1426
|
-
(0, page_contents_lib_1.
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
expect(
|
|
1430
|
-
expect(
|
|
1431
|
-
});
|
|
1432
|
-
it('should
|
|
1433
|
-
const
|
|
1434
|
-
...
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
fallbackToDefault: false,
|
|
2621
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2622
|
+
const layoutNode = pageContents.content.main[0];
|
|
2623
|
+
const nestedFragment = layoutNode.content.inner[0];
|
|
2624
|
+
expect(nestedFragment.children[0].value).toBe('Nested French');
|
|
2625
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
2626
|
+
});
|
|
2627
|
+
it('should handle page contents with empty content', () => {
|
|
2628
|
+
const pageContents = {
|
|
2629
|
+
...mockPageContentsWithContent,
|
|
2630
|
+
content: {
|
|
2631
|
+
main: [],
|
|
1438
2632
|
},
|
|
1439
2633
|
};
|
|
1440
|
-
|
|
1441
|
-
|
|
2634
|
+
expect(() => (0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr')).not.toThrow();
|
|
2635
|
+
});
|
|
2636
|
+
it('should handle page contents with no content property', () => {
|
|
2637
|
+
const pageContents = {
|
|
2638
|
+
...mockPageContentsWithContent,
|
|
2639
|
+
content: undefined,
|
|
2640
|
+
};
|
|
2641
|
+
expect(() => (0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr')).not.toThrow();
|
|
2642
|
+
});
|
|
2643
|
+
it('should handle mixed content types in content', () => {
|
|
2644
|
+
const pageContents = {
|
|
2645
|
+
...mockPageContentsWithContent,
|
|
1442
2646
|
content: {
|
|
1443
2647
|
main: [
|
|
1444
2648
|
{
|
|
1445
|
-
// has both "fr" and "jp" translations
|
|
1446
2649
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1447
2650
|
type: 'fragment',
|
|
1448
2651
|
children: [
|
|
1449
2652
|
{
|
|
1450
2653
|
type: 'text',
|
|
1451
|
-
value: 'English
|
|
2654
|
+
value: 'English fragment',
|
|
1452
2655
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1453
2656
|
},
|
|
1454
2657
|
],
|
|
@@ -1457,16 +2660,7 @@ describe('translateLanguageNodes', () => {
|
|
|
1457
2660
|
children: [
|
|
1458
2661
|
{
|
|
1459
2662
|
type: 'text',
|
|
1460
|
-
value: 'French
|
|
1461
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1462
|
-
},
|
|
1463
|
-
],
|
|
1464
|
-
},
|
|
1465
|
-
jp: {
|
|
1466
|
-
children: [
|
|
1467
|
-
{
|
|
1468
|
-
type: 'text',
|
|
1469
|
-
value: 'Japanese text 1',
|
|
2663
|
+
value: 'French fragment',
|
|
1470
2664
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1471
2665
|
},
|
|
1472
2666
|
],
|
|
@@ -1474,215 +2668,264 @@ describe('translateLanguageNodes', () => {
|
|
|
1474
2668
|
},
|
|
1475
2669
|
},
|
|
1476
2670
|
{
|
|
1477
|
-
|
|
2671
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2672
|
+
type: 'component',
|
|
2673
|
+
componentId: 'test/component/1.0.0',
|
|
2674
|
+
componentSet: 'test-set',
|
|
2675
|
+
componentType: 'edge',
|
|
2676
|
+
contentItem: { id: 'en-component' },
|
|
2677
|
+
i18n: {
|
|
2678
|
+
fr: { id: 'fr-component' },
|
|
2679
|
+
},
|
|
2680
|
+
},
|
|
2681
|
+
{
|
|
2682
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2683
|
+
type: 'variation',
|
|
2684
|
+
default: { node: null },
|
|
2685
|
+
variants: [],
|
|
2686
|
+
},
|
|
2687
|
+
],
|
|
2688
|
+
},
|
|
2689
|
+
};
|
|
2690
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2691
|
+
const mainContent = pageContents.content.main;
|
|
2692
|
+
const fragment = mainContent[0];
|
|
2693
|
+
const component = mainContent[1];
|
|
2694
|
+
const variation = mainContent[2];
|
|
2695
|
+
expect(fragment.children[0].value).toBe('French fragment');
|
|
2696
|
+
expect(fragment).not.toHaveProperty('i18n');
|
|
2697
|
+
expect(component.contentItem).toEqual({ id: 'fr-component' });
|
|
2698
|
+
expect(component).not.toHaveProperty('i18n');
|
|
2699
|
+
// Variation should remain unchanged
|
|
2700
|
+
expect(variation.type).toBe('variation');
|
|
2701
|
+
});
|
|
2702
|
+
it('should handle language config with custom fallback settings', () => {
|
|
2703
|
+
const pageContents = {
|
|
2704
|
+
...mockPageContentsWithContent,
|
|
2705
|
+
config: {
|
|
2706
|
+
languages: {
|
|
2707
|
+
fr: {
|
|
2708
|
+
fallbackToDefault: false,
|
|
2709
|
+
},
|
|
2710
|
+
},
|
|
2711
|
+
},
|
|
2712
|
+
content: {
|
|
2713
|
+
main: [
|
|
2714
|
+
{
|
|
1478
2715
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1479
2716
|
type: 'fragment',
|
|
1480
2717
|
children: [
|
|
1481
2718
|
{
|
|
1482
2719
|
type: 'text',
|
|
1483
|
-
value: 'English text
|
|
2720
|
+
value: 'English text',
|
|
1484
2721
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1485
2722
|
},
|
|
1486
2723
|
],
|
|
1487
2724
|
i18n: {
|
|
1488
|
-
|
|
2725
|
+
// No French translation
|
|
2726
|
+
},
|
|
2727
|
+
},
|
|
2728
|
+
],
|
|
2729
|
+
},
|
|
2730
|
+
};
|
|
2731
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2732
|
+
// Should not be translated since fallbackToDefault is false and no translation exists
|
|
2733
|
+
// The node should be removed from the array since no translation is available
|
|
2734
|
+
expect(pageContents.content.main).toHaveLength(0);
|
|
2735
|
+
});
|
|
2736
|
+
it('should handle variant nodes with translatable default content', () => {
|
|
2737
|
+
const pageContents = {
|
|
2738
|
+
...mockPageContentsWithContent,
|
|
2739
|
+
content: {
|
|
2740
|
+
main: [
|
|
2741
|
+
{
|
|
2742
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2743
|
+
type: 'variation',
|
|
2744
|
+
default: {
|
|
2745
|
+
node: {
|
|
2746
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2747
|
+
type: 'fragment',
|
|
1489
2748
|
children: [
|
|
1490
2749
|
{
|
|
1491
2750
|
type: 'text',
|
|
1492
|
-
value: '
|
|
2751
|
+
value: 'Default English',
|
|
1493
2752
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1494
2753
|
},
|
|
1495
2754
|
],
|
|
2755
|
+
i18n: {
|
|
2756
|
+
fr: {
|
|
2757
|
+
children: [
|
|
2758
|
+
{
|
|
2759
|
+
type: 'text',
|
|
2760
|
+
value: 'Default French',
|
|
2761
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2762
|
+
},
|
|
2763
|
+
],
|
|
2764
|
+
},
|
|
2765
|
+
},
|
|
1496
2766
|
},
|
|
1497
2767
|
},
|
|
1498
|
-
|
|
1499
|
-
{
|
|
1500
|
-
// has no translations
|
|
1501
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1502
|
-
type: 'fragment',
|
|
1503
|
-
children: [
|
|
2768
|
+
variants: [
|
|
1504
2769
|
{
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
2770
|
+
conditions: { segment: { code: 'is-student' } },
|
|
2771
|
+
node: {
|
|
2772
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2773
|
+
type: 'fragment',
|
|
2774
|
+
children: [
|
|
2775
|
+
{
|
|
2776
|
+
type: 'text',
|
|
2777
|
+
value: 'Variant English',
|
|
2778
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2779
|
+
},
|
|
2780
|
+
],
|
|
2781
|
+
i18n: {
|
|
2782
|
+
fr: {
|
|
2783
|
+
children: [
|
|
2784
|
+
{
|
|
2785
|
+
type: 'text',
|
|
2786
|
+
value: 'Variant French',
|
|
2787
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2788
|
+
},
|
|
2789
|
+
],
|
|
2790
|
+
},
|
|
2791
|
+
},
|
|
2792
|
+
},
|
|
1508
2793
|
},
|
|
1509
2794
|
],
|
|
1510
2795
|
},
|
|
1511
2796
|
],
|
|
1512
2797
|
},
|
|
1513
2798
|
};
|
|
1514
|
-
(0, page_contents_lib_1.
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
2799
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2800
|
+
const variation = pageContents.content.main[0];
|
|
2801
|
+
const defaultNode = variation.default.node;
|
|
2802
|
+
const variantNode = variation.variants[0].node;
|
|
2803
|
+
expect(defaultNode.children[0].value).toBe('Default French');
|
|
2804
|
+
expect(defaultNode).not.toHaveProperty('i18n');
|
|
2805
|
+
expect(variantNode.children[0].value).toBe('Variant French');
|
|
2806
|
+
expect(variantNode).not.toHaveProperty('i18n');
|
|
1518
2807
|
});
|
|
1519
|
-
it('should
|
|
1520
|
-
const
|
|
1521
|
-
|
|
1522
|
-
type: 'fragment',
|
|
1523
|
-
children: [
|
|
1524
|
-
{
|
|
1525
|
-
type: 'text',
|
|
1526
|
-
value: 'English text',
|
|
1527
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1528
|
-
},
|
|
1529
|
-
],
|
|
1530
|
-
i18n: {
|
|
1531
|
-
fr: {
|
|
1532
|
-
children: [
|
|
1533
|
-
{
|
|
1534
|
-
type: 'text',
|
|
1535
|
-
value: 'French text',
|
|
1536
|
-
},
|
|
1537
|
-
],
|
|
1538
|
-
},
|
|
1539
|
-
},
|
|
1540
|
-
};
|
|
1541
|
-
const layout = {
|
|
1542
|
-
name: 'layout-raw',
|
|
2808
|
+
it('should handle nested layout nodes in page contents with content', () => {
|
|
2809
|
+
const pageContents = {
|
|
2810
|
+
...mockPageContentsWithContent,
|
|
1543
2811
|
content: {
|
|
1544
2812
|
main: [
|
|
1545
2813
|
{
|
|
1546
2814
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1547
2815
|
type: 'layout',
|
|
1548
2816
|
layout: {
|
|
1549
|
-
template: '<div>{{zones.
|
|
1550
|
-
name: '
|
|
2817
|
+
template: '<div>{{zones.inner}}</div>',
|
|
2818
|
+
name: 'nested-layout',
|
|
1551
2819
|
options: {},
|
|
1552
2820
|
},
|
|
1553
2821
|
content: {
|
|
1554
|
-
|
|
2822
|
+
inner: [
|
|
2823
|
+
{
|
|
2824
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2825
|
+
type: 'fragment',
|
|
2826
|
+
children: [
|
|
2827
|
+
{
|
|
2828
|
+
type: 'text',
|
|
2829
|
+
value: 'Nested English',
|
|
2830
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2831
|
+
},
|
|
2832
|
+
],
|
|
2833
|
+
i18n: {
|
|
2834
|
+
fr: {
|
|
2835
|
+
children: [
|
|
2836
|
+
{
|
|
2837
|
+
type: 'text',
|
|
2838
|
+
value: 'Nested French',
|
|
2839
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2840
|
+
},
|
|
2841
|
+
],
|
|
2842
|
+
},
|
|
2843
|
+
},
|
|
2844
|
+
},
|
|
2845
|
+
],
|
|
1555
2846
|
},
|
|
1556
2847
|
},
|
|
1557
2848
|
],
|
|
1558
2849
|
},
|
|
1559
2850
|
};
|
|
1560
|
-
(0, page_contents_lib_1.
|
|
1561
|
-
|
|
1562
|
-
const
|
|
1563
|
-
|
|
1564
|
-
expect(
|
|
1565
|
-
});
|
|
1566
|
-
it('should
|
|
1567
|
-
const
|
|
1568
|
-
|
|
1569
|
-
type: 'fragment',
|
|
1570
|
-
children: [
|
|
1571
|
-
{
|
|
1572
|
-
type: 'text',
|
|
1573
|
-
value: 'English Title',
|
|
1574
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1575
|
-
},
|
|
1576
|
-
],
|
|
1577
|
-
i18n: {
|
|
1578
|
-
fr: {
|
|
1579
|
-
children: [
|
|
1580
|
-
{
|
|
1581
|
-
type: 'text',
|
|
1582
|
-
value: 'French Title',
|
|
1583
|
-
},
|
|
1584
|
-
],
|
|
1585
|
-
},
|
|
1586
|
-
},
|
|
1587
|
-
};
|
|
1588
|
-
const componentNode = {
|
|
1589
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1590
|
-
type: 'component',
|
|
1591
|
-
componentId: 'test/component/1.0.0',
|
|
1592
|
-
componentSet: 'test-set',
|
|
1593
|
-
componentType: 'server',
|
|
1594
|
-
contentItem: { id: 'en-content' },
|
|
1595
|
-
i18n: {
|
|
1596
|
-
fr: { id: 'fr-content' },
|
|
1597
|
-
},
|
|
1598
|
-
};
|
|
1599
|
-
const layout = {
|
|
1600
|
-
name: 'layout-raw',
|
|
2851
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2852
|
+
const layoutNode = pageContents.content.main[0];
|
|
2853
|
+
const nestedFragment = layoutNode.content.inner[0];
|
|
2854
|
+
expect(nestedFragment.children[0].value).toBe('Nested French');
|
|
2855
|
+
expect(nestedFragment).not.toHaveProperty('i18n');
|
|
2856
|
+
});
|
|
2857
|
+
it('should handle multiple content zones with different translation scenarios', () => {
|
|
2858
|
+
const pageContents = {
|
|
2859
|
+
...mockPageContentsWithContent,
|
|
1601
2860
|
content: {
|
|
1602
|
-
|
|
2861
|
+
header: [
|
|
1603
2862
|
{
|
|
1604
2863
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1605
|
-
type: '
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
2864
|
+
type: 'fragment',
|
|
2865
|
+
children: [
|
|
2866
|
+
{
|
|
2867
|
+
type: 'text',
|
|
2868
|
+
value: 'Header English',
|
|
2869
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2870
|
+
},
|
|
2871
|
+
],
|
|
2872
|
+
i18n: {
|
|
2873
|
+
fr: {
|
|
2874
|
+
children: [
|
|
2875
|
+
{
|
|
2876
|
+
type: 'text',
|
|
2877
|
+
value: 'Header French',
|
|
2878
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2879
|
+
},
|
|
2880
|
+
],
|
|
2881
|
+
},
|
|
1614
2882
|
},
|
|
1615
2883
|
},
|
|
1616
2884
|
],
|
|
1617
|
-
},
|
|
1618
|
-
};
|
|
1619
|
-
(0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
|
|
1620
|
-
// Verify both content sections inside the layout node are translated
|
|
1621
|
-
const layoutNode = layout.content.main[0];
|
|
1622
|
-
const translatedFragment = layoutNode.content.title[0];
|
|
1623
|
-
const translatedComponent = layoutNode.content.content[0];
|
|
1624
|
-
expect(translatedFragment.children[0].value).toBe('French Title');
|
|
1625
|
-
expect(translatedComponent.contentItem.id).toBe('fr-content');
|
|
1626
|
-
});
|
|
1627
|
-
it('should handle nested layout nodes with translations', () => {
|
|
1628
|
-
const fragmentNode = {
|
|
1629
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1630
|
-
type: 'fragment',
|
|
1631
|
-
children: [
|
|
1632
|
-
{
|
|
1633
|
-
type: 'text',
|
|
1634
|
-
value: 'English text',
|
|
1635
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1636
|
-
},
|
|
1637
|
-
],
|
|
1638
|
-
i18n: {
|
|
1639
|
-
fr: {
|
|
1640
|
-
children: [
|
|
1641
|
-
{
|
|
1642
|
-
type: 'text',
|
|
1643
|
-
value: 'French text',
|
|
1644
|
-
},
|
|
1645
|
-
],
|
|
1646
|
-
},
|
|
1647
|
-
},
|
|
1648
|
-
};
|
|
1649
|
-
const innerLayoutNode = {
|
|
1650
|
-
nodeId: (0, crypto_1.randomUUID)(),
|
|
1651
|
-
type: 'layout',
|
|
1652
|
-
layout: {
|
|
1653
|
-
template: '<div>{{zones.inner}}</div>',
|
|
1654
|
-
name: 'inner-layout',
|
|
1655
|
-
options: {},
|
|
1656
|
-
},
|
|
1657
|
-
content: {
|
|
1658
|
-
inner: [fragmentNode],
|
|
1659
|
-
},
|
|
1660
|
-
};
|
|
1661
|
-
const layout = {
|
|
1662
|
-
name: 'layout-raw',
|
|
1663
|
-
content: {
|
|
1664
2885
|
main: [
|
|
1665
2886
|
{
|
|
1666
2887
|
nodeId: (0, crypto_1.randomUUID)(),
|
|
1667
|
-
type: '
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
2888
|
+
type: 'component',
|
|
2889
|
+
componentId: 'test/component/1.0.0',
|
|
2890
|
+
componentSet: 'test-set',
|
|
2891
|
+
componentType: 'edge',
|
|
2892
|
+
contentItem: { id: 'main-en' },
|
|
2893
|
+
i18n: {
|
|
2894
|
+
fr: { id: 'main-fr' },
|
|
1672
2895
|
},
|
|
1673
|
-
|
|
1674
|
-
|
|
2896
|
+
},
|
|
2897
|
+
],
|
|
2898
|
+
footer: [
|
|
2899
|
+
{
|
|
2900
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2901
|
+
type: 'fragment',
|
|
2902
|
+
children: [
|
|
2903
|
+
{
|
|
2904
|
+
type: 'text',
|
|
2905
|
+
value: 'Footer English',
|
|
2906
|
+
nodeId: (0, crypto_1.randomUUID)(),
|
|
2907
|
+
},
|
|
2908
|
+
],
|
|
2909
|
+
i18n: {
|
|
2910
|
+
// No French translation
|
|
1675
2911
|
},
|
|
1676
2912
|
},
|
|
1677
2913
|
],
|
|
1678
2914
|
},
|
|
1679
2915
|
};
|
|
1680
|
-
(0, page_contents_lib_1.
|
|
1681
|
-
//
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
2916
|
+
(0, page_contents_lib_1.translatePageContentsWithContent)(pageContents, 'fr');
|
|
2917
|
+
// Check header zone
|
|
2918
|
+
const headerFragment = pageContents.content.header[0];
|
|
2919
|
+
expect(headerFragment.children[0].value).toBe('Header French');
|
|
2920
|
+
expect(headerFragment).not.toHaveProperty('i18n');
|
|
2921
|
+
// Check main zone
|
|
2922
|
+
const mainComponent = pageContents.content.main[0];
|
|
2923
|
+
expect(mainComponent.contentItem).toEqual({ id: 'main-fr' });
|
|
2924
|
+
expect(mainComponent).not.toHaveProperty('i18n');
|
|
2925
|
+
// Check footer zone - should fallback to English since fallbackToDefault is true
|
|
2926
|
+
const footerFragment = pageContents.content.footer[0];
|
|
2927
|
+
expect(footerFragment.children[0].value).toBe('Footer English');
|
|
2928
|
+
expect(footerFragment).not.toHaveProperty('i18n');
|
|
1686
2929
|
});
|
|
1687
2930
|
});
|
|
1688
2931
|
//# sourceMappingURL=page-contents-lib.spec.js.map
|