diff --git a/cypress/integration/Admin.PinPost.feature b/cypress/integration/Admin.PinPost.feature new file mode 100644 index 000000000..a5297d894 --- /dev/null +++ b/cypress/integration/Admin.PinPost.feature @@ -0,0 +1,43 @@ +Feature: Admin pins a post + As an admin + I want to pin a post so that it always appears at the top + In order to make sure all network users read it + e.g. notify people about security incidents, maintenance downtimes + + Background: + Given the following "users" are in the database: + | slug | email | password | id | name | role | termsAndConditionsAgreedVersion | + | user | user@example.org | abcd | user | User-Chad | user | 0.0.4 | + | admin | admin@example.org | 1234 | admin | Admin-Man | admin | 0.0.4 | + Given the following "posts" are in the database: + | id | title | pinned | createdAt | + | p1 | Some other post | | 2020-01-21 | + | p2 | Houston we have a problem | x | 2020-01-20 | + | p3 | Yet another post | | 2020-01-19 | + + Scenario: Pinned post always appears on the top of the newsfeed + When I am logged in as "user" + And I navigate to page "/" + Then the first post on the newsfeed has the title: + """ + Houston we have a problem + """ + And the post with title "Houston we have a problem" has a ribbon for pinned posts + + Scenario: Ordinary users cannot pin a post + When I am logged in as "user" + And I navigate to page "/" + And I open the content menu of post "Yet another post" + Then there is no button to pin a post + + Scenario: Admins are allowed to pin a post + When I am logged in as "admin" + And I navigate to page "/" + And I open the content menu of post "Yet another post" + And I click on "pin post" + Then I see a toaster with "Post pinned successfully" + And the first post on the newsfeed has the title: + """ + Yet another post + """ + And the post with title "Yet another post" has a ribbon for pinned posts diff --git a/cypress/integration/Admin.PinPost/I_open_the_content_menu_of_post_{string}.js b/cypress/integration/Admin.PinPost/I_open_the_content_menu_of_post_{string}.js new file mode 100644 index 000000000..78e9ab1ea --- /dev/null +++ b/cypress/integration/Admin.PinPost/I_open_the_content_menu_of_post_{string}.js @@ -0,0 +1,7 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I open the content menu of post {string}", (title)=> { + cy.contains('.post-teaser', title) + .find('.content-menu .base-button') + .click() +}) \ No newline at end of file diff --git a/cypress/integration/Admin.PinPost/the_first_post_on_the_newsfeed_has_the_title.js b/cypress/integration/Admin.PinPost/the_first_post_on_the_newsfeed_has_the_title.js new file mode 100644 index 000000000..afe370e90 --- /dev/null +++ b/cypress/integration/Admin.PinPost/the_first_post_on_the_newsfeed_has_the_title.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the first post on the newsfeed has the title:", title => { + cy.get(".post-teaser:first") + .should("contain", title); +}); \ No newline at end of file diff --git a/cypress/integration/Admin.PinPost/the_post_with_title_{string}_has_a_ribbon_for_pinned_posts.js b/cypress/integration/Admin.PinPost/the_post_with_title_{string}_has_a_ribbon_for_pinned_posts.js new file mode 100644 index 000000000..1db51d2b0 --- /dev/null +++ b/cypress/integration/Admin.PinPost/the_post_with_title_{string}_has_a_ribbon_for_pinned_posts.js @@ -0,0 +1,9 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the post with title {string} has a ribbon for pinned posts", (title) => { + cy.get(".post-teaser").contains(title) + .parent() + .parent() + .find(".ribbon.--pinned") + .should("contain", "Announcement") +}) \ No newline at end of file diff --git a/cypress/integration/Admin.PinPost/there_is_no_button_to_pin_a_post.js b/cypress/integration/Admin.PinPost/there_is_no_button_to_pin_a_post.js new file mode 100644 index 000000000..859b9faf1 --- /dev/null +++ b/cypress/integration/Admin.PinPost/there_is_no_button_to_pin_a_post.js @@ -0,0 +1,7 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("there is no button to pin a post", () => { + cy.get("a.ds-menu-item-link") + .should('contain', "Report Post") // sanity check + .should('not.contain', "Pin post") +}) \ No newline at end of file diff --git a/cypress/integration/common/.post.js b/cypress/integration/common/.post.js index 6beaf7e96..41c098890 100644 --- a/cypress/integration/common/.post.js +++ b/cypress/integration/common/.post.js @@ -10,31 +10,11 @@ Then("I click on the {string} button", text => { .click(); }); -When("I open the content menu of post {string}", (title)=> { - cy.contains('.post-teaser', title) - .find('.content-menu .base-button') - .click() -}) - When("I click on 'Pin post'", (string)=> { cy.get("a.ds-menu-item-link").contains("Pin post") .click() }) -Then("there is no button to pin a post", () => { - cy.get("a.ds-menu-item-link") - .should('contain', "Report Post") // sanity check - .should('not.contain', "Pin post") -}) - -And("the post with title {string} has a ribbon for pinned posts", (title) => { - cy.get(".post-teaser").contains(title) - .parent() - .parent() - .find(".ribbon.--pinned") - .should("contain", "Announcement") -}) - /* Then('confirm crop', () => { cy.get('.crop-confirm') .click() diff --git a/cypress/integration/common/.steps.js b/cypress/integration/common/.steps.js index 541c5f04c..e5a4cf6b4 100644 --- a/cypress/integration/common/.steps.js +++ b/cypress/integration/common/.steps.js @@ -165,10 +165,6 @@ Then(/^I should see only ([0-9]+) posts? on the newsfeed/, postCount => { cy.get(".post-teaser").should("have.length", postCount); }); -Then("the first post on the newsfeed has the title:", title => { - cy.get(".post-teaser:first").should("contain", title); -}); - Then( "the page {string} returns a 404 error with a message:", (route, message) => { diff --git a/cypress/integration/common/I_click_on_{string}.js b/cypress/integration/common/I_click_on_{string}.js index a1cd16bd6..275b5febf 100644 --- a/cypress/integration/common/I_click_on_{string}.js +++ b/cypress/integration/common/I_click_on_{string}.js @@ -9,6 +9,7 @@ When("I click on {string}", element => { 'comment button': 'button[type=submit]', 'reply button': '.reply-button', 'security menu': 'a[href="/settings/security"]', + 'pin post': '.ds-menu-item:first-child', } cy.get(elementSelectors[element]) diff --git a/cypress/integration/Post.Images/I_see_a_toaster_with_{string}.js b/cypress/integration/common/I_see_a_toaster_with_{string}.js similarity index 100% rename from cypress/integration/Post.Images/I_see_a_toaster_with_{string}.js rename to cypress/integration/common/I_see_a_toaster_with_{string}.js diff --git a/cypress/integration/moderation/.HidePosts.feature b/cypress/integration/moderation/.HidePosts.feature index bb82c7188..cb748062f 100644 --- a/cypress/integration/moderation/.HidePosts.feature +++ b/cypress/integration/moderation/.HidePosts.feature @@ -10,10 +10,10 @@ Feature: Hide Posts | p2 | This post is disabled | | x | | p3 | This post is deleted | x | | - Scenario: Disabled posts don't show up on the landing page + Scenario: Disabled posts don't show up on the newsfeed Given I am logged in with a "user" role - Then I should see only 1 post on the landing page - And the first post on the landing page has the title: + Then I should see only 1 post on the newsfeed + And the first post on the newsfeed has the title: """ This post should be visible """