From f0a112ec1c0e25e860e19d6f7da5ec3b4f50a531 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 10 Apr 2021 21:52:12 +0200 Subject: [PATCH] post.comment feature registration.todo lots of unifications --- .../.Comment.feature => Post.Comment.feature} | 34 ++++++------- .../Post.Comment/I_comment_the_following.js | 7 +++ ...ee_an_abbreviated_version_of_my_comment.js | 6 +++ .../Post.Comment/I_should_see_my_comment.js | 13 +++++ ...I_should_see_the_entirety_of_my_comment.js | 6 +++ ...type_in_a_comment_with_{int}_characters.js | 9 ++++ ...uld_create_a_mention_in_the_CommentForm.js | 7 +++ ..._comment_should_be_successfully_created.js | 5 ++ .../the_editor_should_be_cleared.js | 5 ++ cypress/integration/Post.feature | 6 ++- .../Post/I_previously_created_a_post.js | 14 ------ ...p_on_the_landing_page_at_position_{int}.js | 9 ++-- cypress/integration/Registration.todo | 0 cypress/integration/common/.post.js | 49 ------------------- cypress/integration/common/.steps.js | 10 ---- .../I_choose_the_following_text_as_content.js | 0 .../integration/common/I_click_on_{string}.js | 4 +- ..._following_{string}_are_in_the_database.js | 27 ++++++++++ 18 files changed, 113 insertions(+), 98 deletions(-) rename cypress/integration/{post/.Comment.feature => Post.Comment.feature} (61%) create mode 100644 cypress/integration/Post.Comment/I_comment_the_following.js create mode 100644 cypress/integration/Post.Comment/I_should_see_an_abbreviated_version_of_my_comment.js create mode 100644 cypress/integration/Post.Comment/I_should_see_my_comment.js create mode 100644 cypress/integration/Post.Comment/I_should_see_the_entirety_of_my_comment.js create mode 100644 cypress/integration/Post.Comment/I_type_in_a_comment_with_{int}_characters.js create mode 100644 cypress/integration/Post.Comment/it_should_create_a_mention_in_the_CommentForm.js create mode 100644 cypress/integration/Post.Comment/my_comment_should_be_successfully_created.js create mode 100644 cypress/integration/Post.Comment/the_editor_should_be_cleared.js delete mode 100644 cypress/integration/Post/I_previously_created_a_post.js create mode 100644 cypress/integration/Registration.todo rename cypress/integration/{Post.Create => common}/I_choose_the_following_text_as_content.js (100%) create mode 100644 cypress/integration/common/the_following_{string}_are_in_the_database.js diff --git a/cypress/integration/post/.Comment.feature b/cypress/integration/Post.Comment.feature similarity index 61% rename from cypress/integration/post/.Comment.feature rename to cypress/integration/Post.Comment.feature index da261726b..adfc9f358 100644 --- a/cypress/integration/post/.Comment.feature +++ b/cypress/integration/Post.Comment.feature @@ -1,46 +1,46 @@ -Feature: Post Comment +Feature: Comments on post As a user - I want to comment on contributions of others + I want to comment and see comments on contributions of others To be able to express my thoughts and emotions about these, discuss, and add give further information. Background: - Given I have a user account - And we have the following posts in our database: + Given I have an user account + And I am logged in + And the following "posts" are in the database: | id | title | slug | authorId | | bWBjpkTKZp | 101 Essays that will change the way you think | 101-essays | id-of-peter-pan | - And we have the following comments in our database: + And the following "comments" are in the database: | postId | content | authorId | | bWBjpkTKZp | @peter-pan reply to me | id-of-peter-pan | - And I am logged in Scenario: Comment creation - Given I visit "post/bWBjpkTKZp/101-essays" - And I type in the following text: + Given I navigate to page "post/bWBjpkTKZp/101-essays" + And I comment the following: """ - Human Connection rocks + Ocelot.social rocks """ - And I click on the "Comment" button + And I click on "comment button" Then my comment should be successfully created And I should see my comment And the editor should be cleared Scenario: View medium length comments - Given I visit "post/bWBjpkTKZp/101-essays" + Given I navigate to page "post/bWBjpkTKZp/101-essays" And I type in a comment with 305 characters - And I click on the "Comment" button + And I click on "comment button" Then my comment should be successfully created And I should see the entirety of my comment And the editor should be cleared Scenario: View long comments - Given I visit "post/bWBjpkTKZp/101-essays" + Given I navigate to page "post/bWBjpkTKZp/101-essays" And I type in a comment with 1205 characters - And I click on the "Comment" button + And I click on "comment button" Then my comment should be successfully created - And I should see an abreviated version of my comment + And I should see an abbreviated version of my comment And the editor should be cleared Scenario: Direct reply to Comment - Given I visit "post/bWBjpkTKZp/101-essays" - And I click on the reply button + Given I navigate to page "post/bWBjpkTKZp/101-essays" + And I click on "reply button" Then it should create a mention in the CommentForm diff --git a/cypress/integration/Post.Comment/I_comment_the_following.js b/cypress/integration/Post.Comment/I_comment_the_following.js new file mode 100644 index 000000000..0f5a5049c --- /dev/null +++ b/cypress/integration/Post.Comment/I_comment_the_following.js @@ -0,0 +1,7 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I comment the following:", async text => { + const comment = text.replace("\n", " ") + cy.task('pushValue', { name: 'lastComment', value: comment }) + cy.get(".editor .ProseMirror").type(comment); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/I_should_see_an_abbreviated_version_of_my_comment.js b/cypress/integration/Post.Comment/I_should_see_an_abbreviated_version_of_my_comment.js new file mode 100644 index 000000000..d0b7940f0 --- /dev/null +++ b/cypress/integration/Post.Comment/I_should_see_an_abbreviated_version_of_my_comment.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see an abbreviated version of my comment", () => { + cy.get("article.comment-card") + .should("contain", "show more") +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/I_should_see_my_comment.js b/cypress/integration/Post.Comment/I_should_see_my_comment.js new file mode 100644 index 000000000..356593f9c --- /dev/null +++ b/cypress/integration/Post.Comment/I_should_see_my_comment.js @@ -0,0 +1,13 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see my comment", () => { + cy.get("article.comment-card p") + .should("contain", "Ocelot.social rocks") + .get(".user-teaser span.slug") + .should("contain", "@peter-pan") // specific enough + .get(".user-avatar img") + .should("have.attr", "src") + .and("contain", 'https://') // some url + .get(".user-teaser > .info > .text") + .should("contain", "today at"); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/I_should_see_the_entirety_of_my_comment.js b/cypress/integration/Post.Comment/I_should_see_the_entirety_of_my_comment.js new file mode 100644 index 000000000..a903fa4d0 --- /dev/null +++ b/cypress/integration/Post.Comment/I_should_see_the_entirety_of_my_comment.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see the entirety of my comment", () => { + cy.get("article.comment-card") + .should("not.contain", "show more") +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/I_type_in_a_comment_with_{int}_characters.js b/cypress/integration/Post.Comment/I_type_in_a_comment_with_{int}_characters.js new file mode 100644 index 000000000..1522c0e64 --- /dev/null +++ b/cypress/integration/Post.Comment/I_type_in_a_comment_with_{int}_characters.js @@ -0,0 +1,9 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I type in a comment with {int} characters", size => { + var c=""; + for (var i = 0; i < size; i++) { + c += "c" + } + cy.get(".editor .ProseMirror").type(c); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/it_should_create_a_mention_in_the_CommentForm.js b/cypress/integration/Post.Comment/it_should_create_a_mention_in_the_CommentForm.js new file mode 100644 index 000000000..3468badad --- /dev/null +++ b/cypress/integration/Post.Comment/it_should_create_a_mention_in_the_CommentForm.js @@ -0,0 +1,7 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("it should create a mention in the CommentForm", () => { + cy.get(".ProseMirror a") + .should('have.class', 'mention') + .should('contain', '@peter-pan') +}) \ No newline at end of file diff --git a/cypress/integration/Post.Comment/my_comment_should_be_successfully_created.js b/cypress/integration/Post.Comment/my_comment_should_be_successfully_created.js new file mode 100644 index 000000000..766106ddf --- /dev/null +++ b/cypress/integration/Post.Comment/my_comment_should_be_successfully_created.js @@ -0,0 +1,5 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("my comment should be successfully created", () => { + cy.get(".iziToast-message").contains("Comment submitted!"); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Comment/the_editor_should_be_cleared.js b/cypress/integration/Post.Comment/the_editor_should_be_cleared.js new file mode 100644 index 000000000..579fc2ca9 --- /dev/null +++ b/cypress/integration/Post.Comment/the_editor_should_be_cleared.js @@ -0,0 +1,5 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the editor should be cleared", () => { + cy.get(".ProseMirror p").should("have.class", "is-empty"); +}); \ No newline at end of file diff --git a/cypress/integration/Post.feature b/cypress/integration/Post.feature index 3f3879949..bec4b67c7 100644 --- a/cypress/integration/Post.feature +++ b/cypress/integration/Post.feature @@ -1,4 +1,4 @@ -Feature: Create a post +Feature: See a post As an logged in user I would like to see a post And to see the whole content of it @@ -6,7 +6,9 @@ Feature: Create a post Background: Given I have an user account And I am logged in - And I previously created a post + And the following "posts" are in the database: + | id | title | slug | authorId | content | + | aBcDeFgHiJ | previously created post | previously-created-post | id-of-peter-pan | with some content | Scenario: See a post on the landing page When I navigate to page "landing" diff --git a/cypress/integration/Post/I_previously_created_a_post.js b/cypress/integration/Post/I_previously_created_a_post.js deleted file mode 100644 index a10e98758..000000000 --- a/cypress/integration/Post/I_previously_created_a_post.js +++ /dev/null @@ -1,14 +0,0 @@ -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/the_post_shows_up_on_the_landing_page_at_position_{int}.js b/cypress/integration/Post/the_post_shows_up_on_the_landing_page_at_position_{int}.js index a1571717d..070d23905 100644 --- a/cypress/integration/Post/the_post_shows_up_on_the_landing_page_at_position_{int}.js +++ b/cypress/integration/Post/the_post_shows_up_on_the_landing_page_at_position_{int}.js @@ -1,9 +1,8 @@ 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); - }) + const selector = `.post-teaser:nth-child(${index}) > .base-card`; + cy.get(selector).should("contain", 'previously created post'); + cy.get(selector).should("contain", 'with some content'); + }); \ No newline at end of file diff --git a/cypress/integration/Registration.todo b/cypress/integration/Registration.todo new file mode 100644 index 000000000..e69de29bb diff --git a/cypress/integration/common/.post.js b/cypress/integration/common/.post.js index cba238a63..a759e5c9c 100644 --- a/cypress/integration/common/.post.js +++ b/cypress/integration/common/.post.js @@ -4,61 +4,12 @@ import orderBy from 'lodash/orderBy' const languages = orderBy(locales, 'name') -When("I type in a comment with {int} characters", size => { - var c=""; - for (var i = 0; i < size; i++) { - c += "c" - } - cy.get(".editor .ProseMirror").type(c); -}); - Then("I click on the {string} button", text => { cy.get("button") .contains(text) .click(); }); -Then("I click on the reply button", () => { - cy.get(".reply-button") - .click(); -}); - -Then("my comment should be successfully created", () => { - cy.get(".iziToast-message").contains("Comment submitted!"); -}); - -Then("I should see my comment", () => { - cy.get("article.comment-card p") - .should("contain", "Human Connection rocks") - .get(".user-teaser span.slug") - .should("contain", "@peter-pan") // specific enough - .get(".user-avatar img") - .should("have.attr", "src") - .and("contain", 'https://') // some url - .get(".user-teaser > .info > .text") - .should("contain", "today at"); -}); - -Then("I should see the entirety of my comment", () => { - cy.get("article.comment-card") - .should("not.contain", "show more") -}); - -Then("I should see an abreviated version of my comment", () => { - cy.get("article.comment-card") - .should("contain", "show more") -}); - -Then("the editor should be cleared", () => { - cy.get(".ProseMirror p").should("have.class", "is-empty"); -}); - -Then("it should create a mention in the CommentForm", () => { - cy.get(".ProseMirror a") - .should('have.class', 'mention') - .should('contain', '@peter-pan') -}) - When("I open the content menu of post {string}", (title)=> { cy.contains('.post-teaser', title) .find('.content-menu .base-button') diff --git a/cypress/integration/common/.steps.js b/cypress/integration/common/.steps.js index 3ae8fbbe8..9b1c9a6d0 100644 --- a/cypress/integration/common/.steps.js +++ b/cypress/integration/common/.steps.js @@ -153,16 +153,6 @@ When("I press {string}", label => { cy.contains(label).click(); }); -Given("we have the following comments in our database:", table => { - table.hashes().forEach((attributesOrOptions, i) => { - cy.factory().build("comment", { - ...attributesOrOptions, - }, { - ...attributesOrOptions, - }); - }) -}); - Given("we have the following posts in our database:", table => { table.hashes().forEach((attributesOrOptions, i) => { cy.factory().build("post", { diff --git a/cypress/integration/Post.Create/I_choose_the_following_text_as_content.js b/cypress/integration/common/I_choose_the_following_text_as_content.js similarity index 100% rename from cypress/integration/Post.Create/I_choose_the_following_text_as_content.js rename to cypress/integration/common/I_choose_the_following_text_as_content.js diff --git a/cypress/integration/common/I_click_on_{string}.js b/cypress/integration/common/I_click_on_{string}.js index b08399a41..50e864c29 100644 --- a/cypress/integration/common/I_click_on_{string}.js +++ b/cypress/integration/common/I_click_on_{string}.js @@ -5,7 +5,9 @@ When("I click on {string}", element => { 'submit button': 'button[name=submit]', 'create post button': '.post-add-button', 'save button': 'button[type=submit]', - 'the first post': '.post-teaser:nth-child(1)', + 'the first post': '.post-teaser:first-child', + 'comment button': 'button[type=submit]', + 'reply button': '.reply-button', } cy.get(elementSelectors[element]) diff --git a/cypress/integration/common/the_following_{string}_are_in_the_database.js b/cypress/integration/common/the_following_{string}_are_in_the_database.js new file mode 100644 index 000000000..1e1abbbf3 --- /dev/null +++ b/cypress/integration/common/the_following_{string}_are_in_the_database.js @@ -0,0 +1,27 @@ +import { Given } from "cypress-cucumber-preprocessor/steps"; + +Given("the following {string} are in the database:", (table,data) => { + switch(table){ + case "posts": + data.hashes().forEach((attributesOrOptions, i) => { + cy.factory().build("post", { + ...attributesOrOptions, + deleted: Boolean(attributesOrOptions.deleted), + disabled: Boolean(attributesOrOptions.disabled), + pinned: Boolean(attributesOrOptions.pinned), + }, { + ...attributesOrOptions, + }); + }) + break + case "comments": + data.hashes().forEach((attributesOrOptions, i) => { + cy.factory().build("comment", { + ...attributesOrOptions, + }, { + ...attributesOrOptions, + }); + }) + break + } +}) \ No newline at end of file