mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Implement first cucumber features with factories
This commit is contained in:
parent
8fb94a12dd
commit
a024282f75
1
.gitignore
vendored
1
.gitignore
vendored
@ -79,3 +79,4 @@ static/uploads
|
||||
|
||||
cypress/videos
|
||||
cypress/screenshots/
|
||||
cypress.env.json
|
||||
|
||||
5
cypress.env.template.json
Normal file
5
cypress.env.template.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"NEO4J_URI": "bolt://localhost:7687",
|
||||
"NEO4J_USERNAME": "neo4j",
|
||||
"NEO4J_PASSWORD": "letmein"
|
||||
}
|
||||
@ -5,7 +5,7 @@ Feature: Create a post
|
||||
|
||||
Background:
|
||||
Given I am logged in
|
||||
Given I am on the "landing" page
|
||||
And I am on the "landing" page
|
||||
|
||||
Scenario: Create a post
|
||||
When I click on the big plus icon in the bottom right corner to create post
|
||||
|
||||
@ -6,9 +6,18 @@ import users from '../../fixtures/users.json'
|
||||
|
||||
let lastPost = {
|
||||
}
|
||||
let loginCredentials
|
||||
|
||||
Given('I am logged in', () => {
|
||||
cy.loginAs('admin')
|
||||
loginCredentials = {
|
||||
email: 'admin@example.org',
|
||||
password: '1234',
|
||||
}
|
||||
cy.factory().create('user', {
|
||||
role: 'admin',
|
||||
...loginCredentials
|
||||
})
|
||||
cy.login('admin@example.org', '1234')
|
||||
})
|
||||
Given('I am logged in as {string}', userType => {
|
||||
cy.loginAs(userType)
|
||||
@ -112,7 +121,9 @@ When('I click on the big plus icon in the bottom right corner to create post', (
|
||||
})
|
||||
|
||||
Given('I previously created a post', () => {
|
||||
// TODO: create a post in the database
|
||||
cy.factory()
|
||||
.authenticateAs(loginCredentials)
|
||||
.create('post', lastPost)
|
||||
})
|
||||
|
||||
When('I choose {string} as the title of the post', (title) => {
|
||||
@ -121,15 +132,15 @@ When('I choose {string} as the title of the post', (title) => {
|
||||
})
|
||||
|
||||
When('I type in the following text:', (text) => {
|
||||
lastPost.text = text.replace('\n', ' ')
|
||||
cy.get('.ProseMirror').type(lastPost.text)
|
||||
lastPost.content = text.replace('\n', ' ')
|
||||
cy.get('.ProseMirror').type(lastPost.content)
|
||||
})
|
||||
|
||||
Then('the post shows up on the landing page at position {int}', (index) => {
|
||||
cy.openPage('landing')
|
||||
const selector = `:nth-child(${index}) > .ds-card > .ds-card-content`
|
||||
cy.get(selector).should('contain', lastPost.title)
|
||||
cy.get(selector).should('contain', lastPost.text)
|
||||
cy.get(selector).should('contain', lastPost.content)
|
||||
})
|
||||
|
||||
Then('I get redirected to {string}', (route) => {
|
||||
@ -138,5 +149,5 @@ Then('I get redirected to {string}', (route) => {
|
||||
|
||||
Then('the post was saved successfully', () => {
|
||||
cy.get('.ds-card-header > .ds-heading').should('contain', lastPost.title)
|
||||
cy.get('.content').should('contain', lastPost.text)
|
||||
cy.get('.content').should('contain', lastPost.content)
|
||||
})
|
||||
|
||||
30
cypress/support/factories.js
Normal file
30
cypress/support/factories.js
Normal file
@ -0,0 +1,30 @@
|
||||
// TODO: find a better way how to import the factories
|
||||
import Factory from '../../../Nitro-Backend/src/seed/factories'
|
||||
import { getDriver } from '../../../Nitro-Backend/src/bootstrap/neo4j'
|
||||
|
||||
const neo4jDriver = getDriver({
|
||||
uri: Cypress.env('NEO4J_URI'),
|
||||
username: Cypress.env('NEO4J_USERNAME'),
|
||||
password: Cypress.env('NEO4J_PASSWORD')
|
||||
})
|
||||
const factory = Factory({neo4jDriver})
|
||||
|
||||
beforeEach(async () => {
|
||||
await factory.cleanDatabase({ neo4jDriver })
|
||||
})
|
||||
|
||||
Cypress.Commands.add('factory', (node, relationship, properties) => {
|
||||
return Factory()
|
||||
})
|
||||
|
||||
Cypress.Commands.add('create', { prevSubject: true }, (factory, node, properties) => {
|
||||
return factory.create(node, properties)
|
||||
})
|
||||
|
||||
Cypress.Commands.add('relate', { prevSubject: true }, (factory, node, relationship, properties) => {
|
||||
return factory.relate(node, relationship, properties)
|
||||
})
|
||||
|
||||
Cypress.Commands.add('authenticateAs', { prevSubject: true }, (factory, node, relationship, properties) => {
|
||||
return factory.authenticateAs(node, relationship, properties)
|
||||
})
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
import './factories'
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user