From 02ed3db6fc3f4311e6371a1ce21b8d2c07fe12e3 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Thu, 10 Jan 2019 15:55:05 +0100 Subject: [PATCH] Improved integration tests --- .../integration/02.Internationalization.feature | 9 ++++----- cypress/integration/common/admin.js | 4 ++-- cypress/integration/common/settings.js | 8 +++++++- cypress/integration/common/steps.js | 4 +--- cypress/support/commands.js | 15 +++++++++------ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cypress/integration/02.Internationalization.feature b/cypress/integration/02.Internationalization.feature index 375fc03aa..0a5f90ff0 100644 --- a/cypress/integration/02.Internationalization.feature +++ b/cypress/integration/02.Internationalization.feature @@ -13,12 +13,11 @@ Feature: Internationalization Examples: Login Button | language | buttonLabel | - | English | Login | - | Deutsch | Einloggen | | Français | Connexion | - | Nederlands | Inloggen | + | Deutsch | Einloggen | + | English | Login | Scenario: Keep preferred language after refresh - Given I previously switched the language to "Deutsch" + Given I previously switched the language to "Français" And I refresh the page - Then the whole user interface appears in "Deutsch" + Then the whole user interface appears in "Français" diff --git a/cypress/integration/common/admin.js b/cypress/integration/common/admin.js index b1466a402..9162667b4 100644 --- a/cypress/integration/common/admin.js +++ b/cypress/integration/common/admin.js @@ -17,8 +17,8 @@ const lastColumnIsSortedInDescendingOrder = () => { When('I navigate to the administration dashboard', () => { cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover a') - .contains('Admin') + cy.get('.avatar-menu-popover') + .find('a[href="/admin"]') .click() }) diff --git a/cypress/integration/common/settings.js b/cypress/integration/common/settings.js index 0f5a9d9cc..f4746a3cd 100644 --- a/cypress/integration/common/settings.js +++ b/cypress/integration/common/settings.js @@ -7,8 +7,9 @@ let myLocation let myName const matchNameInUserMenu = name => { - cy.get('.avatar-menu').click() + cy.get('.avatar-menu').click() // open cy.get('.avatar-menu-popover').contains(name) + cy.get('.avatar-menu').click() // close again } const setUserName = name => { @@ -66,3 +67,8 @@ Then('they can see the location in the info box below my avatar', () => { Then('my new username is still there', () => { matchNameInUserMenu(myName) }) + +Then( + 'I can see my new name {string} when I click on my profile picture in the top right', + name => matchNameInUserMenu(name) +) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index ceaf3d328..173b1418d 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -48,8 +48,7 @@ When('I refresh the page', () => { When('I log out through the menu in the top right corner', () => { cy.get('.avatar-menu').click() cy.get('.avatar-menu-popover') - .find('a') - .contains('Logout') + .find('a[href="/logout"]') .click() }) @@ -64,7 +63,6 @@ Then('I can see my name {string} in the dropdown menu', () => { Then('I see the login screen again', () => { cy.location('pathname').should('contain', '/login') - cy.contains('If you already have a human-connection account, login here.') }) Then('I am still logged in', () => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 34fe771ef..77c75c7d5 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -17,21 +17,25 @@ import { getLangByName } from './helpers' const switchLang = name => { - cy.get('.login-locale-switch a').click() + cy.get('.locale-menu').click() cy.contains('.locale-menu-popover a', name).click() } Cypress.Commands.add('switchLanguage', (name, force) => { const code = getLangByName(name).code - if (force || !cy.get(`html[lang=${code}]`)) { + if (force) { switchLang(name) + } else { + cy.get('html').then($html => { + if ($html && $html.attr('lang') !== code) { + switchLang(name) + } + }) } }) Cypress.Commands.add('visitMyProfile', () => { - if (!cy.get('.avatar-menu-popover')) { - cy.get('.avatar-menu').click() - } + cy.get('.avatar-menu').click() cy.get('.avatar-menu-popover') .find('a[href^="/profile/"]') .click() @@ -39,7 +43,6 @@ Cypress.Commands.add('visitMyProfile', () => { Cypress.Commands.add('login', (email, password) => { cy.visit(`/login`) - cy.switchLanguage('English') cy.get('input[name=email]') .trigger('focus') .type(email)