diff --git a/cypress/integration/Authentication.feature b/cypress/integration/Authentication.feature index 86439d332..ea8807d35 100644 --- a/cypress/integration/Authentication.feature +++ b/cypress/integration/Authentication.feature @@ -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" diff --git a/cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js b/cypress/integration/Authentication/I_am_logged_in_as_{string}.js similarity index 100% rename from cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js rename to cypress/integration/Authentication/I_am_logged_in_as_{string}.js diff --git a/cypress/integration/Authentication/when_I_click_submit.js b/cypress/integration/Authentication/I_click_submit.js similarity index 100% rename from cypress/integration/Authentication/when_I_click_submit.js rename to cypress/integration/Authentication/I_click_submit.js diff --git a/cypress/integration/Authentication/when_I_fill_in_my_credentials.js b/cypress/integration/Authentication/I_fill_in_my_credentials.js similarity index 100% rename from cypress/integration/Authentication/when_I_fill_in_my_credentials.js rename to cypress/integration/Authentication/I_fill_in_my_credentials.js diff --git a/cypress/integration/Authentication/when_I_log_out.js b/cypress/integration/Authentication/I_log_out.js similarity index 100% rename from cypress/integration/Authentication/when_I_log_out.js rename to cypress/integration/Authentication/I_log_out.js diff --git a/cypress/integration/Authentication/when_I_refresh_the_page.js b/cypress/integration/Authentication/I_refresh_the_page.js similarity index 100% rename from cypress/integration/Authentication/when_I_refresh_the_page.js rename to cypress/integration/Authentication/I_refresh_the_page.js diff --git a/cypress/integration/Authentication/when_I_visit_the_{string}_page.js b/cypress/integration/Authentication/when_I_visit_the_{string}_page.js deleted file mode 100644 index 336d14b15..000000000 --- a/cypress/integration/Authentication/when_I_visit_the_{string}_page.js +++ /dev/null @@ -1,5 +0,0 @@ -import { When } from "cypress-cucumber-preprocessor/steps"; - -When("I visit the {string} page", page => { - cy.openPage(page); -}); \ No newline at end of file diff --git a/cypress/integration/Post.Create.feature b/cypress/integration/Post.Create.feature new file mode 100644 index 000000000..e9cd8b01a --- /dev/null +++ b/cypress/integration/Post.Create.feature @@ -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 diff --git a/cypress/integration/Post.Create/I_choose_the_following_text_as_content.js b/cypress/integration/Post.Create/I_choose_the_following_text_as_content.js new file mode 100644 index 000000000..62b5426d5 --- /dev/null +++ b/cypress/integration/Post.Create/I_choose_the_following_text_as_content.js @@ -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); + }) +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create/I_choose_{string}_as_the_title.js b/cypress/integration/Post.Create/I_choose_{string}_as_the_title.js new file mode 100644 index 000000000..9fbf8e58f --- /dev/null +++ b/cypress/integration/Post.Create/I_choose_{string}_as_the_title.js @@ -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); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create/I_click_on_create_post.js b/cypress/integration/Post.Create/I_click_on_create_post.js new file mode 100644 index 000000000..7624acf5a --- /dev/null +++ b/cypress/integration/Post.Create/I_click_on_create_post.js @@ -0,0 +1,5 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I click on create post", () => { + cy.get(".post-add-button").click(); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create/I_click_on_{string}.js b/cypress/integration/Post.Create/I_click_on_{string}.js new file mode 100644 index 000000000..1a58cf13f --- /dev/null +++ b/cypress/integration/Post.Create/I_click_on_{string}.js @@ -0,0 +1,6 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When(`I click on {string}`, text => { + cy.contains(text) + .click() +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create/I_previously_created_a_post.js b/cypress/integration/Post.Create/I_previously_created_a_post.js new file mode 100644 index 000000000..a10e98758 --- /dev/null +++ b/cypress/integration/Post.Create/I_previously_created_a_post.js @@ -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 }) + }); \ No newline at end of file diff --git a/cypress/integration/Post.Create/the_post_shows_up_on_the_landing_page_at_position_{int}.js b/cypress/integration/Post.Create/the_post_shows_up_on_the_landing_page_at_position_{int}.js new file mode 100644 index 000000000..a1571717d --- /dev/null +++ b/cypress/integration/Post.Create/the_post_shows_up_on_the_landing_page_at_position_{int}.js @@ -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); + }) +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create/the_post_was_saved_successfully.js b/cypress/integration/Post.Create/the_post_was_saved_successfully.js new file mode 100644 index 000000000..eec2f819b --- /dev/null +++ b/cypress/integration/Post.Create/the_post_was_saved_successfully.js @@ -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); + }) +}); \ No newline at end of file diff --git a/cypress/integration/TermsAndConditions.todo b/cypress/integration/TermsAndConditions.todo new file mode 100644 index 000000000..e69de29bb diff --git a/cypress/integration/common/.steps.js b/cypress/integration/common/.steps.js index 0ca6ff438..3ae8fbbe8 100644 --- a/cypress/integration/common/.steps.js +++ b/cypress/integration/common/.steps.js @@ -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); }); diff --git a/cypress/integration/Authentication/given_I_am_logged_in.js b/cypress/integration/common/I_am_logged_in.js similarity index 100% rename from cypress/integration/Authentication/given_I_am_logged_in.js rename to cypress/integration/common/I_am_logged_in.js diff --git a/cypress/integration/Authentication/then_I_am_on_page_{string}.js b/cypress/integration/common/I_am_on_page_{string}.js similarity index 59% rename from cypress/integration/Authentication/then_I_am_on_page_{string}.js rename to cypress/integration/common/I_am_on_page_{string}.js index 219e181b7..8fe06d7b9 100644 --- a/cypress/integration/Authentication/then_I_am_on_page_{string}.js +++ b/cypress/integration/common/I_am_on_page_{string}.js @@ -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("...", "")); }); \ No newline at end of file diff --git a/cypress/integration/Authentication/given_I_have_an_user_account.js b/cypress/integration/common/I_have_an_user_account.js similarity index 100% rename from cypress/integration/Authentication/given_I_have_an_user_account.js rename to cypress/integration/common/I_have_an_user_account.js diff --git a/cypress/integration/common/I_navigate_to_page_{string}.js b/cypress/integration/common/I_navigate_to_page_{string}.js new file mode 100644 index 000000000..f0ecb2065 --- /dev/null +++ b/cypress/integration/common/I_navigate_to_page_{string}.js @@ -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}`); +}); \ No newline at end of file diff --git a/cypress/integration/common/I_wait_for_{int}_milliseconds.js b/cypress/integration/common/I_wait_for_{int}_milliseconds.js new file mode 100644 index 000000000..bc8ef906a --- /dev/null +++ b/cypress/integration/common/I_wait_for_{int}_milliseconds.js @@ -0,0 +1,5 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I wait for {int} milliseconds", time => { + cy.wait(time) +}); \ No newline at end of file diff --git a/cypress/integration/notifications/.Mentions.feature b/cypress/integration/notifications/.Mentions.feature index 1cf265624..d269daec5 100644 --- a/cypress/integration/notifications/.Mentions.feature +++ b/cypress/integration/notifications/.Mentions.feature @@ -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 diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 09939ef2e..4e6b440ef 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -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 -} +} \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 46099a937..a1e3ebc2a 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -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}) => {