Internationalization.feature

This commit is contained in:
Ulf Gebhardt 2021-04-11 20:00:31 +02:00
parent b6ffca2c0a
commit 163ee21180
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
8 changed files with 23 additions and 48 deletions

View File

@ -4,7 +4,7 @@ Feature: Internationalization
In order to be able to understand the interface
Background:
Given I am on the "login" page
Given I navigate to page "/login"
Scenario Outline: I select "<language>" in the language menu and see "<buttonLabel>"
When I select "<language>" in the language menu
@ -18,6 +18,6 @@ Feature: Internationalization
| English | Login |
Scenario: Keep preferred language after refresh
Given I previously switched the language to "Français"
When I select "Français" in the language menu
And I refresh the page
Then the whole user interface appears in "Français"

View File

@ -0,0 +1,5 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then("I see a button with the label {string}", label => {
cy.contains("button", label);
});

View File

@ -0,0 +1,8 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I select {string} in the language menu", language => {
cy.get(".locale-menu")
.click();
cy.contains(".locale-menu-popover a", language)
.click();
});

View File

@ -0,0 +1,8 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import locales from '../../../webapp/locales'
Then("the whole user interface appears in {string}", language => {
const { code } = locales.find((entry) => entry.name === language);
cy.get(`html[lang=${code}]`);
cy.getCookie("locale").should("have.property", "value", code);
});

View File

@ -52,26 +52,6 @@ When("a blocked user visits the post page of one of my authored posts", () => {
cy.openPage('post/previously-created-post')
})
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 {
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);
});
When(`I click on the menu item {string}`, linkOrButton => {
cy.contains(".ds-menu-item", linkOrButton).click();
});

View File

@ -19,11 +19,6 @@ import { GraphQLClient, request } from 'graphql-request'
import { gql } from '../../backend/src/helpers/jest'
import config from '../../backend/src/config'
const switchLang = name => {
cy.get(".locale-menu").click();
cy.contains(".locale-menu-popover a", name).click();
};
const authenticatedHeaders = (variables) => {
const mutation = gql`
mutation($email: String!, $password: String!) {
@ -37,19 +32,6 @@ const authenticatedHeaders = (variables) => {
})
}
Cypress.Commands.add("switchLanguage", (name, force) => {
const { code } = helpers.getLangByName(name);
if (force) {
switchLang(name);
} else {
cy.get("html").then($html => {
if ($html && $html.attr("lang") !== code) {
switchLang(name);
}
});
}
});
Cypress.Commands.add("logout", () => {
cy.visit(`/logout`);
cy.location("pathname").should("contain", "/login"); // we're out

View File

@ -1,8 +0,0 @@
import find from 'lodash/find'
import locales from '../../webapp/locales'
export default {
getLangByName(name) {
return find(locales, { name })
}
}