Implemented most cucumber features with factories

This commit is contained in:
Robert Schäfer 2019-02-21 23:37:53 +01:00
parent a024282f75
commit 5e0d245b40
8 changed files with 65 additions and 70 deletions

View File

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

View File

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

View File

@ -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 "<location>"
When I save "<location>" 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

View File

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

View File

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

View File

@ -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 => {

View File

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

View File

@ -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)
})