From 9f514a50ca3db1a0d9347901b245ea66abdf2fc5 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Tue, 26 Jul 2022 16:31:59 -0300 Subject: [PATCH] DEV: Add acceptance tests for assignment notifications (#307) Co-authored-by: Jarek Radosz Co-authored-by: Alan Guo Xiang Tan --- .../acceptance/assigned-topic-test.js | 35 ++++++++ .../fixtures/notifications-fixtures.js | 87 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 test/javascripts/fixtures/notifications-fixtures.js diff --git a/test/javascripts/acceptance/assigned-topic-test.js b/test/javascripts/acceptance/assigned-topic-test.js index 82cd69a..7123ce0 100644 --- a/test/javascripts/acceptance/assigned-topic-test.js +++ b/test/javascripts/acceptance/assigned-topic-test.js @@ -7,8 +7,10 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import { visit } from "@ember/test-helpers"; import { cloneJSON } from "discourse-common/lib/object"; +import I18n from "I18n"; import topicFixtures from "discourse/tests/fixtures/topic"; import selectKit from "discourse/tests/helpers/select-kit-helper"; +import NotificationFixture from "../fixtures/notifications-fixtures"; function assignCurrentUserToTopic(needs) { needs.pretender((server, helper) => { @@ -40,6 +42,12 @@ function assignCurrentUserToTopic(needs) { }; return helper.response(topic); }); + + server.get("/notifications", () => { + return helper.response( + NotificationFixture["/assign/notifications/eviltrout"] + ); + }); }); } @@ -146,6 +154,33 @@ acceptance("Discourse Assign | Assigned topic", function (needs) { "does not show reassign dropdown at the bottom of the topic" ); }); + + test("Shows assignment notification", async function (assert) { + updateCurrentUser({ can_assign: true }); + + await visit("/u/eviltrout/notifications"); + + const notification = query( + "section.user-content ul.notifications li.item.notification" + ); + + assert.equal( + notification.children[0].classList, + "assigned", + "with correct assigned class" + ); + + assert.equal( + notification.querySelector("a").title, + I18n.t("notifications.titles.assigned"), + "with correct title" + ); + assert.equal( + notification.querySelector("svg use").href["baseVal"], + "#user-plus", + "with correct icon" + ); + }); }); acceptance("Discourse Assign | Re-assign topic", function (needs) { diff --git a/test/javascripts/fixtures/notifications-fixtures.js b/test/javascripts/fixtures/notifications-fixtures.js new file mode 100644 index 0000000..c27f2d9 --- /dev/null +++ b/test/javascripts/fixtures/notifications-fixtures.js @@ -0,0 +1,87 @@ +export default { + "/assign/notifications/eviltrout": { + notifications: [ + { + id: 193, + user_id: 26, + notification_type: 34, + read: false, + high_priority: true, + created_at: "2022-03-18T17:51:11.920Z", + post_number: 1, + topic_id: 59, + fancy_title: + "A bear, however hard he tries, grows tubby without exercise", + slug: "a-bear-however-hard-he-tries-grows-tubby-without-exercise", + data: { + message: "discourse_assign.assign_notification", + display_username: "system", + topic_title: + "A bear, however hard he tries, grows tubby without exercise", + }, + }, + { + id: 192, + user_id: 26, + notification_type: 12, + read: false, + high_priority: false, + created_at: "2022-03-18T16:47:09.668Z", + post_number: null, + topic_id: null, + slug: null, + data: { + badge_id: 5, + badge_name: "Welcome", + badge_slug: "welcome", + badge_title: false, + username: "eviltrout", + }, + }, + { + id: 191, + user_id: 26, + notification_type: 5, + read: false, + high_priority: false, + created_at: "2022-03-18T16:46:57.744Z", + post_number: 5, + topic_id: 59, + fancy_title: + "A bear, however hard he tries, grows tubby without exercise", + slug: "a-bear-however-hard-he-tries-grows-tubby-without-exercise", + data: { + topic_title: + "A bear, however hard he tries, grows tubby without exercise", + original_post_id: 285, + original_post_type: 1, + original_username: "system", + revision_number: null, + display_username: "system", + }, + }, + { + id: 148, + user_id: 26, + notification_type: 12, + read: false, + high_priority: false, + created_at: "2022-03-17T21:49:02.226Z", + post_number: null, + topic_id: null, + slug: null, + data: { + badge_id: 1, + badge_name: "Basic", + badge_slug: "basic", + badge_title: false, + username: "eviltrout", + }, + }, + ], + total_rows_notifications: 4, + seen_notification_id: 193, + load_more_notifications: + "/notifications?filter=all&offset=60&username=eviltrout", + }, +};