@squiz/dx-page-contents-lib 1.77.0 → 1.78.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -688,7 +688,7 @@ describe('renderLayout', () => {
688
688
  type: 'layout',
689
689
  nodeId: (0, crypto_1.randomUUID)(),
690
690
  layout: {
691
- template: '<div class="container custom-class">{{top}}</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
691
+ template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
692
692
  name: 'mock-dev-layout-with-classes',
693
693
  options: {},
694
694
  },
@@ -718,7 +718,7 @@ describe('renderLayout', () => {
718
718
  type: 'layout',
719
719
  nodeId: (0, crypto_1.randomUUID)(),
720
720
  layout: {
721
- template: '<div class="container custom-class">{{top</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
721
+ template: '<div class="container custom-class">{{zones.top</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
722
722
  name: 'mock-dev-layout-with-classes',
723
723
  options: {},
724
724
  },
@@ -748,7 +748,7 @@ describe('renderLayout', () => {
748
748
  type: 'layout',
749
749
  nodeId: (0, crypto_1.randomUUID)(),
750
750
  layout: {
751
- template: '<div class="dev-layout">{{content}}</div>',
751
+ template: '<div class="dev-layout">{{zones.content}}</div>',
752
752
  name: 'dev-layout-in-single-column',
753
753
  options: {},
754
754
  },
@@ -766,7 +766,7 @@ describe('renderLayout', () => {
766
766
  type: 'layout',
767
767
  nodeId: (0, crypto_1.randomUUID)(),
768
768
  layout: {
769
- template: '<section class="left-dev-layout">{{content}}</section>',
769
+ template: '<section class="left-dev-layout">{{zones.content}}</section>',
770
770
  name: 'dev-layout-left',
771
771
  options: {},
772
772
  },
@@ -778,7 +778,7 @@ describe('renderLayout', () => {
778
778
  type: 'layout',
779
779
  nodeId: (0, crypto_1.randomUUID)(),
780
780
  layout: {
781
- template: '<aside class="right-dev-layout">{{content}}</aside>',
781
+ template: '<aside class="right-dev-layout">{{zones.content}}</aside>',
782
782
  name: 'dev-layout-right',
783
783
  options: {},
784
784
  },
@@ -812,7 +812,7 @@ describe('renderLayout', () => {
812
812
  type: 'layout',
813
813
  nodeId: (0, crypto_1.randomUUID)(),
814
814
  layout: {
815
- template: '<article class="article-layout"><h1>{{title}}</h1><div class="content">{{body}}</div></article>',
815
+ template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
816
816
  name: 'article-layout',
817
817
  options: {},
818
818
  },
@@ -836,7 +836,7 @@ describe('renderLayout', () => {
836
836
  type: 'layout',
837
837
  nodeId: (0, crypto_1.randomUUID)(),
838
838
  layout: {
839
- template: '<div class="inner-layout">{{innerContent}}</div>',
839
+ template: '<div class="inner-layout">{{zones.innerContent}}</div>',
840
840
  name: 'inner-dev-layout',
841
841
  options: {},
842
842
  },
@@ -848,7 +848,7 @@ describe('renderLayout', () => {
848
848
  type: 'layout',
849
849
  nodeId: (0, crypto_1.randomUUID)(),
850
850
  layout: {
851
- template: '<div class="outer-layout">{{outerContent}}</div>',
851
+ template: '<div class="outer-layout">{{zones.outerContent}}</div>',
852
852
  name: 'outer-dev-layout',
853
853
  options: {},
854
854
  },
@@ -872,7 +872,7 @@ describe('renderLayout', () => {
872
872
  nodeId: (0, crypto_1.randomUUID)(),
873
873
  type: 'layout',
874
874
  layout: {
875
- template: '<section class="level-3">{{content}}</section>',
875
+ template: '<section class="level-3">{{zones.content}}</section>',
876
876
  name: 'level-3-layout',
877
877
  options: {},
878
878
  },
@@ -884,7 +884,7 @@ describe('renderLayout', () => {
884
884
  nodeId: (0, crypto_1.randomUUID)(),
885
885
  type: 'layout',
886
886
  layout: {
887
- template: '<article class="level-2">{{nestedContent}}</article>',
887
+ template: '<article class="level-2">{{zones.nestedContent}}</article>',
888
888
  name: 'level-2-layout',
889
889
  options: {},
890
890
  },
@@ -896,7 +896,7 @@ describe('renderLayout', () => {
896
896
  nodeId: (0, crypto_1.randomUUID)(),
897
897
  type: 'layout',
898
898
  layout: {
899
- template: '<div class="level-1">{{rootContent}}</div>',
899
+ template: '<div class="level-1">{{zones.rootContent}}</div>',
900
900
  name: 'level-1-layout',
901
901
  options: {},
902
902
  },
@@ -925,7 +925,7 @@ describe('renderLayout', () => {
925
925
  type: 'layout',
926
926
  nodeId: (0, crypto_1.randomUUID)(),
927
927
  layout: {
928
- template: '<div class="inner-mixed"><h2>{{heading}}</h2><div>{{content}}</div></div>',
928
+ template: '<div class="inner-mixed"><h2>{{zones.heading}}</h2><div>{{zones.content}}</div></div>',
929
929
  name: 'inner-mixed-layout',
930
930
  options: {},
931
931
  },
@@ -938,7 +938,7 @@ describe('renderLayout', () => {
938
938
  type: 'layout',
939
939
  nodeId: (0, crypto_1.randomUUID)(),
940
940
  layout: {
941
- template: '<div class="outer-mixed"><div class="intro">{{intro}}</div><div class="main">{{main}}</div></div>',
941
+ template: '<div class="outer-mixed"><div class="intro">{{zones.intro}}</div><div class="main">{{zones.main}}</div></div>',
942
942
  name: 'outer-mixed-layout',
943
943
  options: {},
944
944
  },
@@ -963,13 +963,266 @@ describe('renderLayout', () => {
963
963
  </div>
964
964
  </div>`));
965
965
  });
966
+ it('should add HTML comments for developer defined layouts in preview mode', async () => {
967
+ const developerLayoutNode = {
968
+ type: 'layout',
969
+ nodeId: (0, crypto_1.randomUUID)(),
970
+ layout: {
971
+ template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
972
+ name: 'article-layout',
973
+ options: {},
974
+ },
975
+ content: {
976
+ title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
977
+ body: [{ type: 'text', value: 'Article content goes here.', nodeId: (0, crypto_1.randomUUID)() }],
978
+ },
979
+ };
980
+ const contentPage = {
981
+ name: 'layout-raw',
982
+ content: {
983
+ main: [developerLayoutNode],
984
+ },
985
+ };
986
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
987
+ 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} -->`));
988
+ });
989
+ it('should use the correct nodeId in the HTML comments for nested layouts', async () => {
990
+ const innerLayoutNode = {
991
+ type: 'layout',
992
+ nodeId: (0, crypto_1.randomUUID)(),
993
+ layout: {
994
+ template: '<div class="inner-layout">{{zones.content}}</div>',
995
+ name: 'inner-layout',
996
+ options: {},
997
+ },
998
+ content: {
999
+ content: [{ type: 'text', value: 'Inner content', nodeId: (0, crypto_1.randomUUID)() }],
1000
+ },
1001
+ };
1002
+ const developerLayoutNode = {
1003
+ type: 'layout',
1004
+ nodeId: (0, crypto_1.randomUUID)(),
1005
+ layout: {
1006
+ template: '<div class="outer-layout">{{zones.content}}</div>',
1007
+ name: 'outer-layout',
1008
+ options: {},
1009
+ },
1010
+ content: {
1011
+ content: [innerLayoutNode],
1012
+ },
1013
+ };
1014
+ const contentPage = {
1015
+ name: 'layout-raw',
1016
+ content: {
1017
+ main: [developerLayoutNode],
1018
+ },
1019
+ };
1020
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
1021
+ 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} -->`;
1022
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<!-- start:layout:outer-layout:${developerLayoutNode.nodeId} --><div class="outer-layout"><!-- start:zone:content:${developerLayoutNode.nodeId} -->${expectedInnerHtml}<!-- end:zone:content:${developerLayoutNode.nodeId} --></div><!-- end:layout:outer-layout:${developerLayoutNode.nodeId} -->`));
1023
+ });
1024
+ it('should allow fragment nodes in layout content', async () => {
1025
+ const developerLayoutNode = {
1026
+ type: 'layout',
1027
+ nodeId: (0, crypto_1.randomUUID)(),
1028
+ layout: {
1029
+ template: '<div class="outer-layout">{{zones.content}}</div>',
1030
+ name: 'outer-layout',
1031
+ options: {},
1032
+ },
1033
+ content: {
1034
+ content: [
1035
+ {
1036
+ type: 'fragment',
1037
+ children: [{ type: 'text', value: 'Fragment content', nodeId: (0, crypto_1.randomUUID)() }],
1038
+ nodeId: (0, crypto_1.randomUUID)(),
1039
+ },
1040
+ ],
1041
+ },
1042
+ };
1043
+ const contentPage = {
1044
+ name: 'layout-raw',
1045
+ content: {
1046
+ main: [developerLayoutNode],
1047
+ },
1048
+ };
1049
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, config);
1050
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-layout">Fragment content</div>`));
1051
+ });
1052
+ describe('with language translation', () => {
1053
+ const langConfig = {
1054
+ ...config,
1055
+ lang: {
1056
+ code: 'fr',
1057
+ fallbackToDefault: true,
1058
+ },
1059
+ };
1060
+ it('should render translated fragment nodes', async () => {
1061
+ const layout = new mocks_1.PageSingleColumLayoutBuilder()
1062
+ .addNode({
1063
+ nodeId: (0, crypto_1.randomUUID)(),
1064
+ type: 'fragment',
1065
+ children: [
1066
+ {
1067
+ type: 'text',
1068
+ value: 'English text',
1069
+ nodeId: (0, crypto_1.randomUUID)(),
1070
+ },
1071
+ ],
1072
+ i18n: {
1073
+ fr: {
1074
+ children: [
1075
+ {
1076
+ type: 'text',
1077
+ value: 'French text',
1078
+ },
1079
+ ],
1080
+ },
1081
+ },
1082
+ })
1083
+ .build();
1084
+ const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1085
+ expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">French text</div>'));
1086
+ });
1087
+ it('should render translated component nodes', async () => {
1088
+ const layout = new mocks_1.PageSingleColumLayoutBuilder()
1089
+ .addNode({
1090
+ nodeId: (0, crypto_1.randomUUID)(),
1091
+ type: 'component',
1092
+ componentId: 'test/component/1.0.0',
1093
+ componentSet: 'test-set',
1094
+ componentType: 'server',
1095
+ contentItem: { id: 'en-content' },
1096
+ i18n: {
1097
+ fr: { id: 'fr-content' },
1098
+ },
1099
+ })
1100
+ .build();
1101
+ const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1102
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container"><esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/></div>`));
1103
+ });
1104
+ it('should render mixed translated and untranslated nodes', async () => {
1105
+ const layout = new mocks_1.PageSingleColumLayoutBuilder()
1106
+ .addNode({
1107
+ // Translated fragment
1108
+ nodeId: (0, crypto_1.randomUUID)(),
1109
+ type: 'fragment',
1110
+ children: [
1111
+ {
1112
+ type: 'text',
1113
+ value: 'English text',
1114
+ nodeId: (0, crypto_1.randomUUID)(),
1115
+ },
1116
+ ],
1117
+ i18n: {
1118
+ fr: {
1119
+ children: [
1120
+ {
1121
+ type: 'text',
1122
+ value: 'French text',
1123
+ },
1124
+ ],
1125
+ },
1126
+ },
1127
+ })
1128
+ .addNode({
1129
+ // Untranslated component
1130
+ nodeId: (0, crypto_1.randomUUID)(),
1131
+ type: 'component',
1132
+ componentId: 'test/component/1.0.0',
1133
+ componentSet: 'test-set',
1134
+ componentType: 'server',
1135
+ contentItem: { id: 'en-content' },
1136
+ })
1137
+ .build();
1138
+ const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1139
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/></div>`));
1140
+ });
1141
+ it('should render developer layout with translated content', async () => {
1142
+ const developerLayoutNode = {
1143
+ type: 'layout',
1144
+ nodeId: (0, crypto_1.randomUUID)(),
1145
+ layout: {
1146
+ template: '<div class="top">{{zones.top}}</div><div class="side">{{zones.side}}</div>',
1147
+ name: 'article-layout',
1148
+ options: {},
1149
+ },
1150
+ content: {
1151
+ top: [
1152
+ {
1153
+ type: 'component',
1154
+ nodeId: (0, crypto_1.randomUUID)(),
1155
+ componentId: 'test/component/1.0.0',
1156
+ componentSet: 'test-set',
1157
+ componentType: 'server',
1158
+ contentItem: { id: 'en-top' },
1159
+ i18n: {
1160
+ fr: { id: 'fr-top' },
1161
+ },
1162
+ },
1163
+ ],
1164
+ side: [
1165
+ {
1166
+ type: 'component',
1167
+ nodeId: (0, crypto_1.randomUUID)(),
1168
+ componentId: 'test/component/1.0.0',
1169
+ componentSet: 'test-set',
1170
+ componentType: 'server',
1171
+ contentItem: { id: 'en-side' },
1172
+ i18n: {
1173
+ fr: { id: 'fr-side' },
1174
+ },
1175
+ },
1176
+ ],
1177
+ },
1178
+ };
1179
+ const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(developerLayoutNode).build();
1180
+ const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1181
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
1182
+ <div class="top">
1183
+ <esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-top"/>
1184
+ </div>
1185
+ <div class="side">
1186
+ <esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-side"/>
1187
+ </div>
1188
+ </div>`));
1189
+ });
1190
+ it('should render layout with no translations when language config is missing', async () => {
1191
+ const layout = new mocks_1.PageSingleColumLayoutBuilder()
1192
+ .addNode({
1193
+ nodeId: (0, crypto_1.randomUUID)(),
1194
+ type: 'fragment',
1195
+ children: [
1196
+ {
1197
+ type: 'text',
1198
+ value: 'English text',
1199
+ nodeId: (0, crypto_1.randomUUID)(),
1200
+ },
1201
+ ],
1202
+ i18n: {
1203
+ fr: {
1204
+ children: [
1205
+ {
1206
+ type: 'text',
1207
+ value: 'French text',
1208
+ nodeId: (0, crypto_1.randomUUID)(),
1209
+ },
1210
+ ],
1211
+ },
1212
+ },
1213
+ })
1214
+ .build();
1215
+ const result = await (0, page_contents_lib_1.renderLayout)(layout, config); // Using config without lang
1216
+ expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">English text</div>'));
1217
+ });
1218
+ });
966
1219
  });
967
1220
  describe('Helper functions', () => {
968
1221
  it('isDeveloperDefinedLayoutNode returns true for valid developer layouts', () => {
969
1222
  const layoutNode = {
970
1223
  type: 'layout',
971
1224
  layout: {
972
- template: '<div class="container custom-class">{{top}}</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
1225
+ template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
973
1226
  name: 'mock-dev-layout-with-classes',
974
1227
  options: {},
975
1228
  },
@@ -1004,4 +1257,541 @@ describe('Helper functions', () => {
1004
1257
  expect((0, page_contents_lib_1.isCustomLayout)(layout)).toEqual(false);
1005
1258
  });
1006
1259
  });
1260
+ describe('translateLanguageNodes', () => {
1261
+ const config = {
1262
+ componentRootUrl: 'https://mock.url/__dxp/service/components-render',
1263
+ lang: {
1264
+ code: 'fr',
1265
+ fallbackToDefault: true,
1266
+ },
1267
+ };
1268
+ it('should return early if no language config is provided', () => {
1269
+ const layout = {
1270
+ name: 'layout-raw',
1271
+ content: {
1272
+ main: [
1273
+ {
1274
+ nodeId: (0, crypto_1.randomUUID)(),
1275
+ type: 'fragment',
1276
+ children: [
1277
+ {
1278
+ type: 'text',
1279
+ value: 'English text',
1280
+ nodeId: '123',
1281
+ },
1282
+ ],
1283
+ i18n: {
1284
+ fr: {
1285
+ children: [
1286
+ {
1287
+ type: 'text',
1288
+ value: 'French text',
1289
+ },
1290
+ ],
1291
+ },
1292
+ },
1293
+ },
1294
+ ],
1295
+ },
1296
+ };
1297
+ const configWithoutLang = { ...config, lang: undefined };
1298
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, configWithoutLang);
1299
+ expect(layout.content.main[0].children[0].value).toBe('English text');
1300
+ });
1301
+ it('should translate fragment nodes when translation is available', () => {
1302
+ const layout = {
1303
+ name: 'layout-raw',
1304
+ content: {
1305
+ main: [
1306
+ {
1307
+ nodeId: (0, crypto_1.randomUUID)(),
1308
+ type: 'fragment',
1309
+ children: [
1310
+ {
1311
+ type: 'text',
1312
+ value: 'English text',
1313
+ nodeId: (0, crypto_1.randomUUID)(),
1314
+ },
1315
+ ],
1316
+ i18n: {
1317
+ fr: {
1318
+ children: [
1319
+ {
1320
+ type: 'text',
1321
+ value: 'French text',
1322
+ nodeId: (0, crypto_1.randomUUID)(),
1323
+ },
1324
+ ],
1325
+ },
1326
+ },
1327
+ },
1328
+ ],
1329
+ },
1330
+ };
1331
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1332
+ expect(layout.content.main[0].children[0].value).toBe('French text');
1333
+ });
1334
+ it('should translate component nodes when translation is available', () => {
1335
+ const layout = {
1336
+ name: 'layout-raw',
1337
+ content: {
1338
+ main: [
1339
+ {
1340
+ nodeId: (0, crypto_1.randomUUID)(),
1341
+ type: 'component',
1342
+ componentId: 'test/component/1.0.0',
1343
+ componentSet: 'test-set',
1344
+ componentType: 'edge',
1345
+ contentItem: { id: 'en-content' },
1346
+ i18n: {
1347
+ fr: { id: 'fr-content' },
1348
+ },
1349
+ },
1350
+ ],
1351
+ },
1352
+ };
1353
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1354
+ expect(layout.content.main[0].contentItem.id).toBe('fr-content');
1355
+ });
1356
+ it('should fallback to default content when translation is not available and fallback is enabled', () => {
1357
+ const layout = {
1358
+ name: 'layout-raw',
1359
+ content: {
1360
+ main: [
1361
+ {
1362
+ nodeId: (0, crypto_1.randomUUID)(),
1363
+ type: 'fragment',
1364
+ children: [
1365
+ {
1366
+ type: 'text',
1367
+ value: 'English text',
1368
+ nodeId: (0, crypto_1.randomUUID)(),
1369
+ },
1370
+ ],
1371
+ i18n: {
1372
+ es: {
1373
+ children: [
1374
+ {
1375
+ type: 'text',
1376
+ value: 'Spanish text',
1377
+ nodeId: (0, crypto_1.randomUUID)(),
1378
+ },
1379
+ ],
1380
+ },
1381
+ },
1382
+ },
1383
+ ],
1384
+ },
1385
+ };
1386
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1387
+ expect(layout.content.main[0].children[0].value).toBe('English text');
1388
+ });
1389
+ it('should skip translation for non-translatable node types', () => {
1390
+ const layout = {
1391
+ name: 'layout-raw',
1392
+ content: {
1393
+ main: [
1394
+ {
1395
+ nodeId: (0, crypto_1.randomUUID)(),
1396
+ type: 'variation',
1397
+ default: {
1398
+ node: {
1399
+ nodeId: (0, crypto_1.randomUUID)(),
1400
+ type: 'text',
1401
+ value: 'Default text',
1402
+ },
1403
+ },
1404
+ variants: [],
1405
+ },
1406
+ ],
1407
+ },
1408
+ };
1409
+ const originalLayout = { ...layout };
1410
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1411
+ expect(layout).toEqual(originalLayout);
1412
+ });
1413
+ it('should not include node when translation is missing and fallback is disabled', () => {
1414
+ const configWithoutFallback = {
1415
+ ...config,
1416
+ lang: {
1417
+ code: 'fr',
1418
+ fallbackToDefault: false,
1419
+ },
1420
+ };
1421
+ const layout = {
1422
+ name: 'layout-raw',
1423
+ content: {
1424
+ main: [
1425
+ {
1426
+ nodeId: (0, crypto_1.randomUUID)(),
1427
+ type: 'fragment',
1428
+ children: [
1429
+ {
1430
+ type: 'text',
1431
+ value: 'English text',
1432
+ nodeId: (0, crypto_1.randomUUID)(),
1433
+ },
1434
+ ],
1435
+ i18n: {
1436
+ es: {
1437
+ children: [
1438
+ {
1439
+ type: 'text',
1440
+ value: 'Spanish text',
1441
+ nodeId: (0, crypto_1.randomUUID)(),
1442
+ },
1443
+ ],
1444
+ },
1445
+ },
1446
+ },
1447
+ ],
1448
+ },
1449
+ };
1450
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, configWithoutFallback);
1451
+ expect(layout.content.main).toHaveLength(0);
1452
+ });
1453
+ it('should translate multiple nodes in a single layout with fallback to true', () => {
1454
+ const langConfig = {
1455
+ ...config,
1456
+ lang: {
1457
+ code: 'jp',
1458
+ fallbackToDefault: true,
1459
+ },
1460
+ };
1461
+ const layout = {
1462
+ name: 'layout-raw',
1463
+ content: {
1464
+ main: [
1465
+ {
1466
+ // has both "fr" and "jp" translations
1467
+ nodeId: (0, crypto_1.randomUUID)(),
1468
+ type: 'fragment',
1469
+ children: [
1470
+ {
1471
+ type: 'text',
1472
+ value: 'English text 1',
1473
+ nodeId: (0, crypto_1.randomUUID)(),
1474
+ },
1475
+ ],
1476
+ i18n: {
1477
+ fr: {
1478
+ children: [
1479
+ {
1480
+ type: 'text',
1481
+ value: 'French text 1',
1482
+ nodeId: (0, crypto_1.randomUUID)(),
1483
+ },
1484
+ ],
1485
+ },
1486
+ jp: {
1487
+ children: [
1488
+ {
1489
+ type: 'text',
1490
+ value: 'Japanese text 1',
1491
+ nodeId: (0, crypto_1.randomUUID)(),
1492
+ },
1493
+ ],
1494
+ },
1495
+ },
1496
+ },
1497
+ {
1498
+ // has "fr" translation but no "jp" translation
1499
+ nodeId: (0, crypto_1.randomUUID)(),
1500
+ type: 'fragment',
1501
+ children: [
1502
+ {
1503
+ type: 'text',
1504
+ value: 'English text 2',
1505
+ nodeId: (0, crypto_1.randomUUID)(),
1506
+ },
1507
+ ],
1508
+ i18n: {
1509
+ fr: {
1510
+ children: [
1511
+ {
1512
+ type: 'text',
1513
+ value: 'French text 2',
1514
+ nodeId: (0, crypto_1.randomUUID)(),
1515
+ },
1516
+ ],
1517
+ },
1518
+ },
1519
+ },
1520
+ {
1521
+ // has no translations
1522
+ nodeId: (0, crypto_1.randomUUID)(),
1523
+ type: 'fragment',
1524
+ children: [
1525
+ {
1526
+ type: 'text',
1527
+ value: 'English text 3',
1528
+ nodeId: (0, crypto_1.randomUUID)(),
1529
+ },
1530
+ ],
1531
+ },
1532
+ ],
1533
+ },
1534
+ };
1535
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, langConfig);
1536
+ expect(layout.content.main).toHaveLength(3);
1537
+ expect(layout.content.main[0].children[0].value).toBe('Japanese text 1');
1538
+ expect(layout.content.main[1].children[0].value).toBe('English text 2');
1539
+ expect(layout.content.main[2].children[0].value).toBe('English text 3');
1540
+ });
1541
+ it('should translate multiple nodes in a single layout with fallback to false', () => {
1542
+ const langConfig = {
1543
+ ...config,
1544
+ lang: {
1545
+ code: 'jp',
1546
+ fallbackToDefault: false,
1547
+ },
1548
+ };
1549
+ const layout = {
1550
+ name: 'layout-raw',
1551
+ content: {
1552
+ main: [
1553
+ {
1554
+ // has both "fr" and "jp" translations
1555
+ nodeId: (0, crypto_1.randomUUID)(),
1556
+ type: 'fragment',
1557
+ children: [
1558
+ {
1559
+ type: 'text',
1560
+ value: 'English text 1',
1561
+ nodeId: (0, crypto_1.randomUUID)(),
1562
+ },
1563
+ ],
1564
+ i18n: {
1565
+ fr: {
1566
+ children: [
1567
+ {
1568
+ type: 'text',
1569
+ value: 'French text 1',
1570
+ nodeId: (0, crypto_1.randomUUID)(),
1571
+ },
1572
+ ],
1573
+ },
1574
+ jp: {
1575
+ children: [
1576
+ {
1577
+ type: 'text',
1578
+ value: 'Japanese text 1',
1579
+ nodeId: (0, crypto_1.randomUUID)(),
1580
+ },
1581
+ ],
1582
+ },
1583
+ },
1584
+ },
1585
+ {
1586
+ // has "fr" translation but no "jp" translation
1587
+ nodeId: (0, crypto_1.randomUUID)(),
1588
+ type: 'fragment',
1589
+ children: [
1590
+ {
1591
+ type: 'text',
1592
+ value: 'English text 2',
1593
+ nodeId: (0, crypto_1.randomUUID)(),
1594
+ },
1595
+ ],
1596
+ i18n: {
1597
+ fr: {
1598
+ children: [
1599
+ {
1600
+ type: 'text',
1601
+ value: 'French text 2',
1602
+ nodeId: (0, crypto_1.randomUUID)(),
1603
+ },
1604
+ ],
1605
+ },
1606
+ },
1607
+ },
1608
+ {
1609
+ // has no translations
1610
+ nodeId: (0, crypto_1.randomUUID)(),
1611
+ type: 'fragment',
1612
+ children: [
1613
+ {
1614
+ type: 'text',
1615
+ value: 'English text 3',
1616
+ nodeId: (0, crypto_1.randomUUID)(),
1617
+ },
1618
+ ],
1619
+ },
1620
+ ],
1621
+ },
1622
+ };
1623
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, langConfig);
1624
+ // there will be 2nd and 3rd nodes in main array as they don't have translations for "jp" and fallback is false
1625
+ expect(layout.content.main).toHaveLength(1);
1626
+ expect(layout.content.main[0].children[0].value).toBe('Japanese text 1');
1627
+ });
1628
+ it('should translate content inside layout nodes', () => {
1629
+ const fragmentNode = {
1630
+ nodeId: (0, crypto_1.randomUUID)(),
1631
+ type: 'fragment',
1632
+ children: [
1633
+ {
1634
+ type: 'text',
1635
+ value: 'English text',
1636
+ nodeId: (0, crypto_1.randomUUID)(),
1637
+ },
1638
+ ],
1639
+ i18n: {
1640
+ fr: {
1641
+ children: [
1642
+ {
1643
+ type: 'text',
1644
+ value: 'French text',
1645
+ },
1646
+ ],
1647
+ },
1648
+ },
1649
+ };
1650
+ const layout = {
1651
+ name: 'layout-raw',
1652
+ content: {
1653
+ main: [
1654
+ {
1655
+ nodeId: (0, crypto_1.randomUUID)(),
1656
+ type: 'layout',
1657
+ layout: {
1658
+ template: '<div>{{zones.content}}</div>',
1659
+ name: 'test-layout',
1660
+ options: {},
1661
+ },
1662
+ content: {
1663
+ content: [fragmentNode],
1664
+ },
1665
+ },
1666
+ ],
1667
+ },
1668
+ };
1669
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1670
+ // Verify the content inside the layout node is translated
1671
+ const layoutNode = layout.content.main[0];
1672
+ const translatedFragment = layoutNode.content.content[0];
1673
+ expect(translatedFragment.children[0].value).toBe('French text');
1674
+ });
1675
+ it('should translate multiple content sections in layout nodes', () => {
1676
+ const fragmentNode = {
1677
+ nodeId: (0, crypto_1.randomUUID)(),
1678
+ type: 'fragment',
1679
+ children: [
1680
+ {
1681
+ type: 'text',
1682
+ value: 'English Title',
1683
+ nodeId: (0, crypto_1.randomUUID)(),
1684
+ },
1685
+ ],
1686
+ i18n: {
1687
+ fr: {
1688
+ children: [
1689
+ {
1690
+ type: 'text',
1691
+ value: 'French Title',
1692
+ },
1693
+ ],
1694
+ },
1695
+ },
1696
+ };
1697
+ const componentNode = {
1698
+ nodeId: (0, crypto_1.randomUUID)(),
1699
+ type: 'component',
1700
+ componentId: 'test/component/1.0.0',
1701
+ componentSet: 'test-set',
1702
+ componentType: 'server',
1703
+ contentItem: { id: 'en-content' },
1704
+ i18n: {
1705
+ fr: { id: 'fr-content' },
1706
+ },
1707
+ };
1708
+ const layout = {
1709
+ name: 'layout-raw',
1710
+ content: {
1711
+ main: [
1712
+ {
1713
+ nodeId: (0, crypto_1.randomUUID)(),
1714
+ type: 'layout',
1715
+ layout: {
1716
+ template: '<div><h1>{{zones.title}}</h1><div>{{zones.content}}</div></div>',
1717
+ name: 'test-layout',
1718
+ options: {},
1719
+ },
1720
+ content: {
1721
+ title: [fragmentNode],
1722
+ content: [componentNode],
1723
+ },
1724
+ },
1725
+ ],
1726
+ },
1727
+ };
1728
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1729
+ // Verify both content sections inside the layout node are translated
1730
+ const layoutNode = layout.content.main[0];
1731
+ const translatedFragment = layoutNode.content.title[0];
1732
+ const translatedComponent = layoutNode.content.content[0];
1733
+ expect(translatedFragment.children[0].value).toBe('French Title');
1734
+ expect(translatedComponent.contentItem.id).toBe('fr-content');
1735
+ });
1736
+ it('should handle nested layout nodes with translations', () => {
1737
+ const fragmentNode = {
1738
+ nodeId: (0, crypto_1.randomUUID)(),
1739
+ type: 'fragment',
1740
+ children: [
1741
+ {
1742
+ type: 'text',
1743
+ value: 'English text',
1744
+ nodeId: (0, crypto_1.randomUUID)(),
1745
+ },
1746
+ ],
1747
+ i18n: {
1748
+ fr: {
1749
+ children: [
1750
+ {
1751
+ type: 'text',
1752
+ value: 'French text',
1753
+ },
1754
+ ],
1755
+ },
1756
+ },
1757
+ };
1758
+ const innerLayoutNode = {
1759
+ nodeId: (0, crypto_1.randomUUID)(),
1760
+ type: 'layout',
1761
+ layout: {
1762
+ template: '<div>{{zones.inner}}</div>',
1763
+ name: 'inner-layout',
1764
+ options: {},
1765
+ },
1766
+ content: {
1767
+ inner: [fragmentNode],
1768
+ },
1769
+ };
1770
+ const layout = {
1771
+ name: 'layout-raw',
1772
+ content: {
1773
+ main: [
1774
+ {
1775
+ nodeId: (0, crypto_1.randomUUID)(),
1776
+ type: 'layout',
1777
+ layout: {
1778
+ template: '<div>{{zones.outer}}</div>',
1779
+ name: 'outer-layout',
1780
+ options: {},
1781
+ },
1782
+ content: {
1783
+ outer: [innerLayoutNode],
1784
+ },
1785
+ },
1786
+ ],
1787
+ },
1788
+ };
1789
+ (0, page_contents_lib_1.translateLanguageNodes)(layout.content, config);
1790
+ // Verify content in nested layout node is translated
1791
+ const outerLayoutNode = layout.content.main[0];
1792
+ const translatedInnerLayout = outerLayoutNode.content.outer[0];
1793
+ const translatedFragment = translatedInnerLayout.content.inner[0];
1794
+ expect(translatedFragment.children[0].value).toBe('French text');
1795
+ });
1796
+ });
1007
1797
  //# sourceMappingURL=page-contents-lib.spec.js.map