From f8d87a4e98b8e1b75cd39a6ce414587cc4b9aaca Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sun, 11 Apr 2021 17:43:20 +0200 Subject: [PATCH] Notification.Mention.feature Regex for URL matches "I am on page ..." Fixed some category/search related errors --- backend/src/db/factories.js | 10 ++--- backend/src/schema/resolvers/posts.js | 2 +- .../integration/Notification.Mention.feature | 28 ++++++++++++ ..._with_the_title_{string}_beginning_with.js | 8 ++++ .../mention_{string}_in_the_text.js | 9 ++++ ...cation_menu_and_click_on_the_first_item.js | 10 +++++ ...t}_unread_notifications_in_the_top_menu.js | 6 +++ ...ton_links_to_the_all_notifications_page.js | 8 ++++ .../the_unread_counter_is_removed.js | 6 +++ cypress/integration/Post.Create.feature | 2 +- cypress/integration/Post.Images.feature | 8 ++-- cypress/integration/Post.feature | 2 +- cypress/integration/Search.feature | 1 - cypress/integration/common/.steps.js | 44 ------------------- .../common/I_am_on_page_{string}.js | 2 +- 15 files changed, 88 insertions(+), 58 deletions(-) create mode 100644 cypress/integration/Notification.Mention.feature create mode 100644 cypress/integration/Notification.Mention/I_start_to_write_a_new_post_with_the_title_{string}_beginning_with.js create mode 100644 cypress/integration/Notification.Mention/mention_{string}_in_the_text.js create mode 100644 cypress/integration/Notification.Mention/open_the_notification_menu_and_click_on_the_first_item.js create mode 100644 cypress/integration/Notification.Mention/see_{int}_unread_notifications_in_the_top_menu.js create mode 100644 cypress/integration/Notification.Mention/the_notification_menu_button_links_to_the_all_notifications_page.js create mode 100644 cypress/integration/Notification.Mention/the_unread_counter_is_removed.js diff --git a/backend/src/db/factories.js b/backend/src/db/factories.js index 717926413..a165979e5 100644 --- a/backend/src/db/factories.js +++ b/backend/src/db/factories.js @@ -105,12 +105,12 @@ Factory.define('user') }) Factory.define('post') - .option('categoryIds', []) + /*.option('categoryIds', []) .option('categories', ['categoryIds'], (categoryIds) => { if (categoryIds.length) return Promise.all(categoryIds.map((id) => neode.find('Category', id))) // there must be at least one category return Promise.all([Factory.build('category')]) - }) + })*/ .option('tagIds', []) .option('tags', ['tagIds'], (tagIds) => { return Promise.all(tagIds.map((id) => neode.find('Tag', id))) @@ -147,16 +147,16 @@ Factory.define('post') return language || 'en' }) .after(async (buildObject, options) => { - const [post, author, image, categories, tags] = await Promise.all([ + const [post, author, image, /*categories,*/ tags] = await Promise.all([ neode.create('Post', buildObject), options.author, options.image, - options.categories, + //options.categories, options.tags, ]) await Promise.all([ post.relateTo(author, 'author'), - Promise.all(categories.map((c) => c.relateTo(post, 'post'))), + //Promise.all(categories.map((c) => c.relateTo(post, 'post'))), Promise.all(tags.map((t) => t.relateTo(post, 'post'))), ]) if (image) await post.relateTo(image, 'image') diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index b7b77bbd5..d199b6f09 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -348,7 +348,7 @@ export default { undefinedToNull: ['activityId', 'objectId', 'language', 'pinnedAt', 'pinned'], hasMany: { tags: '-[:TAGGED]->(related:Tag)', - categories: '-[:CATEGORIZED]->(related:Category)', + // categories: '-[:CATEGORIZED]->(related:Category)', comments: '<-[:COMMENTS]-(related:Comment)', shoutedBy: '<-[:SHOUTED]-(related:User)', emotions: '<-[related:EMOTED]', diff --git a/cypress/integration/Notification.Mention.feature b/cypress/integration/Notification.Mention.feature new file mode 100644 index 000000000..5ae2296f2 --- /dev/null +++ b/cypress/integration/Notification.Mention.feature @@ -0,0 +1,28 @@ +Feature: Notification for a mention + As a user + I want to be notified if somebody mentions me in a post or comment + In order join conversations about or related to me + + Background: + Given the following "users" are in the database: + | slug | email | password | id | name | termsAndConditionsAgreedVersion | + | wolle-aus-hamburg | wolle@example.org | 1234 | wolle | Wolle aus Hamburg | 0.0.4 | + | matt-rider | matt@example.org | 4321 | matt | Matt Rider | 0.0.4 | + + Scenario: Mention another user, re-login as this user and see notifications + Given I am logged in as "wolle-aus-hamburg" + And I navigate to page "landing" + And I navigate to page "post/create" + And I start to write a new post with the title "Hey Matt" beginning with: + """ + Big shout to our fellow contributor + """ + And mention "@matt-rider" in the text + And I click on "save button" + And I am logged in as "matt-rider" + And I navigate to page "landing" + And see 1 unread notifications in the top menu + And open the notification menu and click on the first item + Then I am on page "/post/.*/hey-matt" + And the unread counter is removed + And the notification menu button links to the all notifications page \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/I_start_to_write_a_new_post_with_the_title_{string}_beginning_with.js b/cypress/integration/Notification.Mention/I_start_to_write_a_new_post_with_the_title_{string}_beginning_with.js new file mode 100644 index 000000000..fde5042c1 --- /dev/null +++ b/cypress/integration/Notification.Mention/I_start_to_write_a_new_post_with_the_title_{string}_beginning_with.js @@ -0,0 +1,8 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I start to write a new post with the title {string} beginning with:", (title, intro) => { + cy.get('input[name="title"]') + .type(title); + cy.get(".ProseMirror") + .type(intro); +}); \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/mention_{string}_in_the_text.js b/cypress/integration/Notification.Mention/mention_{string}_in_the_text.js new file mode 100644 index 000000000..fa8a29d4a --- /dev/null +++ b/cypress/integration/Notification.Mention/mention_{string}_in_the_text.js @@ -0,0 +1,9 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("mention {string} in the text", mention => { + cy.get(".ProseMirror") + .type(" @"); + cy.get(".suggestion-list__item") + .contains(mention) + .click(); +}); \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/open_the_notification_menu_and_click_on_the_first_item.js b/cypress/integration/Notification.Mention/open_the_notification_menu_and_click_on_the_first_item.js new file mode 100644 index 000000000..0d3917f38 --- /dev/null +++ b/cypress/integration/Notification.Mention/open_the_notification_menu_and_click_on_the_first_item.js @@ -0,0 +1,10 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("open the notification menu and click on the first item", () => { + cy.get(".notifications-menu") + .invoke('show') + .click(); // "invoke('show')" because of the delay for show the menu + cy.get(".notification .link") + .first() + .click({force: true}); +}); \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/see_{int}_unread_notifications_in_the_top_menu.js b/cypress/integration/Notification.Mention/see_{int}_unread_notifications_in_the_top_menu.js new file mode 100644 index 000000000..124b61873 --- /dev/null +++ b/cypress/integration/Notification.Mention/see_{int}_unread_notifications_in_the_top_menu.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("see {int} unread notifications in the top menu", count => { + cy.get(".notifications-menu") + .should("contain", count); +}); \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/the_notification_menu_button_links_to_the_all_notifications_page.js b/cypress/integration/Notification.Mention/the_notification_menu_button_links_to_the_all_notifications_page.js new file mode 100644 index 000000000..e40827a16 --- /dev/null +++ b/cypress/integration/Notification.Mention/the_notification_menu_button_links_to_the_all_notifications_page.js @@ -0,0 +1,8 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the notification menu button links to the all notifications page", () => { + cy.get(".notifications-menu") + .click(); + cy.location("pathname") + .should("contain", "/notifications"); +}); \ No newline at end of file diff --git a/cypress/integration/Notification.Mention/the_unread_counter_is_removed.js b/cypress/integration/Notification.Mention/the_unread_counter_is_removed.js new file mode 100644 index 000000000..3859103e8 --- /dev/null +++ b/cypress/integration/Notification.Mention/the_unread_counter_is_removed.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("the unread counter is removed", () => { + cy.get('.notifications-menu .counter-icon') + .should('not.exist'); +}); \ No newline at end of file diff --git a/cypress/integration/Post.Create.feature b/cypress/integration/Post.Create.feature index e8d3947f2..602c924e3 100644 --- a/cypress/integration/Post.Create.feature +++ b/cypress/integration/Post.Create.feature @@ -20,5 +20,5 @@ Feature: Create a post for active citizenship. """ And I click on "save button" - Then I am on page ".../my-first-post" + Then I am on page "/post/.*/my-first-post" And the post was saved successfully diff --git a/cypress/integration/Post.Images.feature b/cypress/integration/Post.Images.feature index 5b03c047c..ff99d320a 100644 --- a/cypress/integration/Post.Images.feature +++ b/cypress/integration/Post.Images.feature @@ -19,7 +19,7 @@ Feature: Upload/Delete images on posts And I add all required fields And I click on "save button" And I wait for 750 milliseconds - Then I am on page ".../new-post" + Then I am on page "/post/.*/new-post" And I wait for 750 milliseconds And the post was saved successfully with the "new" teaser image @@ -29,7 +29,7 @@ Feature: Upload/Delete images on posts And I click on "save button" Then I see a toaster with "Saved!" And I wait for 750 milliseconds - And I am on page ".../post-to-be-updated" + And I am on page "/post/.*/post-to-be-updated" And I wait for 750 milliseconds Then the post was saved successfully with the "updated" teaser image @@ -46,7 +46,7 @@ Feature: Upload/Delete images on posts And I add all required fields And I click on "save button" And I wait for 750 milliseconds - Then I am on page ".../new-post" + Then I am on page "/post/.*/new-post" And I wait for 750 milliseconds And the "new" post was saved successfully without a teaser image @@ -56,6 +56,6 @@ Feature: Upload/Delete images on posts Then I should be able to "remove" a teaser image And I click on "save button" And I wait for 750 milliseconds - Then I am on page ".../post-to-be-updated" + Then I am on page "/post/.*/post-to-be-updated" And I wait for 750 milliseconds And the "updated" post was saved successfully without a teaser image \ No newline at end of file diff --git a/cypress/integration/Post.feature b/cypress/integration/Post.feature index a02398714..a4f6f98ae 100644 --- a/cypress/integration/Post.feature +++ b/cypress/integration/Post.feature @@ -20,4 +20,4 @@ Feature: See a post Scenario: Navigate to the Post Page When I navigate to page "landing" And I click on "the first post" - Then I am on page "post/..." + Then I am on page "/post/.*" diff --git a/cypress/integration/Search.feature b/cypress/integration/Search.feature index b98fcbc76..91ddd8375 100644 --- a/cypress/integration/Search.feature +++ b/cypress/integration/Search.feature @@ -30,7 +30,6 @@ Feature: Search 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 diff --git a/cypress/integration/common/.steps.js b/cypress/integration/common/.steps.js index a59082b1b..e7331fa36 100644 --- a/cypress/integration/common/.steps.js +++ b/cypress/integration/common/.steps.js @@ -185,50 +185,6 @@ Then( } ); -When("open the notification menu and click on the first item", () => { - cy.get(".notifications-menu").invoke('show').click(); // "invoke('show')" because of the delay for show the menu - cy.get(".notification .link") - .first() - .click({ - force: true - }); -}); - -Then("see {int} unread notifications in the top menu", count => { - cy.get(".notifications-menu").should("contain", count); -}); - -Then("I get to the post page of {string}", path => { - path = path.replace("...", ""); - cy.url().should("contain", "/post/"); - cy.url().should("contain", path); -}); - -When( - "I start to write a new post with the title {string} beginning with:", - (title, intro) => { - cy.get(".post-add-button").click(); - cy.get('input[name="title"]').type(title); - cy.get(".ProseMirror").type(intro); - } -); - -When("mention {string} in the text", mention => { - cy.get(".ProseMirror").type(" @"); - cy.get(".suggestion-list__item") - .contains(mention) - .click(); -}); - -Then("the unread counter is removed", () => { - cy.get('.notifications-menu .counter-icon').should('not.exist'); -}); - -Then("the notification menu button links to the all notifications page", () => { - cy.get(".notifications-menu").click(); - cy.location("pathname").should("contain", "/notifications"); -}); - Given("there is an annoying user called {string}", name => { cy.factory().build("user", { id: "annoying-user", diff --git a/cypress/integration/common/I_am_on_page_{string}.js b/cypress/integration/common/I_am_on_page_{string}.js index 2e61d35bc..5ef1b9852 100644 --- a/cypress/integration/common/I_am_on_page_{string}.js +++ b/cypress/integration/common/I_am_on_page_{string}.js @@ -2,5 +2,5 @@ import { Then } from "cypress-cucumber-preprocessor/steps"; Then("I am on page {string}", page => { cy.location("pathname") - .should("contain", page.replace("...", "")); + .should("match", new RegExp(page)); }); \ No newline at end of file