diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 98e2d862b..4387feeaf 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -1,5 +1,5 @@ import { Given, When, Then } from "cypress-cucumber-preprocessor/steps"; -import { getLangByName } from "../../support/helpers"; +import helpers from "../../support/helpers"; import slugify from "slug"; /* global cy */ @@ -131,14 +131,17 @@ Then("I am still logged in", () => { When("I select {string} in the language menu", name => { cy.switchLanguage(name, true); }); + Given("I previously switched the language to {string}", name => { cy.switchLanguage(name, true); }); + Then("the whole user interface appears in {string}", name => { - const lang = getLangByName(name); - cy.get(`html[lang=${lang.code}]`); - cy.getCookie("locale").should("have.property", "value", lang.code); + const { code } = helpers.getLangByName(name); + cy.get(`html[lang=${code}]`); + cy.getCookie("locale").should("have.property", "value", code); }); + Then("I see a button with the label {string}", label => { cy.contains("button", label); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index e69d296dc..630b52935 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -14,7 +14,7 @@ /* globals Cypress cy */ import "cypress-file-upload"; -import { getLangByName } from "./helpers"; +import helpers from "./helpers"; import users from "../fixtures/users.json"; const switchLang = name => { @@ -22,8 +22,9 @@ const switchLang = name => { cy.contains(".locale-menu-popover a", name).click(); }; + Cypress.Commands.add("switchLanguage", (name, force) => { - const code = getLangByName(name).code; + const { code } = helpers.getLangByName(name); if (force) { switchLang(name); } else { diff --git a/cypress/support/helpers.js b/cypress/support/helpers.js index 4a8376ec0..7d66af5d6 100644 --- a/cypress/support/helpers.js +++ b/cypress/support/helpers.js @@ -1,10 +1,8 @@ import find from 'lodash/find' +import locales from '../../webapp/locales' -const helpers = { - locales: require('../../webapp/locales'), - getLangByName: name => { - return find(helpers.locales, { name }) +export default { + getLangByName(name) { + return find(locales, { name }) } } - -export default helpers