diff --git a/cypress/integration/administration/TagsAndCategories.feature b/cypress/integration/administration/TagsAndCategories.feature index 7d0adb6a9..f93cdb59c 100644 --- a/cypress/integration/administration/TagsAndCategories.feature +++ b/cypress/integration/administration/TagsAndCategories.feature @@ -15,9 +15,7 @@ Feature: Tags and Categories Background: Given my user account has the role "admin" - And we have a selection of categories - And we have a selection of tags - And we have a selection of posts + And we have a selection of tags and categories as well as posts And I am logged in Scenario: See an overview of categories diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 190184bd8..1c87240b6 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -20,37 +20,18 @@ const narratorParams = { Given("I am logged in", () => { cy.login(loginCredentials); }); + Given("we have a selection of categories", () => { - cy.neode() - .create("Category", { - id: "cat1", - name: "Just For Fun", - slug: "just-for-fun", - icon: "smile" - }) - .create("Category", { - id: "cat2", - name: "Happiness & Values", - slug: "happiness-values", - icon: "heart-o" - }) - .create("Category", { - id: "cat3", - name: "Health & Wellbeing", - slug: "health-wellbeing", - icon: "medkit" - }); + cy.createCategories(); }); -Given("we have a selection of tags", () => { - cy.factory() +Given("we have a selection of tags and categories as well as posts", () => { + cy.createCategories() + .factory() .authenticateAs(loginCredentials) .create("Tag", { id: "Ecology" }) .create("Tag", { id: "Nature" }) .create("Tag", { id: "Democracy" }); -}); - -Given("we have a selection of posts", () => { const someAuthor = { id: "authorId", email: "author@example.org", @@ -436,7 +417,8 @@ Given("I follow the user {string}", name => { }); Given('"Spammy Spammer" wrote a post {string}', title => { - cy.factory() + cy.createCategories() + .factory() .authenticateAs({ email: "spammy-spammer@example.org", password: "1234" @@ -458,7 +440,8 @@ Then("nobody is following the user profile anymore", () => { }); Given("I wrote a post {string}", title => { - cy.factory() + cy.createCategories() + .factory() .authenticateAs(loginCredentials) .create("Post", { title, categoryIds: ["cat2"] }); }); diff --git a/cypress/integration/notifications/Mentions.feature b/cypress/integration/notifications/Mentions.feature index d3bcb574d..d3c123863 100644 --- a/cypress/integration/notifications/Mentions.feature +++ b/cypress/integration/notifications/Mentions.feature @@ -5,7 +5,7 @@ Feature: Notifications for a mentions Background: Given we have a selection of categories - Given we have the following user accounts: + And we have the following user accounts: | name | slug | email | password | | Wolle aus Hamburg | wolle-aus-hamburg | wolle@example.org | 1234 | | Matt Rider | matt-rider | matt@example.org | 4321 | diff --git a/cypress/integration/user_profile/blocked-users/Content.feature b/cypress/integration/user_profile/blocked-users/Content.feature index 00c2abc21..edc0d63b9 100644 --- a/cypress/integration/user_profile/blocked-users/Content.feature +++ b/cypress/integration/user_profile/blocked-users/Content.feature @@ -5,7 +5,6 @@ Feature: Block a User Background: Given I have a user account - And we have a selection of categories And there is an annoying user called "Spammy Spammer" Scenario Outline: Blocked users cannot see each others posts diff --git a/cypress/support/commands.js b/cypress/support/commands.js index f6253af20..0601fa137 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -13,55 +13,76 @@ // Cypress.Commands.add('login', (email, password) => { ... }) /* globals Cypress cy */ -import 'cypress-file-upload' -import { getLangByName } from './helpers' -import users from '../fixtures/users.json' +import "cypress-file-upload"; +import { getLangByName } from "./helpers"; +import users from "../fixtures/users.json"; const switchLang = name => { - cy.get('.locale-menu').click() - cy.contains('.locale-menu-popover a', name).click() -} + cy.get(".locale-menu").click(); + cy.contains(".locale-menu-popover a", name).click(); +}; -Cypress.Commands.add('switchLanguage', (name, force) => { - const code = getLangByName(name).code +Cypress.Commands.add("switchLanguage", (name, force) => { + const code = getLangByName(name).code; if (force) { - switchLang(name) + switchLang(name); } else { - cy.get('html').then($html => { - if ($html && $html.attr('lang') !== code) { - switchLang(name) + cy.get("html").then($html => { + if ($html && $html.attr("lang") !== code) { + switchLang(name); } + }); + } +}); + +Cypress.Commands.add("login", ({ email, password }) => { + cy.visit(`/login`); + cy.get("input[name=email]") + .trigger("focus") + .type(email); + cy.get("input[name=password]") + .trigger("focus") + .type(password); + cy.get("button[name=submit]") + .as("submitButton") + .click(); + cy.get(".iziToast-message").should("contain", "You are logged in!"); + cy.get(".iziToast-close").click(); +}); + +Cypress.Commands.add("logout", (email, password) => { + cy.visit(`/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("createCategories", () => { + cy.neode() + .create("Category", { + id: "cat1", + name: "Just For Fun", + slug: "just-for-fun", + icon: "smile" }) - } -}) - -Cypress.Commands.add('login', ({ email, password }) => { - cy.visit(`/login`) - cy.get('input[name=email]') - .trigger('focus') - .type(email) - cy.get('input[name=password]') - .trigger('focus') - .type(password) - cy.get('button[name=submit]') - .as('submitButton') - .click() - cy.get('.iziToast-message').should('contain', 'You are logged in!') - cy.get('.iziToast-close').click() -}) - -Cypress.Commands.add('logout', (email, password) => { - cy.visit(`/logout`) - cy.location('pathname').should('contain', '/login') // we're out -}) - -Cypress.Commands.add('openPage', page => { - if (page === 'landing') { - page = '' - } - cy.visit(`/${page}`) -}) - + .create("Category", { + id: "cat2", + name: "Happiness & Values", + slug: "happiness-values", + icon: "heart-o" + }) + .create("Category", { + id: "cat3", + name: "Health & Wellbeing", + slug: "health-wellbeing", + icon: "medkit" + }); +}); // // // -- This is a child command --