Fixed Cypress tests

Co-Authored-By: mattwr18 <mattwr18@gmail.com>
Co-Authored-By: ogerly <fridolin@tutanota.com>
This commit is contained in:
Wolfgang Huß 2019-09-04 20:19:45 +02:00
parent b04649e1ee
commit 7bdc6b52d2

View File

@ -1,6 +1,9 @@
import { Given, When, Then } from "cypress-cucumber-preprocessor/steps"; import {
Given,
When,
Then
} from "cypress-cucumber-preprocessor/steps";
import helpers from "../../support/helpers"; import helpers from "../../support/helpers";
import slugify from "slug";
/* global cy */ /* global cy */
@ -10,19 +13,18 @@ let loginCredentials = {
email: "peterpan@example.org", email: "peterpan@example.org",
password: "1234" password: "1234"
}; };
const termsAndConditionsAgreedVersion = {
const termsAndConditionsAgreedVersion = { termsAndConditionsAgreedVersion: "0.0.2" }; termsAndConditionsAgreedVersion: "0.0.2"
};
const narratorParams = { const narratorParams = {
id: 'id-of-peter-pan', id: 'id-of-peter-pan',
name: "Peter Pan", name: "Peter Pan",
slug: "peter-pan", slug: "peter-pan",
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/nerrsoft/128.jpg", avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/nerrsoft/128.jpg",
...loginCredentials,
...termsAndConditionsAgreedVersion, ...termsAndConditionsAgreedVersion,
...loginCredentials
}; };
Given("I am logged in", () => { Given("I am logged in", () => {
cy.login(loginCredentials); cy.login(loginCredentials);
}); });
@ -34,38 +36,54 @@ Given("we have a selection of categories", () => {
Given("we have a selection of tags and categories as well as posts", () => { Given("we have a selection of tags and categories as well as posts", () => {
cy.createCategories("cat12") cy.createCategories("cat12")
.factory() .factory()
.create("Tag", { id: "Ecology" }) .create("Tag", {
.create("Tag", { id: "Nature" }) id: "Ecology"
.create("Tag", { id: "Democracy" }); })
.create("Tag", {
const someAuthor = { id: "Nature"
id: "authorId", })
email: "author@example.org", .create("Tag", {
password: "1234", id: "Democracy"
...termsAndConditionsAgreedVersion });
};
const yetAnotherAuthor = {
id: "yetAnotherAuthor",
email: "yet-another-author@example.org",
password: "1234",
...termsAndConditionsAgreedVersion
};
cy.factory() cy.factory()
.create("User", { id: 'a1' }) .create("User", {
.create("Post", {authorId: 'a1', tagIds: [ "Ecology", "Nature", "Democracy" ], categoryIds: ["cat12"] }) id: 'a1'
.create("Post", {authorId: 'a1', tagIds: [ "Nature", "Democracy" ], categoryIds: ["cat121"] }); })
.create("Post", {
authorId: 'a1',
tagIds: ["Ecology", "Nature", "Democracy"],
categoryIds: ["cat12"]
})
.create("Post", {
authorId: 'a1',
tagIds: ["Nature", "Democracy"],
categoryIds: ["cat121"]
});
cy.factory() cy.factory()
.create("User", { id: 'a2'}) .create("User", {
.create("Post", { authorId: 'a2', tagIds: ['Nature', 'Democracy'], categoryIds: ["cat12"] }); id: 'a2'
})
.create("Post", {
authorId: 'a2',
tagIds: ['Nature', 'Democracy'],
categoryIds: ["cat12"]
});
cy.factory() cy.factory()
.create("Post", { authorId: narratorParams.id, tagIds: ['Democracy'], categoryIds: ["cat122"] }) .create("Post", {
authorId: narratorParams.id,
tagIds: ['Democracy'],
categoryIds: ["cat122"]
})
}); });
Given("we have the following user accounts:", table => { Given("we have the following user accounts:", table => {
table.hashes().forEach(params => { table.hashes().forEach(params => {
cy.factory().create("User", { ...params, ...termsAndConditionsAgreedVersion }); cy.factory().create("User", {
...params,
...termsAndConditionsAgreedVersion
});
}); });
}); });
@ -76,8 +94,8 @@ Given("I have a user account", () => {
Given("my user account has the role {string}", role => { Given("my user account has the role {string}", role => {
cy.factory().create("User", { cy.factory().create("User", {
role, role,
...loginCredentials,
...termsAndConditionsAgreedVersion, ...termsAndConditionsAgreedVersion,
...loginCredentials
}); });
}); });
@ -137,7 +155,9 @@ Given("I previously switched the language to {string}", name => {
}); });
Then("the whole user interface appears in {string}", name => { Then("the whole user interface appears in {string}", name => {
const { code } = helpers.getLangByName(name); const {
code
} = helpers.getLangByName(name);
cy.get(`html[lang=${code}]`); cy.get(`html[lang=${code}]`);
cy.getCookie("locale").should("have.property", "value", code); cy.getCookie("locale").should("have.property", "value", code);
}); });
@ -164,41 +184,21 @@ Given("we have this user in our database:", table => {
}) })
Given("we have the following posts in our database:", table => { Given("we have the following posts in our database:", table => {
cy.factory().create('Category', {
id: `cat-456`,
name: "Just For Fun",
slug: `just-for-fun`,
icon: "smile"
})
table.hashes().forEach(({ Author, ...postAttributes }, i) => { table.hashes().forEach(({
Author = Author || `author-${i}`; ...postAttributes
const userAttributes = { }, i) => {
name: Author, postAttributes = {
email: `${slugify(Author, { lower: true })}@example.org`, ...postAttributes,
password: "1234", deleted: Boolean(postAttributes.deleted),
termsAndConditionsAgreedVersion: '0.0.2', disabled: Boolean(postAttributes.disabled),
}; categoryIds: ['cat-456']
postAttributes.deleted = Boolean(postAttributes.deleted);
const disabled = Boolean(postAttributes.disabled);
postAttributes.categoryIds = [`cat${i}${new Date()}`];
postAttributes;
cy.factory()
.create("User", userAttributes)
.authenticateAs(userAttributes)
.create("Category", {
id: `cat${i}${new Date()}`,
name: "Just For Fun",
slug: `just-for-fun-${i}`,
icon: "smile"
})
.create("Post", postAttributes);
if (disabled) {
const moderatorParams = {
email: "moderator@example.org",
role: "moderator",
password: "1234",
termsAndConditionsAgreedVersion: '0.0.2',
};
cy.factory()
.create("User", moderatorParams)
.authenticateAs(moderatorParams)
.mutate("mutation($id: ID!) { disable(id: $id) }", postAttributes);
} }
cy.factory().create("Post", postAttributes); cy.factory().create("Post", postAttributes);
}) })
@ -271,17 +271,26 @@ Then("the first post on the landing page has the title:", title => {
Then( Then(
"the page {string} returns a 404 error with a message:", "the page {string} returns a 404 error with a message:",
(route, message) => { (route, message) => {
cy.request({ url: route, failOnStatusCode: false }) cy.request({
url: route,
failOnStatusCode: false
})
.its("status") .its("status")
.should("eq", 404); .should("eq", 404);
cy.visit(route, { failOnStatusCode: false }); cy.visit(route, {
failOnStatusCode: false
});
cy.get(".error").should("contain", message); cy.get(".error").should("contain", message);
} }
); );
Given("my user account has the following login credentials:", table => { Given("my user account has the following login credentials:", table => {
loginCredentials = table.hashes()[0]; loginCredentials = table.hashes()[0];
cy.factory().create("User", { ...termsAndConditionsAgreedVersion, ...loginCredentials }); cy.debug();
cy.factory().create("User", {
...termsAndConditionsAgreedVersion,
...loginCredentials
});
}); });
When("I fill the password form with:", table => { When("I fill the password form with:", table => {
@ -300,7 +309,9 @@ When("submit the form", () => {
Then("I cannot login anymore with password {string}", password => { Then("I cannot login anymore with password {string}", password => {
cy.reload(); cy.reload();
const { email } = loginCredentials; const {
email
} = loginCredentials;
cy.visit(`/login`); cy.visit(`/login`);
cy.get("input[name=email]") cy.get("input[name=email]")
.trigger("focus") .trigger("focus")
@ -321,14 +332,22 @@ Then("I can login successfully with password {string}", password => {
cy.reload(); cy.reload();
cy.login({ cy.login({
...loginCredentials, ...loginCredentials,
...{ password } ...{
password
}
}); });
cy.get(".iziToast-wrapper").should("contain", "You are logged in!"); cy.get(".iziToast-wrapper").should("contain", "You are logged in!");
}); });
When("I log in with the following credentials:", table => { When("I log in with the following credentials:", table => {
const { email, password } = table.hashes()[0]; const {
cy.login({ email, password }); email,
password
} = table.hashes()[0];
cy.login({
email,
password
});
}); });
When("open the notification menu and click on the first item", () => { When("open the notification menu and click on the first item", () => {
@ -385,10 +404,7 @@ Given("there is an annoying user called {string}", name => {
...annoyingParams, ...annoyingParams,
id: "annoying-user", id: "annoying-user",
name, name,
...termsAndConditionsAgreedVersion ...termsAndConditionsAgreedVersion,
}); });
}); });
@ -410,7 +426,9 @@ When(
cy.get(".user-content-menu .content-menu-trigger").click(); cy.get(".user-content-menu .content-menu-trigger").click();
cy.get(".popover .ds-menu-item-link") cy.get(".popover .ds-menu-item-link")
.contains(button) .contains(button)
.click({ force: true }); .click({
force: true
});
} }
); );
@ -425,10 +443,14 @@ When("I navigate to my {string} settings page", settingsPage => {
Given("I follow the user {string}", name => { Given("I follow the user {string}", name => {
cy.neode() cy.neode()
.first("User", { name }) .first("User", {
name
})
.then(followed => { .then(followed => {
cy.neode() cy.neode()
.first("User", { name: narratorParams.name }) .first("User", {
name: narratorParams.name
})
.relateTo(followed, "following"); .relateTo(followed, "following");
}); });
}); });
@ -436,7 +458,11 @@ Given("I follow the user {string}", name => {
Given('"Spammy Spammer" wrote a post {string}', title => { Given('"Spammy Spammer" wrote a post {string}', title => {
cy.createCategories("cat21") cy.createCategories("cat21")
.factory() .factory()
.create("Post", { authorId: 'annoying-user', title, categoryIds: ["cat21"] }); .create("Post", {
authorId: 'annoying-user',
title,
categoryIds: ["cat21"]
});
}); });
Then("the list of posts of this user is empty", () => { Then("the list of posts of this user is empty", () => {
@ -455,23 +481,37 @@ Then("nobody is following the user profile anymore", () => {
Given("I wrote a post {string}", title => { Given("I wrote a post {string}", title => {
cy.createCategories(`cat213`, title) cy.createCategories(`cat213`, title)
.factory() .factory()
.create("Post", { authorId: narratorParams.id, title, categoryIds: ["cat213"] }); .create("Post", {
authorId: narratorParams.id,
title,
categoryIds: ["cat213"]
});
}); });
When("I block the user {string}", name => { When("I block the user {string}", name => {
cy.neode() cy.neode()
.first("User", { name }) .first("User", {
name
})
.then(blocked => { .then(blocked => {
cy.neode() cy.neode()
.first("User", { name: narratorParams.name }) .first("User", {
name: narratorParams.name
})
.relateTo(blocked, "blocked"); .relateTo(blocked, "blocked");
}); });
}); });
When("I log in with:", table => { When("I log in with:", table => {
const [firstRow] = table.hashes(); const [firstRow] = table.hashes();
const { Email, Password } = firstRow; const {
cy.login({ email: Email, password: Password }); Email,
Password
} = firstRow;
cy.login({
email: Email,
password: Password
});
}); });
Then("I see only one post with the title {string}", title => { Then("I see only one post with the title {string}", title => {
@ -479,4 +519,4 @@ Then("I see only one post with the title {string}", title => {
.find(".post-link") .find(".post-link")
.should("have.length", 1); .should("have.length", 1);
cy.get(".main-container").contains(".post-link", title); cy.get(".main-container").contains(".post-link", title);
}); });