From 4f3a18263b257edc870f3e02bbcedb50883a0a74 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Fri, 21 Dec 2018 15:11:13 +0100 Subject: [PATCH] Refactored internationalization tests --- .../integration/Internationalization.feature | 12 +++--- cypress/integration/common/steps.js | 42 ++++++++++++------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/cypress/integration/Internationalization.feature b/cypress/integration/Internationalization.feature index d1c4051a7..cf679b982 100644 --- a/cypress/integration/Internationalization.feature +++ b/cypress/integration/Internationalization.feature @@ -4,21 +4,21 @@ Feature: Internationalization In order to be able to understand the interface Background: - When I visit the "login" page + Given I am on the "login" page Scenario: Change the language When I select "Deutsch" in the language menu - Then The whole user interface appears in "Deutsch" + Then the whole user interface appears in "Deutsch" When I select "Français" in the language menu - Then The whole user interface appears in "Français" + Then the whole user interface appears in "Français" When I select "English" in the language menu - Then The whole user interface appears in "English" + Then the whole user interface appears in "English" Scenario: Keep preferred language after refresh When I select "Deutsch" in the language menu - Then The whole user interface appears in "Deutsch" + Then the whole user interface appears in "Deutsch" And I refresh the page - Then The whole user interface appears in "Deutsch" + Then the whole user interface appears in "Deutsch" diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index a835f1bde..91f0906d4 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -1,5 +1,8 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' import find from 'lodash/find' +import { eq } from 'semver'; + +/* global cy */ const baseUrl = 'http://localhost:3000' const username = 'Peter Lustig' @@ -14,6 +17,18 @@ const localeStrings = { } } +const getLangByName = function(name) { + return find(locales, { name }) +} + +const openPage = function(page) { + if (page === 'landing') { + page = '' + } + cy.visit(`${baseUrl}/${page}`) + cy.get('html[data-n-head]') +} + const login = (email, password) => { cy.visit(`${baseUrl}/login`) cy.get('input[name=email]') @@ -51,14 +66,11 @@ Given('my user account has the role {string}', (role) => { When('I log out', logout) -When('I visit the {string} page', route => { - if (route === 'main') { - route = '' - } - cy.visit(`${baseUrl}/${route}`) +When('I visit the {string} page', page => { + openPage(page) }) Given('I am on the {string} page', page => { - cy.location('pathname').should('contain', `/${page}`) + openPage(page) }) When('I fill in my email and password combination and click submit', () => { @@ -97,17 +109,15 @@ Then('I am still logged in', () => { }) When('I select {string} in the language menu', name => { - cy.get('.login-locale-switch a') - .click() - const code = find(locales, ['name', name]).code - cy.get(`.locale-menu-popover a.${code}`) - .click() - .wait(500) + cy.get('.login-locale-switch a').click() + cy.contains('.locale-menu-popover a', name).click() }) -Then('The whole user interface appears in {string}', name => { - const code = find(locales, ['name', name]).code - cy.getCookie('locale').should('have.property', 'value', code) - cy.contains(localeStrings.login[name]) +Then('the whole user interface appears in {string}', name => { + const lang = getLangByName(name) + cy.get(`html[lang=${lang.code}]`) + cy.contains('button', localeStrings.login[name]) + cy.get(`html[lang=${getLangByName(name).code}]`).as('lang') + cy.getCookie('locale').should('have.property', 'value', lang.code) }) When('I navigate to the administration dashboard', () => {