1- import { addNode , createSite , deleteSite , publishAndWaitJobEnding } from "@jahia/cypress" ;
1+ import {
2+ addNode ,
3+ createSite ,
4+ deleteSite ,
5+ enableModule ,
6+ publishAndWaitJobEnding ,
7+ } from "@jahia/cypress" ;
28import { addSimplePage } from "../../utils/helpers" ;
39
410const testData = {
@@ -23,30 +29,24 @@ const testData = {
2329} ;
2430
2531describe ( "Test i18n" , ( ) => {
26- before ( "Create test site/contents" , ( ) => {
27- createSite ( "javascriptI18NTestSite" , {
32+ const createSiteWithContent = ( siteKey : string ) => {
33+ deleteSite ( siteKey ) ; // cleanup from previous test runs
34+ createSite ( siteKey , {
2835 languages : "en,fr_LU,fr,de" ,
2936 templateSet : "javascript-modules-engine-test-module" ,
3037 locale : "en" ,
3138 serverName : "localhost" ,
3239 } ) ;
3340
34- addSimplePage (
35- "/sites/javascriptI18NTestSite/home" ,
36- "testPageI18N" ,
37- "Test i18n en" ,
38- "en" ,
39- "simple" ,
40- [
41- {
42- name : "pagecontent" ,
43- primaryNodeType : "jnt:contentList" ,
44- } ,
45- ] ,
46- ) . then ( ( ) => {
41+ addSimplePage ( `/sites/${ siteKey } /home` , "testPageI18N" , "Test i18n en" , "en" , "simple" , [
42+ {
43+ name : "pagecontent" ,
44+ primaryNodeType : "jnt:contentList" ,
45+ } ,
46+ ] ) . then ( ( ) => {
4747 cy . apollo ( {
4848 variables : {
49- pathOrId : " /sites/javascriptI18NTestSite /home/testPageI18N" ,
49+ pathOrId : ` /sites/${ siteKey } /home/testPageI18N` ,
5050 properties : [
5151 { name : "jcr:title" , value : "Test i18n fr_LU" , language : "fr_LU" } ,
5252 { name : "jcr:title" , value : "Test i18n fr" , language : "fr" } ,
@@ -57,57 +57,45 @@ describe("Test i18n", () => {
5757 } ) ;
5858
5959 addNode ( {
60- parentPathOrId : " /sites/javascriptI18NTestSite /home/testPageI18N/pagecontent" ,
60+ parentPathOrId : ` /sites/${ siteKey } /home/testPageI18N/pagecontent` ,
6161 name : "test" ,
6262 primaryNodeType : "javascriptExample:testI18n" ,
6363 } ) ;
6464 } ) ;
6565
66- publishAndWaitJobEnding ( "/sites/javascriptI18NTestSite/home/testPageI18N" , [
67- "en" ,
68- "fr_LU" ,
69- "fr" ,
70- "de" ,
71- ] ) ;
72- } ) ;
66+ publishAndWaitJobEnding ( `/sites/${ siteKey } /home/testPageI18N` , [ "en" , "fr_LU" , "fr" , "de" ] ) ;
67+ } ;
7368
7469 it ( "Test I18n values in various workspace/locales and various type of usage SSR/hydrate/rendered client side" , ( ) => {
70+ const siteKey = "javascriptI18NTestSite" ;
71+ createSiteWithContent ( siteKey ) ;
72+
7573 cy . login ( ) ;
7674 [ "live" , "default" ] . forEach ( ( workspace ) => {
7775 [ "en" , "fr_LU" , "fr" , "de" ] . forEach ( ( locale ) => {
78- cy . visit (
79- `/cms/render/${ workspace } /${ locale } /sites/javascriptI18NTestSite/home/testPageI18N.html` ,
80- ) ;
81- testI18n (
82- workspace ,
83- locale ,
84- 'div[data-testid="i18n-server-side"]' ,
85- "We are server side !" ,
86- false ,
87- ) ;
76+ cy . visit ( `/cms/render/${ workspace } /${ locale } /sites/${ siteKey } /home/testPageI18N.html` ) ;
77+ testI18n ( locale , 'div[data-testid="i18n-server-side"]' , "We are server side !" , false ) ;
8878 testI18n (
89- workspace ,
9079 locale ,
9180 'div[data-testid="i18n-hydrated-client-side"]' ,
9281 "We are hydrated client side !" ,
9382 true ,
9483 ) ;
9584 testI18n (
96- workspace ,
9785 locale ,
9886 'div[data-testid="i18n-rendered-client-side"]' ,
9987 "We are rendered client side !" ,
10088 true ,
10189 ) ;
10290 } ) ;
103-
10491 cy . get ( '[data-testid="getSiteLocales"]' ) . should ( "contain" , "de,en,fr,fr_LU" ) ;
10592 } ) ;
10693 cy . logout ( ) ;
94+
95+ deleteSite ( siteKey ) ;
10796 } ) ;
10897
10998 const testI18n = (
110- workspace : string ,
11199 locale : string ,
112100 mainSelector : string ,
113101 placeholderIntialValue : string ,
@@ -141,8 +129,46 @@ describe("Test i18n", () => {
141129 }
142130 } ;
143131
144- after ( "Cleanup" , ( ) => {
145- cy . visit ( "/start" , { failOnStatusCode : false } ) ;
146- deleteSite ( "javascriptI18NTestSite" ) ;
132+ it . only ( "Support client-side i18n with components from multiple JS modules on the same page" , ( ) => {
133+ const siteKey = "javascriptI18NMultiModuleTestSite" ;
134+ createSiteWithContent ( siteKey ) ;
135+ // add a component from another JS module
136+ enableModule ( "hydrogen" , siteKey ) ;
137+ addNode ( {
138+ parentPathOrId : `/sites/${ siteKey } /home/testPageI18N/pagecontent` ,
139+ name : "testOtherModule" ,
140+ primaryNodeType : "hydrogen:helloWorld" ,
141+ properties : [ { name : "name" , value : "John Doe" , language : "en" } ] ,
142+ } ) ;
143+ publishAndWaitJobEnding ( `/sites/${ siteKey } /home/testPageI18N` , [ "en" ] ) ;
144+
145+ cy . login ( ) ;
146+ [ "live" , "default" ] . forEach ( ( workspace ) => {
147+ cy . visit ( `/cms/render/${ workspace } /en/sites/${ siteKey } /home/testPageI18N.html` ) ;
148+
149+ // make sure the 2 modules are present on the page with their i18n store
150+ cy . get ( 'script[data-i18n-store="javascript-modules-engine-test-module"]' ) . should ( "exist" ) ;
151+ cy . get ( 'script[data-i18n-store="hydrogen"]' ) . should ( "exist" ) ;
152+ cy . get ( "jsm-island" ) . then ( ( $islands ) => {
153+ // get unique "data-bundle" values from all islands elements
154+ const bundles = new Set ( $islands . get ( ) . map ( ( el ) => el . getAttribute ( "data-bundle" ) ) ) ;
155+ expect ( bundles . size ) . to . eq ( 2 ) ;
156+ expect ( bundles ) . to . contain ( "javascript-modules-engine-test-module" ) ;
157+ expect ( bundles ) . to . contain ( "hydrogen" ) ;
158+ } ) ;
159+
160+ // make sure the translations are rendered client-side
161+ cy . get (
162+ 'jsm-island[data-bundle="javascript-modules-engine-test-module"] [data-testid="i18n-simple"]' ,
163+ ) . should ( "contain" , testData . translations . en . simple ) ;
164+ cy . get ( 'jsm-island[data-bundle="hydrogen"] [data-testid="i18n-client-only"]' ) . should (
165+ "contain" ,
166+ "Rendered client-side only" , // the translated content
167+ ) ;
168+ } ) ;
169+
170+ cy . logout ( ) ;
171+
172+ deleteSite ( siteKey ) ;
147173 } ) ;
148174} ) ;
0 commit comments