@squiz/dx-page-contents-lib 1.79.0 → 1.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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(normalizeHtml(result)).toBe(normalizeHtml(`<!-- start:layout:article-layout:${developerLayoutNode.nodeId} --><article class="article-layout"><h1><!-- start:zone:title:${developerLayoutNode.nodeId} -->Article Title<!-- end:zone:title:${developerLayoutNode.nodeId} --></h1><div class="content"><!-- start:zone:body:${developerLayoutNode.nodeId} -->Article content goes here.<!-- end:zone:body:${developerLayoutNode.nodeId} --></div></article><!-- end:layout:article-layout:${developerLayoutNode.nodeId} -->`));
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 expectedInnerHtml = `<!-- start:layout:inner-layout:${innerLayoutNode.nodeId} --><div class="inner-layout"><!-- start:zone:content:${innerLayoutNode.nodeId} -->Inner content<!-- end:zone:content:${innerLayoutNode.nodeId} --></div><!-- end:layout:inner-layout:${innerLayoutNode.nodeId} -->`;
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
- describe('with language translation', () => {
970
- const langConfig = {
971
- ...config,
972
- lang: {
973
- code: 'fr',
974
- fallbackToDefault: true,
975
- },
976
- };
977
- it('should render translated fragment nodes', async () => {
978
- const layout = new mocks_1.PageRawLayoutBuilder()
979
- .addNode({
980
- nodeId: (0, crypto_1.randomUUID)(),
981
- type: 'fragment',
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
- i18n: {
1033
- fr: {
1034
- children: [
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
- .addNode({
1044
- // Untranslated component
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: 'text',
1113
- value: 'English text',
1263
+ type: 'fragment',
1264
+ children: [{ type: 'text', value: 'Fragment content' }],
1265
+ nodeId: (0, crypto_1.randomUUID)(),
1114
1266
  },
1115
1267
  ],
1116
- i18n: {
1117
- fr: {
1118
- children: [
1119
- {
1120
- type: 'text',
1121
- value: 'French text',
1122
- },
1123
- ],
1124
- },
1125
- },
1126
- })
1127
- .build();
1128
- const result = await (0, page_contents_lib_1.renderLayout)(layout, config); // Using config without lang
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,539 +1300,1082 @@ describe('Helper functions', () => {
1150
1300
  expect((0, page_contents_lib_1.isCustomLayout)(layout)).toEqual(false);
1151
1301
  });
1152
1302
  });
1153
- describe('translateLanguageNodes', () => {
1154
- const config = {
1155
- componentRootUrl: 'https://mock.url/__dxp/service/components-render',
1156
- lang: {
1157
- code: 'fr',
1158
- fallbackToDefault: true,
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
- it('should return early if no language config is provided', () => {
1162
- const layout = {
1163
- name: 'layout-raw',
1164
- content: {
1165
- main: [
1166
- {
1167
- nodeId: (0, crypto_1.randomUUID)(),
1168
- type: 'fragment',
1169
- children: [
1170
- {
1171
- type: 'text',
1172
- value: 'English text',
1173
- nodeId: '123',
1174
- },
1175
- ],
1176
- i18n: {
1177
- fr: {
1178
- children: [
1179
- {
1180
- type: 'text',
1181
- value: 'French text',
1182
- },
1183
- ],
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
+ },
1184
1342
  },
1185
1343
  },
1186
- },
1187
- ],
1188
- },
1189
- };
1190
- const configWithoutLang = { ...config, lang: undefined };
1191
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, configWithoutLang);
1192
- expect(layout.content.main[0].children[0].value).toBe('English text');
1193
- });
1194
- it('should translate fragment nodes when translation is available', () => {
1195
- const layout = {
1196
- name: 'layout-raw',
1197
- content: {
1198
- main: [
1199
- {
1200
- nodeId: (0, crypto_1.randomUUID)(),
1201
- type: 'fragment',
1202
- children: [
1203
- {
1204
- type: 'text',
1205
- value: 'English text',
1206
- nodeId: (0, crypto_1.randomUUID)(),
1207
- },
1208
- ],
1209
- i18n: {
1210
- fr: {
1211
- children: [
1212
- {
1213
- type: 'text',
1214
- value: 'French text',
1215
- nodeId: (0, crypto_1.randomUUID)(),
1216
- },
1217
- ],
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' },
1218
1353
  },
1219
1354
  },
1220
- },
1221
- ],
1355
+ ],
1356
+ },
1222
1357
  },
1223
- };
1224
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1225
- expect(layout.content.main[0].children[0].value).toBe('French text');
1226
- });
1227
- it('should translate component nodes when translation is available', () => {
1228
- const layout = {
1229
- name: 'layout-raw',
1230
- content: {
1231
- main: [
1232
- {
1233
- nodeId: (0, crypto_1.randomUUID)(),
1234
- type: 'component',
1235
- componentId: 'test/component/1.0.0',
1236
- componentSet: 'test-set',
1237
- componentType: 'edge',
1238
- contentItem: { id: 'en-content' },
1239
- i18n: {
1240
- fr: { id: 'fr-content' },
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
+ },
1241
1383
  },
1242
- },
1243
- ],
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
+ },
1244
1399
  },
1245
- };
1246
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1247
- expect(layout.content.main[0].contentItem.id).toBe('fr-content');
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');
1248
1421
  });
1249
- it('should fallback to default content when translation is not available and fallback is enabled', () => {
1250
- const layout = {
1251
- name: 'layout-raw',
1252
- content: {
1253
- main: [
1254
- {
1255
- nodeId: (0, crypto_1.randomUUID)(),
1256
- type: 'fragment',
1257
- children: [
1422
+ it('should fallback to default content when translation is not available and fallbackToDefault is true', () => {
1423
+ const pageContents = {
1424
+ ...mockPageContents,
1425
+ layouts: [
1426
+ {
1427
+ name: 'single-column',
1428
+ content: {
1429
+ main: [
1258
1430
  {
1259
- type: 'text',
1260
- value: 'English text',
1261
1431
  nodeId: (0, crypto_1.randomUUID)(),
1262
- },
1263
- ],
1264
- i18n: {
1265
- es: {
1432
+ type: 'fragment',
1266
1433
  children: [
1267
1434
  {
1268
1435
  type: 'text',
1269
- value: 'Spanish text',
1436
+ value: 'English text',
1270
1437
  nodeId: (0, crypto_1.randomUUID)(),
1271
1438
  },
1272
1439
  ],
1440
+ i18n: {
1441
+ // No French translation available
1442
+ },
1273
1443
  },
1274
- },
1444
+ ],
1275
1445
  },
1276
- ],
1277
- },
1446
+ },
1447
+ ],
1278
1448
  };
1279
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1280
- expect(layout.content.main[0].children[0].value).toBe('English text');
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');
1281
1453
  });
1282
- it('should skip translation for non-translatable node types', () => {
1283
- const layout = {
1284
- name: 'layout-raw',
1285
- content: {
1286
- main: [
1287
- {
1288
- nodeId: (0, crypto_1.randomUUID)(),
1289
- type: 'variation',
1290
- default: {
1291
- node: {
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
+ {
1292
1463
  nodeId: (0, crypto_1.randomUUID)(),
1293
1464
  type: 'fragment',
1294
- children: [{ type: 'text', value: 'Default text' }],
1295
- },
1296
- },
1297
- variants: [],
1298
- },
1299
- ],
1300
- },
1301
- };
1302
- const originalLayout = { ...layout };
1303
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1304
- expect(layout).toEqual(originalLayout);
1305
- });
1306
- it('should not include node when translation is missing and fallback is disabled', () => {
1307
- const configWithoutFallback = {
1308
- ...config,
1309
- lang: {
1310
- code: 'fr',
1311
- fallbackToDefault: false,
1312
- },
1313
- };
1314
- const layout = {
1315
- name: 'layout-raw',
1316
- content: {
1317
- main: [
1318
- {
1319
- nodeId: (0, crypto_1.randomUUID)(),
1320
- type: 'fragment',
1321
- children: [
1322
- {
1323
- type: 'text',
1324
- value: 'English text',
1325
- },
1326
- ],
1327
- i18n: {
1328
- es: {
1329
1465
  children: [
1330
1466
  {
1331
1467
  type: 'text',
1332
- value: 'Spanish text',
1468
+ value: 'English text',
1469
+ nodeId: (0, crypto_1.randomUUID)(),
1333
1470
  },
1334
1471
  ],
1472
+ i18n: {
1473
+ // No Spanish translation available
1474
+ },
1335
1475
  },
1336
- },
1476
+ ],
1337
1477
  },
1338
- ],
1339
- },
1478
+ },
1479
+ ],
1340
1480
  };
1341
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, configWithoutFallback);
1342
- expect(layout.content.main).toHaveLength(0);
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);
1343
1485
  });
1344
- it('should translate multiple nodes in a single layout with fallback to true', () => {
1345
- const langConfig = {
1346
- ...config,
1347
- lang: {
1348
- code: 'jp',
1349
- fallbackToDefault: true,
1350
- },
1351
- };
1352
- const layout = {
1353
- name: 'layout-raw',
1354
- content: {
1355
- main: [
1356
- {
1357
- // has both "fr" and "jp" translations
1358
- nodeId: (0, crypto_1.randomUUID)(),
1359
- type: 'fragment',
1360
- children: [
1486
+ it('should handle page contents without language config', () => {
1487
+ const pageContents = {
1488
+ ...mockPageContents,
1489
+ config: undefined,
1490
+ layouts: [
1491
+ {
1492
+ name: 'single-column',
1493
+ content: {
1494
+ main: [
1361
1495
  {
1362
- type: 'text',
1363
- value: 'English text 1',
1364
1496
  nodeId: (0, crypto_1.randomUUID)(),
1365
- },
1366
- ],
1367
- i18n: {
1368
- fr: {
1497
+ type: 'fragment',
1369
1498
  children: [
1370
1499
  {
1371
1500
  type: 'text',
1372
- value: 'French text 1',
1501
+ value: 'English text',
1373
1502
  nodeId: (0, crypto_1.randomUUID)(),
1374
1503
  },
1375
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
+ },
1376
1516
  },
1377
- jp: {
1517
+ ],
1518
+ },
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
+ },
1536
+ },
1537
+ layouts: [
1538
+ {
1539
+ name: 'single-column',
1540
+ content: {
1541
+ main: [
1542
+ {
1543
+ nodeId: (0, crypto_1.randomUUID)(),
1544
+ type: 'fragment',
1378
1545
  children: [
1379
1546
  {
1380
1547
  type: 'text',
1381
- value: 'Japanese text 1',
1548
+ value: 'English text',
1382
1549
  nodeId: (0, crypto_1.randomUUID)(),
1383
1550
  },
1384
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
+ },
1385
1563
  },
1386
- },
1564
+ ],
1387
1565
  },
1388
- {
1389
- // has "fr" translation but no "jp" translation
1390
- nodeId: (0, crypto_1.randomUUID)(),
1391
- type: 'fragment',
1392
- children: [
1566
+ },
1567
+ ],
1568
+ };
1569
+ (0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
1570
+ // Should not translate since no French language config exists
1571
+ // The i18n property should be removed but content preserved
1572
+ const fragment = pageContents.layouts[0].content.main[0];
1573
+ expect(fragment.children[0].value).toBe('English text');
1574
+ expect(fragment).not.toHaveProperty('i18n');
1575
+ });
1576
+ it('should handle nested layout nodes in page contents', () => {
1577
+ const pageContents = {
1578
+ ...mockPageContents,
1579
+ layouts: [
1580
+ {
1581
+ name: 'single-column',
1582
+ content: {
1583
+ main: [
1393
1584
  {
1394
- type: 'text',
1395
- value: 'English text 2',
1396
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
+ },
1397
1618
  },
1398
1619
  ],
1399
- i18n: {
1400
- fr: {
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',
1401
1662
  children: [
1402
1663
  {
1403
1664
  type: 'text',
1404
- value: 'French text 2',
1665
+ value: 'English fragment',
1405
1666
  nodeId: (0, crypto_1.randomUUID)(),
1406
1667
  },
1407
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
+ },
1408
1680
  },
1409
- },
1410
- },
1411
- {
1412
- // has no translations
1413
- nodeId: (0, crypto_1.randomUUID)(),
1414
- type: 'fragment',
1415
- children: [
1416
1681
  {
1417
- type: 'text',
1418
- value: 'English text 3',
1419
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: [],
1420
1697
  },
1421
1698
  ],
1422
1699
  },
1423
- ],
1424
- },
1700
+ },
1701
+ ],
1425
1702
  };
1426
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, langConfig);
1427
- expect(layout.content.main).toHaveLength(3);
1428
- expect(layout.content.main[0].children[0].value).toBe('Japanese text 1');
1429
- expect(layout.content.main[1].children[0].value).toBe('English text 2');
1430
- expect(layout.content.main[2].children[0].value).toBe('English text 3');
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');
1431
1714
  });
1432
- it('should translate multiple nodes in a single layout with fallback to false', () => {
1433
- const langConfig = {
1434
- ...config,
1435
- lang: {
1436
- code: 'jp',
1437
- fallbackToDefault: false,
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
+ },
1438
1724
  },
1439
- };
1440
- const layout = {
1441
- name: 'layout-raw',
1442
- content: {
1443
- main: [
1444
- {
1445
- // has both "fr" and "jp" translations
1446
- nodeId: (0, crypto_1.randomUUID)(),
1447
- type: 'fragment',
1448
- children: [
1725
+ layouts: [
1726
+ {
1727
+ name: 'single-column',
1728
+ content: {
1729
+ main: [
1449
1730
  {
1450
- type: 'text',
1451
- value: 'English text 1',
1452
1731
  nodeId: (0, crypto_1.randomUUID)(),
1453
- },
1454
- ],
1455
- i18n: {
1456
- fr: {
1732
+ type: 'fragment',
1457
1733
  children: [
1458
1734
  {
1459
1735
  type: 'text',
1460
- value: 'French text 1',
1736
+ value: 'English text',
1461
1737
  nodeId: (0, crypto_1.randomUUID)(),
1462
1738
  },
1463
1739
  ],
1740
+ i18n: {
1741
+ // No French translation
1742
+ },
1464
1743
  },
1465
- jp: {
1466
- children: [
1467
- {
1468
- type: 'text',
1469
- value: 'Japanese text 1',
1744
+ ],
1745
+ },
1746
+ },
1747
+ ],
1748
+ };
1749
+ (0, page_contents_lib_1.translatePageContents)(pageContents, 'fr');
1750
+ // Should not be translated since fallbackToDefault is false and no translation exists
1751
+ // The node should be removed from the array since no translation is available
1752
+ expect(pageContents.layouts[0].content.main).toHaveLength(0);
1753
+ });
1754
+ it('should handle variant nodes with translatable default content', () => {
1755
+ const pageContents = {
1756
+ ...mockPageContents,
1757
+ layouts: [
1758
+ {
1759
+ name: 'single-column',
1760
+ content: {
1761
+ main: [
1762
+ {
1763
+ nodeId: (0, crypto_1.randomUUID)(),
1764
+ type: 'variation',
1765
+ default: {
1766
+ node: {
1470
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
+ },
1471
1814
  },
1472
1815
  ],
1473
1816
  },
1474
- },
1817
+ ],
1475
1818
  },
1476
- {
1477
- // has "fr" translation but no "jp" translation
1478
- nodeId: (0, crypto_1.randomUUID)(),
1479
- type: 'fragment',
1480
- children: [
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: [
1481
1839
  {
1482
- type: 'text',
1483
- value: 'English text 2',
1484
1840
  nodeId: (0, crypto_1.randomUUID)(),
1485
- },
1486
- ],
1487
- i18n: {
1488
- fr: {
1489
- children: [
1490
- {
1491
- type: 'text',
1492
- value: 'French text 2',
1841
+ type: 'variation',
1842
+ default: {
1843
+ node: {
1493
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
+ },
1494
1869
  },
1495
1870
  ],
1496
1871
  },
1497
- },
1872
+ ],
1498
1873
  },
1499
- {
1500
- // has no translations
1501
- nodeId: (0, crypto_1.randomUUID)(),
1502
- type: 'fragment',
1503
- children: [
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: [
1504
1894
  {
1505
- type: 'text',
1506
- value: 'English text 3',
1507
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
+ ],
1508
1963
  },
1509
1964
  ],
1510
1965
  },
1511
- ],
1512
- },
1966
+ },
1967
+ ],
1513
1968
  };
1514
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, langConfig);
1515
- // there will be 2nd and 3rd nodes in main array as they don't have translations for "jp" and fallback is false
1516
- expect(layout.content.main).toHaveLength(1);
1517
- expect(layout.content.main[0].children[0].value).toBe('Japanese text 1');
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');
1518
1981
  });
1519
- it('should translate content inside layout nodes', () => {
1520
- const fragmentNode = {
1521
- nodeId: (0, crypto_1.randomUUID)(),
1522
- type: 'fragment',
1523
- children: [
1982
+ it('should handle variant nodes with fallback behavior', () => {
1983
+ const pageContents = {
1984
+ ...mockPageContents,
1985
+ layouts: [
1524
1986
  {
1525
- type: 'text',
1526
- value: 'English text',
1527
- nodeId: (0, crypto_1.randomUUID)(),
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
+ },
1528
2039
  },
1529
2040
  ],
1530
- i18n: {
1531
- fr: {
1532
- children: [
1533
- {
1534
- type: 'text',
1535
- value: 'French text',
1536
- },
1537
- ],
1538
- },
1539
- },
1540
2041
  };
1541
- const layout = {
1542
- name: 'layout-raw',
1543
- content: {
1544
- main: [
1545
- {
1546
- nodeId: (0, crypto_1.randomUUID)(),
1547
- type: 'layout',
1548
- layout: {
1549
- template: '<div>{{zones.content}}</div>',
1550
- name: 'test-layout',
1551
- options: {},
1552
- },
1553
- content: {
1554
- content: [fragmentNode],
1555
- },
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,
1556
2060
  },
1557
- ],
2061
+ },
1558
2062
  },
1559
- };
1560
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1561
- // Verify the content inside the layout node is translated
1562
- const layoutNode = layout.content.main[0];
1563
- const translatedFragment = layoutNode.content.content[0];
1564
- expect(translatedFragment.children[0].value).toBe('French text');
1565
- });
1566
- it('should translate multiple content sections in layout nodes', () => {
1567
- const fragmentNode = {
1568
- nodeId: (0, crypto_1.randomUUID)(),
1569
- type: 'fragment',
1570
- children: [
2063
+ layouts: [
1571
2064
  {
1572
- type: 'text',
1573
- value: 'English Title',
1574
- nodeId: (0, crypto_1.randomUUID)(),
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
+ },
1575
2109
  },
1576
2110
  ],
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
2111
  };
1599
- const layout = {
1600
- name: 'layout-raw',
1601
- content: {
1602
- main: [
1603
- {
1604
- nodeId: (0, crypto_1.randomUUID)(),
1605
- type: 'layout',
1606
- layout: {
1607
- template: '<div><h1>{{zones.title}}</h1><div>{{zones.content}}</div></div>',
1608
- name: 'test-layout',
1609
- options: {},
1610
- },
1611
- content: {
1612
- title: [fragmentNode],
1613
- content: [componentNode],
1614
- },
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
+ ],
1615
2175
  },
1616
- ],
1617
- },
2176
+ },
2177
+ ],
1618
2178
  };
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');
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');
1626
2187
  });
1627
- it('should handle nested layout nodes with translations', () => {
1628
- const fragmentNode = {
1629
- nodeId: (0, crypto_1.randomUUID)(),
1630
- type: 'fragment',
1631
- children: [
2188
+ it('should handle deeply nested layout nodes with translatable content', () => {
2189
+ const pageContents = {
2190
+ ...mockPageContents,
2191
+ layouts: [
1632
2192
  {
1633
- type: 'text',
1634
- value: 'English text',
1635
- nodeId: (0, crypto_1.randomUUID)(),
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
+ },
1636
2246
  },
1637
2247
  ],
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
2248
  };
1661
- const layout = {
1662
- name: 'layout-raw',
1663
- content: {
1664
- main: [
1665
- {
1666
- nodeId: (0, crypto_1.randomUUID)(),
1667
- type: 'layout',
1668
- layout: {
1669
- template: '<div>{{zones.outer}}</div>',
1670
- name: 'outer-layout',
1671
- options: {},
1672
- },
1673
- content: {
1674
- outer: [innerLayoutNode],
1675
- },
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
+ ],
1676
2356
  },
1677
- ],
1678
- },
2357
+ },
2358
+ ],
1679
2359
  };
1680
- (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1681
- // Verify content in nested layout node is translated
1682
- const outerLayoutNode = layout.content.main[0];
1683
- const translatedInnerLayout = outerLayoutNode.content.outer[0];
1684
- const translatedFragment = translatedInnerLayout.content.inner[0];
1685
- expect(translatedFragment.children[0].value).toBe('French text');
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');
1686
2379
  });
1687
2380
  });
1688
2381
  //# sourceMappingURL=page-contents-lib.spec.js.map