diff --git a/cypress/integration/Login.feature b/cypress/integration/01.Login.feature similarity index 71% rename from cypress/integration/Login.feature rename to cypress/integration/01.Login.feature index a7a47ddd5..72adc8553 100644 --- a/cypress/integration/Login.feature +++ b/cypress/integration/01.Login.feature @@ -5,8 +5,10 @@ Feature: Authentication Background: Given my account has the following details: - | name | email | password | - | Peter Lustig | admin@example.org | 1234 | + | name | email | password | type + | Peter Lustig | admin@example.org | 1234 | Admin + | Bob der Bausmeister | moderator@example.org | 1234 | Moderator + | Jenny Rostock" | user@example.org | 1234 | User Scenario: Log in When I visit the "/login" page diff --git a/cypress/integration/Internationalization.feature b/cypress/integration/02.Internationalization.feature similarity index 100% rename from cypress/integration/Internationalization.feature rename to cypress/integration/02.Internationalization.feature diff --git a/cypress/integration/TagsAndCategories.feature b/cypress/integration/03.TagsAndCategories.feature similarity index 100% rename from cypress/integration/TagsAndCategories.feature rename to cypress/integration/03.TagsAndCategories.feature diff --git a/cypress/integration/AboutMeAndLocation.feature b/cypress/integration/04.AboutMeAndLocation.feature similarity index 96% rename from cypress/integration/AboutMeAndLocation.feature rename to cypress/integration/04.AboutMeAndLocation.feature index 9d0760a04..ee049fa31 100644 --- a/cypress/integration/AboutMeAndLocation.feature +++ b/cypress/integration/04.AboutMeAndLocation.feature @@ -16,6 +16,7 @@ Feature: About me and and location When I refresh the page Then I can see my new name "Hansi" when I click on my profile picture in the top right + Then I save "Peter Lustig" as my new name Scenario Outline: I set my location to "" When I save "" as my location diff --git a/cypress/integration/common/admin.js b/cypress/integration/common/admin.js new file mode 100644 index 000000000..b1466a402 --- /dev/null +++ b/cypress/integration/common/admin.js @@ -0,0 +1,39 @@ +import { When, Then } from 'cypress-cucumber-preprocessor/steps' + +/* global cy */ + +const lastColumnIsSortedInDescendingOrder = () => { + cy.get('tbody') + .find('tr td:last-child') + .then(lastColumn => { + cy.wrap(lastColumn) + const values = lastColumn + .map((i, td) => parseInt(td.textContent)) + .toArray() + const orderedDescending = values.slice(0).sort((a, b) => b - a) + return cy.wrap(values).should('deep.eq', orderedDescending) + }) +} + +When('I navigate to the administration dashboard', () => { + cy.get('.avatar-menu').click() + cy.get('.avatar-menu-popover a') + .contains('Admin') + .click() +}) + +Then('I can see a list of categories ordered by post count:', table => { + // TODO: match the table in the feature with the html table + cy.get('thead') + .find('tr th') + .should('have.length', 3) + lastColumnIsSortedInDescendingOrder() +}) + +Then('I can see a list of tags ordered by user and post count:', table => { + // TODO: match the table in the feature with the html table + cy.get('thead') + .find('tr th') + .should('have.length', 4) + lastColumnIsSortedInDescendingOrder() +}) diff --git a/cypress/integration/common/settings.js b/cypress/integration/common/settings.js new file mode 100644 index 000000000..9036d5a5e --- /dev/null +++ b/cypress/integration/common/settings.js @@ -0,0 +1,48 @@ +import { When, Then } from 'cypress-cucumber-preprocessor/steps' + +/* global cy */ + +When('I save {string} as my new name', name => { + cy.get('input[id=name]') + .clear() + .type(name) + cy.contains('Save').click() +}) + +When('I save {string} as my location', location => { + cy.get('input[id=city]').type(location) + cy.get('.ds-select-option') + .contains(location) + .click() + cy.contains('Save').click() +}) + +When('I save {string} to about me', text => { + cy.get('textarea[id=bio]') + .clear() + .type(text) + cy.contains('Save').click() +}) + +Then( + 'I can see my new name {string} when I click on my profile picture in the top right', + name => { + cy.get('input[id=name]') + .clear() + .type(name) + cy.contains('Save').click() + } +) + +Then('I can see {string} as my location', location => { + cy.contains(location) +}) + +Then('I can see a {string} as my about me', about => { + cy.contains(about) +}) + +Then('I can see a {string} as my name', name => { + cy.get('.avatar-menu-popover').contains(name) +}) + diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index c0510eff1..0561bd503 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -1,9 +1,9 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' import find from 'lodash/find' +import { baseUrl } from '../../support/config' -/* global cy */ +/* global cy */ -const baseUrl = 'http://localhost:3000' const username = 'Peter Lustig' const locales = require('../../../locales') @@ -19,46 +19,8 @@ const openPage = function(page) { cy.visit(`${baseUrl}/${page}`) } -const switchLanguage = function(name) { - cy.get('.login-locale-switch a').click() - cy.contains('.locale-menu-popover a', name).click() -} - -const login = (email, password) => { - cy.visit(`${baseUrl}/login`) - switchLanguage('English') - cy.get('input[name=email]') - .trigger('focus') - .type(email) - cy.get('input[name=password]') - .trigger('focus') - .type(password) - cy.get('button[name=submit]') - .as('submitButton') - .click() - cy.location('pathname').should('eq', '/') // we're in! -} - -const logout = () => { - cy.visit(`${baseUrl}/logout`) - cy.location('pathname').should('contain', '/login') // we're out -} - -const lastColumnIsSortedInDescendingOrder = () => { - cy.get('tbody') - .find('tr td:last-child') - .then(last_column => { - cy.wrap(last_column) - const values = last_column - .map((i, td) => parseInt(td.textContent)) - .toArray() - const ordered_descending = values.slice(0).sort((a, b) => b - a) - return cy.wrap(values).should('deep.eq', ordered_descending) - }) -} - Given('I am logged in', () => { - login('admin@example.org', 1234) + cy.login('admin@example.org', 1234) }) Given('we have a selection of tags and categories as well as posts', () => { @@ -73,7 +35,7 @@ Given('my user account has the role {string}', role => { // TODO: use db factories instead of seed data }) -When('I log out', logout) +When('I log out', cy.logout) When('I visit the {string} page', page => { openPage(page) @@ -83,7 +45,7 @@ Given('I am on the {string} page', page => { }) When('I fill in my email and password combination and click submit', () => { - login('admin@example.org', 1234) + cy.login('admin@example.org', 1234) }) When('I refresh the page', () => { @@ -118,10 +80,10 @@ Then('I am still logged in', () => { }) When('I select {string} in the language menu', name => { - switchLanguage(name) + cy.switchLanguage(name) }) Given('I previously switched the language to {string}', name => { - switchLanguage(name) + cy.switchLanguage(name) }) Then('the whole user interface appears in {string}', name => { const lang = getLangByName(name) @@ -132,70 +94,10 @@ Then('I see a button with the label {string}', label => { cy.contains('button', label) }) -When('I navigate to the administration dashboard', () => { - cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover a') - .contains('Admin') - .click() -}) - When(`I click on {string}`, linkOrButton => { cy.contains(linkOrButton).click() }) -Then('I can see a list of categories ordered by post count:', table => { - // TODO: match the table in the feature with the html table - cy.get('thead') - .find('tr th') - .should('have.length', 3) - lastColumnIsSortedInDescendingOrder() -}) - -Then('I can see a list of tags ordered by user and post count:', table => { - // TODO: match the table in the feature with the html table - cy.get('thead') - .find('tr th') - .should('have.length', 4) - lastColumnIsSortedInDescendingOrder() -}) - -When('I save {string} as my location', location => { - cy.get('input[id=city]').type(location) - cy.get('.ds-select-option') - .contains(location) - .click() - cy.contains('Save').click() -}) -When('I save {string} to about me', text => { - cy.get('textarea[id=bio]') - .clear() - .type(text) - cy.contains('Save').click() -}) -When('I save {string} as my new name', name => { - cy.get('input[id=name]') - .clear() - .type(name) - cy.contains('Save').click() -}) -Then( - 'I can see my new name {string} when I click on my profile picture in the top right', - name => { - cy.get('input[id=name]') - .clear() - .type(name) - cy.contains('Save').click() - } -) When('I press {string}', label => { cy.contains(label).click() }) -Then('I can see {string} as my location', location => { - cy.contains(location) -}) -Then('I can see a {string} as my about me', about => { - cy.contains(about) -}) -Then('I can see a {string} as my name', name => { - cy.get('.avatar-menu-popover').contains(name) -}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c1f5a772e..0eb913836 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -10,16 +10,45 @@ // // // -- This is a parent command -- -// Cypress.Commands.add("login", (email, password) => { ... }) +// Cypress.Commands.add('login', (email, password) => { ... }) + +/* globals Cypress cy */ + +import { baseUrl } from './config' + +Cypress.Commands.add('switchLanguage', lang => { + cy.get('.login-locale-switch a').click() + cy.contains('.locale-menu-popover a', lang).click() +}) + +Cypress.Commands.add('login', (email, password) => { + cy.visit(`${baseUrl}/login`) + cy.switchLanguage('English') + cy.get('input[name=email]') + .trigger('focus') + .type(email) + cy.get('input[name=password]') + .trigger('focus') + .type(password) + cy.get('button[name=submit]') + .as('submitButton') + .click() + cy.location('pathname').should('eq', '/') // we're in! +}) +Cypress.Commands.add('logout', (email, password) => { + cy.visit(`${baseUrl}/logout`) + cy.location('pathname').should('contain', '/login') // we're out +}) + // // // -- This is a child command -- -// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) // // // -- This is a dual command -- -// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) // // // -- This is will overwrite an existing command -- -// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) diff --git a/cypress/support/config.js b/cypress/support/config.js new file mode 100644 index 000000000..feabb62fe --- /dev/null +++ b/cypress/support/config.js @@ -0,0 +1,17 @@ +export default { + baseUrl: 'http://localhost:3000', + users: { + admin: { + email: 'admin@example.org', + password: 1234 + }, + moderator: { + email: 'moderator@example.org', + password: 1234 + }, + user: { + email: 'user@example.org', + password: 1234 + } + } +}