diff --git a/cypress/integration/01.Login.feature b/cypress/integration/01.Login.feature index 72adc8553..3837f7042 100644 --- a/cypress/integration/01.Login.feature +++ b/cypress/integration/01.Login.feature @@ -4,11 +4,7 @@ Feature: Authentication In order to attribute posts and other contributions to their authors Background: - Given my account has the following details: - | 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 + Given I have a user account Scenario: Log in When I visit the "/login" page diff --git a/cypress/integration/03.TagsAndCategories.feature b/cypress/integration/03.TagsAndCategories.feature index f9509e858..050fb3643 100644 --- a/cypress/integration/03.TagsAndCategories.feature +++ b/cypress/integration/03.TagsAndCategories.feature @@ -14,9 +14,9 @@ Feature: Tags and Categories looking at the popularity of a tag. Background: - Given we have a selection of tags and categories as well as posts - And my user account has the role "administrator" - Given I am logged in + Given my user account has the role "admin" + And we have a selection of tags and categories as well as posts + And I am logged in Scenario: See an overview of categories When I navigate to the administration dashboard diff --git a/cypress/integration/04.AboutMeAndLocation.feature b/cypress/integration/04.AboutMeAndLocation.feature index aedbf62bc..2a512bf3f 100644 --- a/cypress/integration/04.AboutMeAndLocation.feature +++ b/cypress/integration/04.AboutMeAndLocation.feature @@ -7,21 +7,18 @@ Feature: About me and location to search for users by location. Background: - Given I am logged in + Given I have a user account + And I am logged in And I am on the "settings" page Scenario: Change username When I save "Hansi" as my new name Then I can see my new name "Hansi" when I click on my profile picture in the top right - - Scenario: Keep changes after refresh - When I changed my username to "Hansi" previously - And I refresh the page - Then my new username is still there + And when I refresh the page + Then the name "Hansi" is still there Scenario Outline: I set my location to "" When I save "" as my location - And my username is "Peter Lustig" When people visit my profile page Then they can see the location in the info box below my avatar @@ -36,6 +33,5 @@ Feature: About me and location """ Ich lebe fettlos, fleischlos, fischlos dahin, fühle mich aber ganz wohl dabei """ - And my username is "Peter Lustig" When people visit my profile page Then they can see the text in the info box below my avatar diff --git a/cypress/integration/06.WritePost.feature b/cypress/integration/06.WritePost.feature index a9cb81ff9..0193e44bf 100644 --- a/cypress/integration/06.WritePost.feature +++ b/cypress/integration/06.WritePost.feature @@ -4,7 +4,8 @@ Feature: Create a post To say something to everyone in the community Background: - Given I am logged in + Given I have a user account + And I am logged in And I am on the "landing" page Scenario: Create a post diff --git a/cypress/integration/common/settings.js b/cypress/integration/common/settings.js index b7b283e2b..9f74a1200 100644 --- a/cypress/integration/common/settings.js +++ b/cypress/integration/common/settings.js @@ -4,7 +4,6 @@ import { When, Then } from 'cypress-cucumber-preprocessor/steps' let aboutMeText let myLocation -let myName const matchNameInUserMenu = name => { cy.get('.avatar-menu').click() // open @@ -12,18 +11,13 @@ const matchNameInUserMenu = name => { cy.get('.avatar-menu').click() // close again } -const setUserName = name => { +When('I save {string} as my new name', name => { cy.get('input[id=name]') .clear() .type(name) cy.get('[type=submit]') .click() .not('[disabled]') - myName = name -} - -When('I save {string} as my new name', name => { - setUserName(name) }) When('I save {string} as my location', location => { @@ -47,31 +41,20 @@ When('I have the following self-description:', text => { aboutMeText = text }) -When('my username is {string}', name => { - if (myName !== name) { - setUserName(name) - } - matchNameInUserMenu(name) -}) - When('people visit my profile page', url => { - cy.visitMyProfile() + cy.openPage('/profile/peter-pan') }) When('they can see the text in the info box below my avatar', () => { cy.contains(aboutMeText) }) -When('I changed my username to {string} previously', name => { - myName = name -}) - Then('they can see the location in the info box below my avatar', () => { - matchNameInUserMenu(myName) + cy.contains(myLocation) }) -Then('my new username is still there', () => { - matchNameInUserMenu(myName) +Then('the name {string} is still there', (name) => { + matchNameInUserMenu(name) }) Then( diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index fcc2c2789..a00dd5d8f 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -1,38 +1,64 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' import { getLangByName } from '../../support/helpers' -import users from '../../fixtures/users.json' /* global cy */ let lastPost = { } -let loginCredentials + +const loginCredentials = { + email: 'peterpan@example.org', + password: '1234', +} +const narratorParams = { + name: "Peter Pan", + ...loginCredentials +} Given('I am logged in', () => { - loginCredentials = { - email: 'admin@example.org', - password: '1234', - } - cy.factory().create('user', { - role: 'admin', - ...loginCredentials - }) - cy.login('admin@example.org', '1234') + cy.login(loginCredentials) }) Given('I am logged in as {string}', userType => { cy.loginAs(userType) }) Given('we have a selection of tags and categories as well as posts', () => { - // TODO: use db factories instead of seed data + cy.factory() + .authenticateAs(loginCredentials) + .create('category', { id: 'cat1', name: 'Just For Fun', slug: 'justforfun', icon: 'smile' }) + .create('category', { id: 'cat2', name: 'Happyness & Values', slug: 'happyness-values', icon: 'heart-o' }) + .create('category', { id: 'cat3', name: 'Health & Wellbeing', slug: 'health-wellbeing', icon: 'medkit' }) + .create('tag', { id: 't1', name: 'Ecology' }) + .create('tag', { id: 't2', name: 'Nature' }) + .create('tag', { id: 't3', name: 'Democracy' }) + .create('post', { id: 'p0' }) + .create('post', { id: 'p1' }) + .create('post', { id: 'p2' }) + .relate('post', 'Categories', { from: 'p0', to: 'cat1' }) + .relate('post', 'Categories', { from: 'p1', to: 'cat2' }) + .relate('post', 'Categories', { from: 'p2', to: 'cat3' }) + .relate('post', 'Tags', { from: 'p0', to: 't1' }) + .relate('post', 'Tags', { from: 'p0', to: 't2' }) + .relate('post', 'Tags', { from: 'p0', to: 't3' }) + .relate('post', 'Tags', { from: 'p1', to: 't1' }) + .relate('post', 'Tags', { from: 'p1', to: 't2' }) }) -Given('my account has the following details:', table => { - // TODO: use db factories instead of seed data +Given('we have the following user accounts:', table => { + table.hashes().forEach((params) => { + cy.factory().create('user', params) + }) +}) + +Given('I have a user account', () => { + cy.factory().create('user', narratorParams) }) Given('my user account has the role {string}', role => { - // TODO: use db factories instead of seed data + cy.factory().create('user', { + role, + ...loginCredentials + }) }) When('I log out', cy.logout) @@ -46,10 +72,10 @@ Given('I am on the {string} page', page => { }) When('I fill in my email and password combination and click submit', () => { - cy.login('admin@example.org', 1234) + cy.login(loginCredentials) }) -When('I refresh the page', () => { +When(/(?:when )?I refresh the page/, () => { cy.reload() }) @@ -61,7 +87,7 @@ When('I log out through the menu in the top right corner', () => { }) Then('I can see my name {string} in the dropdown menu', () => { - cy.get('.avatar-menu-popover').should('contain', users.admin.name) + cy.get('.avatar-menu-popover').should('contain', narratorParams.name) }) Then('I see the login screen again', () => { @@ -75,7 +101,7 @@ Then('I can click on my profile picture in the top right corner', () => { Then('I am still logged in', () => { cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover').contains(users.admin.name) + cy.get('.avatar-menu-popover').contains(narratorParams.name) }) When('I select {string} in the language menu', name => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ebbd6acd1..30b7745cd 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -35,14 +35,7 @@ Cypress.Commands.add('switchLanguage', (name, force) => { } }) -Cypress.Commands.add('visitMyProfile', () => { - cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover') - .find('a[href^="/profile/"]') - .click() -}) - -Cypress.Commands.add('login', (email, password) => { +Cypress.Commands.add('login', ({email, password}) => { cy.visit(`/login`) cy.get('input[name=email]') .trigger('focus') @@ -58,7 +51,7 @@ Cypress.Commands.add('login', (email, password) => { Cypress.Commands.add('loginAs', role => { role = role || 'admin' - cy.login(users[role].email, users[role].password) + cy.login(users[role]) }) Cypress.Commands.add('logout', (email, password) => { diff --git a/cypress/support/factories.js b/cypress/support/factories.js index c56f6bf27..1c4515737 100644 --- a/cypress/support/factories.js +++ b/cypress/support/factories.js @@ -13,7 +13,7 @@ beforeEach(async () => { await factory.cleanDatabase({ neo4jDriver }) }) -Cypress.Commands.add('factory', (node, relationship, properties) => { +Cypress.Commands.add('factory', () => { return Factory() }) @@ -25,6 +25,6 @@ Cypress.Commands.add('relate', { prevSubject: true }, (factory, node, relationsh return factory.relate(node, relationship, properties) }) -Cypress.Commands.add('authenticateAs', { prevSubject: true }, (factory, node, relationship, properties) => { - return factory.authenticateAs(node, relationship, properties) +Cypress.Commands.add('authenticateAs', { prevSubject: true }, (factory, loginCredentials) => { + return factory.authenticateAs(loginCredentials) })