Refactored internationalization tests

This commit is contained in:
Grzegorz Leoniec 2018-12-21 15:11:13 +01:00
parent 8106d632ed
commit 4f3a18263b
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
2 changed files with 32 additions and 22 deletions

View File

@ -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"

View File

@ -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', () => {