From ecf8e2bd40309250433344869342b11d6015a918 Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Tue, 4 Apr 2023 15:54:08 +0100 Subject: [PATCH] pkp/pkp-lib#8346 Add Cypress command to change the UI language --- cypress/support/commands.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 4a5e4c3d586..65108f68c09 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -80,7 +80,7 @@ Cypress.Commands.add('dispatchTestQueueJobs', (times) => { times = times || 1; for (let index = 0; index < times; index++) { - cy.exec('php lib/pkp/tools/jobs.php test'); + cy.exec('php lib/pkp/tools/jobs.php test'); } }); @@ -866,3 +866,21 @@ Cypress.Commands.add('uploadSubmissionFiles', (files, options) => { }); }); }); + +Cypress.Commands.add('changeLanguage', (locale, contextPath) => { + contextPath = contextPath || 'publicknowledge'; + + // Workaround to make the request with a referrer + // It is not possible to set the referrer header with cy.visit() + cy.window() + .then((win) => { + const link = win.document.createElement('a'); + const url = Cypress.config().baseUrl + '/index.php/' + contextPath + '/user/setLocale/' + locale; + link.setAttribute('href', url); + link.setAttribute('id', 'cypressChangeLanguage'); + link.innerHTML = locale; + win.document.body.appendChild(link); + }); + cy.get('a#cypressChangeLanguage') + .click(); +});