diff --git a/cypress/integration/search/.Search.feature b/cypress/integration/Search.feature similarity index 60% rename from cypress/integration/search/.Search.feature rename to cypress/integration/Search.feature index d128838f3..b98fcbc76 100644 --- a/cypress/integration/search/.Search.feature +++ b/cypress/integration/Search.feature @@ -4,17 +4,17 @@ Feature: Search In order to find related content Background: - Given I have a user account - And we have the following posts in our database: + Given the following "users" are in the database: + | slug | email | password | id | name | termsAndConditionsAgreedVersion | + | narrator | narrator@example.org | 1234 | narrator | Nathan Narrator | 0.0.4 | + | search-for-me | u1@example.org | 1234 | user-for-search | Search for me | 0.0.4 | + | not-to-be-found | u2@example.org | 1234 | just-an-id | Not to be found | 0.0.4 | + And the following "posts" are in the database: | id | title | content | | p1 | 101 Essays that will change the way you think | 101 Essays, of course (PR)! | - | p2 | No content | will be found in this post, I guarantee | - And we have the following user accounts: - | slug | name | id | - | search-for-me | Search for me | user-for-search | - | not-to-be-found | Not to be found | just-an-id | - - Given I am logged in + | p2 | No content | will be found in this post, I guarantee | + And I am logged in as "narrator" + And I navigate to page "landing" Scenario: Search for specific words When I search for "Essays" @@ -25,10 +25,12 @@ Feature: Search Scenario: Press enter opens search page When I type "PR" and press Enter - Then I should see the search results page - Then I should see the following posts on the search results page + Then I am on page "/search/search-results" + And the search parameter equals "?search=PR" + Then I should see the following posts on the search results page: | title | | 101 Essays that will change the way you think | + And I wait for 750 milliseconds Scenario: Press escape clears search When I type "Ess" and press escape @@ -37,7 +39,7 @@ Feature: Search Scenario: Select entry goes to post When I search for "Essays" And I select a post entry - Then I should be on the post's page + Then I am on page "/post/p1/101-essays-that-will-change-the-way-you-think" Scenario: Select dropdown content When I search for "Essays" @@ -52,4 +54,4 @@ Feature: Search | slug | | search-for-me | And I select a user entry - Then I should be on the user's profile \ No newline at end of file + Then I am on page "/profile/user-for-search/search-for-me" \ No newline at end of file diff --git a/cypress/integration/Search/I_search_for_{string}.js b/cypress/integration/Search/I_search_for_{string}.js new file mode 100644 index 000000000..99e507447 --- /dev/null +++ b/cypress/integration/Search/I_search_for_{string}.js @@ -0,0 +1,7 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I search for {string}", value => { + cy.get(".searchable-input .ds-select input") + .focus() + .type(value); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_select_a_post_entry.js b/cypress/integration/Search/I_select_a_post_entry.js new file mode 100644 index 000000000..25611f91e --- /dev/null +++ b/cypress/integration/Search/I_select_a_post_entry.js @@ -0,0 +1,7 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I select a post entry", () => { + cy.get(".searchable-input .search-post") + .first() + .trigger("click"); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_select_a_user_entry.js b/cypress/integration/Search/I_select_a_user_entry.js new file mode 100644 index 000000000..b7222b2fb --- /dev/null +++ b/cypress/integration/Search/I_select_a_user_entry.js @@ -0,0 +1,7 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I select a user entry", () => { + cy.get(".searchable-input .user-teaser") + .first() + .trigger("click"); +}) \ No newline at end of file diff --git a/cypress/integration/Search/I_should_have_one_item_in_the_select_dropdown.js b/cypress/integration/Search/I_should_have_one_item_in_the_select_dropdown.js new file mode 100644 index 000000000..7e5188ab6 --- /dev/null +++ b/cypress/integration/Search/I_should_have_one_item_in_the_select_dropdown.js @@ -0,0 +1,7 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should have one item in the select dropdown", () => { + cy.get(".searchable-input .ds-select-dropdown").should($li => { + expect($li).to.have.length(1); + }); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_should_not_see_posts_without_the_searched-for_term_in_the_select_dropdown.js b/cypress/integration/Search/I_should_not_see_posts_without_the_searched-for_term_in_the_select_dropdown.js new file mode 100644 index 000000000..a76ed6a5d --- /dev/null +++ b/cypress/integration/Search/I_should_not_see_posts_without_the_searched-for_term_in_the_select_dropdown.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should not see posts without the searched-for term in the select dropdown", () => { + cy.get(".ds-select-dropdown") + .should("not.contain","No searched for content"); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_should_see_posts_with_the_searched-for_term_in_the_select_dropdown.js b/cypress/integration/Search/I_should_see_posts_with_the_searched-for_term_in_the_select_dropdown.js new file mode 100644 index 000000000..ce755abb0 --- /dev/null +++ b/cypress/integration/Search/I_should_see_posts_with_the_searched-for_term_in_the_select_dropdown.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see posts with the searched-for term in the select dropdown", () => { + cy.get(".ds-select-dropdown") + .should("contain","101 Essays that will change the way you think"); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_should_see_the_following_posts_in_the_select_dropdown.js b/cypress/integration/Search/I_should_see_the_following_posts_in_the_select_dropdown.js new file mode 100644 index 000000000..420c3376a --- /dev/null +++ b/cypress/integration/Search/I_should_see_the_following_posts_in_the_select_dropdown.js @@ -0,0 +1,8 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see the following posts in the select dropdown:", table => { + table.hashes().forEach(({ title }) => { + cy.get(".ds-select-dropdown") + .should("contain", title); + }); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_should_see_the_following_posts_on_the_search_results_page.js b/cypress/integration/Search/I_should_see_the_following_posts_on_the_search_results_page.js new file mode 100644 index 000000000..f703a04f5 --- /dev/null +++ b/cypress/integration/Search/I_should_see_the_following_posts_on_the_search_results_page.js @@ -0,0 +1,8 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see the following posts on the search results page:", table => { + table.hashes().forEach(({ title }) => { + cy.get(".post-teaser") + .should("contain",title) + }); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_should_see_the_following_users_in_the_select_dropdown.js b/cypress/integration/Search/I_should_see_the_following_users_in_the_select_dropdown.js new file mode 100644 index 000000000..3e5e14043 --- /dev/null +++ b/cypress/integration/Search/I_should_see_the_following_users_in_the_select_dropdown.js @@ -0,0 +1,8 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I should see the following users in the select dropdown:", table => { + cy.get(".search-heading").should("contain", "Users"); + table.hashes().forEach(({ slug }) => { + cy.get(".ds-select-dropdown").should("contain", slug); + }); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_type_{string}_and_press_Enter.js b/cypress/integration/Search/I_type_{string}_and_press_Enter.js new file mode 100644 index 000000000..1a0fc6d42 --- /dev/null +++ b/cypress/integration/Search/I_type_{string}_and_press_Enter.js @@ -0,0 +1,8 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I type {string} and press Enter", value => { + cy.get(".searchable-input .ds-select input") + .focus() + .type(value) + .type("{enter}", { force: true }); +}); \ No newline at end of file diff --git a/cypress/integration/Search/I_type_{string}_and_press_escape.js b/cypress/integration/Search/I_type_{string}_and_press_escape.js new file mode 100644 index 000000000..a3cde6cda --- /dev/null +++ b/cypress/integration/Search/I_type_{string}_and_press_escape.js @@ -0,0 +1,8 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I type {string} and press escape", value => { + cy.get(".searchable-input .ds-select input") + .focus() + .type(value) + .type("{esc}"); +}); \ No newline at end of file diff --git a/cypress/integration/Search/the_search_field_should_clear.js b/cypress/integration/Search/the_search_field_should_clear.js new file mode 100644 index 000000000..f571cdbd4 --- /dev/null +++ b/cypress/integration/Search/the_search_field_should_clear.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the search field should clear", () => { + cy.get(".searchable-input .ds-select input") + .should("have.text", ""); +}); \ No newline at end of file diff --git a/cypress/integration/Search/the_search_parameter_equals_{string}.js b/cypress/integration/Search/the_search_parameter_equals_{string}.js new file mode 100644 index 000000000..b8473584c --- /dev/null +++ b/cypress/integration/Search/the_search_parameter_equals_{string}.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the search parameter equals {string}", search => { + cy.location("search") + .should("eq", search); +}); \ No newline at end of file diff --git a/cypress/integration/common/.search.js b/cypress/integration/common/.search.js index 5eae20a22..387e6c9ca 100644 --- a/cypress/integration/common/.search.js +++ b/cypress/integration/common/.search.js @@ -1,15 +1,4 @@ import { When, Then } from "cypress-cucumber-preprocessor/steps"; -When("I search for {string}", value => { - cy.get(".searchable-input .ds-select input") - .focus() - .type(value); -}); - -Then("I should have one item in the select dropdown", () => { - cy.get(".searchable-input .ds-select-dropdown").should($li => { - expect($li).to.have.length(1); - }); -}); Then("the search should not contain posts by the annoying user", () => { cy.get(".searchable-input .ds-select-dropdown").should($li => { @@ -28,99 +17,4 @@ Then("the search should contain the annoying user", () => { cy.get(".searchable-input .ds-select input") .focus() .type("{esc}"); -}) - -Then("I should see the following posts in the select dropdown:", table => { - table.hashes().forEach(({ title }) => { - cy.get(".ds-select-dropdown").should("contain", title); - }); -}); - -Then("I should see the following users in the select dropdown:", table => { - cy.get(".search-heading").should("contain", "Users"); - table.hashes().forEach(({ slug }) => { - cy.get(".ds-select-dropdown").should("contain", slug); - }); -}); - -When("I type {string} and press Enter", value => { - cy.get(".searchable-input .ds-select input") - .focus() - .type(value) - .type("{enter}", { force: true }); -}); - -When("I type {string} and press escape", value => { - cy.get(".searchable-input .ds-select input") - .focus() - .type(value) - .type("{esc}"); -}); - -Then("the search field should clear", () => { - cy.get(".searchable-input .ds-select input").should("have.text", ""); -}); - -When("I select a post entry", () => { - cy.get(".searchable-input .search-post") - .first() - .trigger("click"); -}); - -Then("I should be on the post's page", () => { - cy.location("pathname").should("contain", "/post/"); - cy.location("pathname").should( - "eq", - "/post/p1/101-essays-that-will-change-the-way-you-think" - ); -}); - -Then( - "I should see posts with the searched-for term in the select dropdown", - () => { - cy.get(".ds-select-dropdown").should( - "contain", - "101 Essays that will change the way you think" - ); - } -); - -Then("I should see the search results page", () => { - cy.location("pathname").should( - "eq", - "/search/search-results" - ); - cy.location("search").should( - "eq", - "?search=PR" - ); -}); - -Then("I should see the following posts on the search results page", - () => { - cy.get(".post-teaser").should( - "contain", - "101 Essays that will change the way you think" - ); - } -); - -Then( - "I should not see posts without the searched-for term in the select dropdown", - () => { - cy.get(".ds-select-dropdown").should( - "not.contain", - "No searched for content" - ); - } -); - -Then("I select a user entry", () => { - cy.get(".searchable-input .user-teaser") - .first() - .trigger("click"); -}) - -Then("I should be on the user's profile", () => { - cy.location("pathname").should("eq", "/profile/user-for-search/search-for-me") -}) +}) \ No newline at end of file diff --git a/cypress/integration/common/I_am_on_page_{string}.js b/cypress/integration/common/I_am_on_page_{string}.js index 8fe06d7b9..2e61d35bc 100644 --- a/cypress/integration/common/I_am_on_page_{string}.js +++ b/cypress/integration/common/I_am_on_page_{string}.js @@ -1,5 +1,6 @@ import { Then } from "cypress-cucumber-preprocessor/steps"; Then("I am on page {string}", page => { - cy.location("pathname").should("contain", page.replace("...", "")); + cy.location("pathname") + .should("contain", page.replace("...", "")); }); \ No newline at end of file