post create cypress feature

This commit is contained in:
Ulf Gebhardt 2021-04-10 17:17:26 +02:00
parent c1b2c28724
commit 3c411514e9
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
25 changed files with 117 additions and 80 deletions

View File

@ -8,7 +8,7 @@ Feature: Authentication
Given I have an user account
Scenario: Log in
When I visit the "login" page
When I navigate to page "login"
And I fill in my credentials
And I click submit
Then I am logged in as "Peter Pan"

View File

@ -1,5 +0,0 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I visit the {string} page", page => {
cy.openPage(page);
});

View File

@ -0,0 +1,29 @@
Feature: Create a post
As an logged in user
I would like to create a post
To say something to everyone in the community
Background:
Given I have an user account
And I am logged in
And I navigate to page "landing"
Scenario: Create a post
When I click on create post
And I wait for 500 milliseconds
Then I am on page "post/create"
When I choose "My first post" as the title
And I choose the following text as content:
"""
Human Connection is a free and open-source social network
for active citizenship.
"""
And I click on "Save"
And I wait for 500 milliseconds
Then I am on page ".../my-first-post"
And the post was saved successfully
Scenario: See a post on the landing page
Given I previously created a post
And I navigate to page "landing"
And the post shows up on the landing page at position 1

View File

@ -0,0 +1,9 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I choose the following text as content:", async text => {
cy.task('getValue', 'lastPost').then(lastPost => {
lastPost.content = text.replace("\n", " ");
cy.task('pushValue', { name: 'lastPost', value: lastPost })
cy.get(".editor .ProseMirror").type(lastPost.content);
})
});

View File

@ -0,0 +1,8 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I choose {string} as the title", async title => {
const lastPost = {}
lastPost.title = title.replace("\n", " ");
cy.task('pushValue', { name: 'lastPost', value: lastPost })
cy.get('input[name="title"]').type(lastPost.title);
});

View File

@ -0,0 +1,5 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I click on create post", () => {
cy.get(".post-add-button").click();
});

View File

@ -0,0 +1,6 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When(`I click on {string}`, text => {
cy.contains(text)
.click()
});

View File

@ -0,0 +1,14 @@
import { Given } from "cypress-cucumber-preprocessor/steps";
import narrator from "../data/narrator"
Given("I previously created a post", () => {
const lastPost = {
title: "previously created post",
content: "with some content",
};
cy.factory()
.build("post", lastPost, {
authorId: narrator.id
});
cy.task('pushValue', { name: 'lastPost', value: lastPost })
});

View File

@ -0,0 +1,9 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then("the post shows up on the landing page at position {int}", index => {
cy.task('getValue', 'lastPost').then(lastPost => {
const selector = `.post-teaser:nth-child(${index}) > .base-card`;
cy.get(selector).should("contain", lastPost.title);
cy.get(selector).should("contain", lastPost.content);
})
});

View File

@ -0,0 +1,8 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then("the post was saved successfully", async () => {
cy.task('getValue', 'lastPost').then(lastPost => {
cy.get(".base-card > .title").should("contain", lastPost.title);
cy.get(".content").should("contain", lastPost.content);
})
});

View File

@ -145,10 +145,6 @@ Then("I see a button with the label {string}", label => {
cy.contains("button", label);
});
When(`I click on {string}`, linkOrButton => {
cy.contains(linkOrButton).click();
});
When(`I click on the menu item {string}`, linkOrButton => {
cy.contains(".ds-menu-item", linkOrButton).click();
});
@ -188,64 +184,6 @@ When("I click on the avatar menu in the top right corner", () => {
cy.get(".avatar-menu").click();
});
When(
"I click on the big plus icon in the bottom right corner to create post",
() => {
cy.get(".post-add-button").click();
cy.location("pathname").should('eq', '/post/create')
}
);
Given("I previously created a post", () => {
lastPost = {
lastPost,
title: "previously created post",
content: "with some content",
};
cy.factory()
.build("post", lastPost, {
authorId: narratorParams.id
});
});
When("I choose {string} as the title of the post", title => {
lastPost.title = title.replace("\n", " ");
cy.get('input[name="title"]').type(lastPost.title);
});
When("I type in the following text:", text => {
lastPost.content = text.replace("\n", " ");
cy.get(".editor .ProseMirror").type(lastPost.content);
});
Then("I select a category", () => {
cy.get(".base-button")
.contains("Just for Fun")
.click();
});
When("I choose {string} as the language for the post", (languageCode) => {
cy.get('.contribution-form .ds-select')
.click().get('.ds-select-option')
.eq(languages.findIndex(l => l.code === languageCode)).click()
})
Then("the post shows up on the landing page at position {int}", index => {
cy.openPage("landing");
const selector = `.post-teaser:nth-child(${index}) > .base-card`;
cy.get(selector).should("contain", lastPost.title);
cy.get(selector).should("contain", lastPost.content);
});
Then("I get redirected to {string}", route => {
cy.location("pathname").should("contain", route.replace("...", ""));
});
Then("the post was saved successfully", () => {
cy.get(".base-card > .title").should("contain", lastPost.title);
cy.get(".content").should("contain", lastPost.content);
});
Then(/^I should see only ([0-9]+) posts? on the landing page/, postCount => {
cy.get(".post-teaser").should("have.length", postCount);
});

View File

@ -1,5 +1,5 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then("I am on page {string}", page => {
cy.location("pathname").should("contain", page);
cy.location("pathname").should("contain", page.replace("...", ""));
});

View File

@ -0,0 +1,8 @@
import { Given } from "cypress-cucumber-preprocessor/steps";
Given("I navigate to page {string}", page => {
if (page === "landing") {
page = "";
}
cy.visit(`/${page}`);
});

View File

@ -0,0 +1,5 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I wait for {int} milliseconds", time => {
cy.wait(time)
});

View File

@ -17,8 +17,6 @@ Feature: Notification for a mention
Big shout to our fellow contributor
"""
And mention "@matt-rider" in the text
And I select a category
And I choose "en" as the language for the post
And I click on "Save"
And I log in as "Matt Rider"
And see 1 unread notifications in the top menu

View File

@ -18,11 +18,24 @@ const dotenv = require('dotenv')
// Import backend .env (smart)?
const { parsed } = dotenv.config({ path: require.resolve('../../backend/.env') })
// Test persistent(between commands) store
const testStore = {}
module.exports = (on, config) => {
config.env.NEO4J_URI = parsed.NEO4J_URI
config.env.NEO4J_USERNAME = parsed.NEO4J_USERNAME
config.env.NEO4J_PASSWORD = parsed.NEO4J_PASSWORD
config.env.JWT_SECRET = parsed.JWT_SECRET
on('file:preprocessor', cucumber())
on('task', {
pushValue({ name, value }) {
testStore[name] = value
return true
},
getValue(name) {
console.log("getValue",name,testStore)
return testStore[name]
},
})
return config
}
}

View File

@ -54,7 +54,6 @@ Cypress.Commands.add("switchLanguage", (name, force) => {
Cypress.Commands.add("login", user => {
const token = encode(user)
cy.setCookie('ocelot-social-token', token)
.visit("/")
});
/*Cypress.Commands.add("manualLogin", ({ email, password }) => {
@ -75,13 +74,6 @@ Cypress.Commands.add("logout", () => {
cy.location("pathname").should("contain", "/login"); // we're out
});
Cypress.Commands.add("openPage", page => {
if (page === "landing") {
page = "";
}
cy.visit(`/${page}`);
});
Cypress.Commands.add(
'authenticateAs',
({email, password}) => {