From 21a830b53d6053e829a7d52293125bd1e118c973 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 7 Feb 2024 00:21:44 +0100 Subject: [PATCH] FIX: Clicking a notification was triggering an error (#25583) --- .../discourse/app/lib/user-menu/base-item.js | 11 +++-- .../tests/acceptance/notifications-test.js | 48 ++++++++++++++----- .../tests/fixtures/notification-fixtures.js | 2 +- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js b/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js index 8b5f656954c..803ad35c0de 100644 --- a/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js +++ b/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js @@ -61,11 +61,12 @@ export default class UserMenuBaseItem { if (wantsNewWindow(event)) { return; } - closeUserMenu(); - const href = this.linkHref; - if (href) { - DiscourseURL.routeTo(href); - } + event.preventDefault(); + closeUserMenu?.(); + + if (this.linkHref) { + DiscourseURL.routeTo(this.linkHref); + } } } diff --git a/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js b/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js index 78c4c00aaf7..0961d8bb932 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/notifications-test.js @@ -1,18 +1,20 @@ -import { visit } from "@ember/test-helpers"; +import { getOwner } from "@ember/application"; +import { click, currentURL, visit } from "@ember/test-helpers"; import { test } from "qunit"; -import User from "discourse/models/user"; +import NotificationFixtures from "discourse/tests/fixtures/notification-fixtures"; import { acceptance, - exists, publishToMessageBus, } from "discourse/tests/helpers/qunit-helpers"; +import { cloneJSON } from "discourse-common/lib/object"; acceptance("Category Notifications", function (needs) { needs.user({ muted_category_ids: [1], indirectly_muted_category_ids: [2] }); test("New category is muted when parent category is muted", async function (assert) { await visit("/"); - const user = User.current(); + const user = getOwner(this).lookup("service:current-user"); + await publishToMessageBus("/categories", { categories: [ { @@ -43,7 +45,7 @@ acceptance("Category Notifications", function (needs) { }); acceptance( - "User Notifications - there is no notifications yet", + "User Notifications - there are no notifications yet", function (needs) { needs.user(); @@ -55,15 +57,37 @@ acceptance( }); }); - test("It renders the empty state panel", async function (assert) { - await visit("/u/eviltrout/notifications"); - assert.ok(exists("div.empty-state")); - }); - - test("It does not render filter", async function (assert) { + test("renders the empty state panel", async function (assert) { await visit("/u/eviltrout/notifications"); - assert.notOk(exists("div.user-notifications-filter")); + assert.dom("div.empty-state").exists(); + assert.dom("div.user-notifications-filter").doesNotExist(); }); } ); + +acceptance("User Notifications", function (needs) { + needs.user(); + + needs.pretender((server, helper) => { + server.get("/notifications", () => { + return helper.response(cloneJSON(NotificationFixtures["/notifications"])); + }); + }); + + test("shows the notifications list", async function (assert) { + await visit("/u/eviltrout/notifications"); + + assert.dom("div.empty-state").doesNotExist(); + assert.dom("div.user-notifications-filter").exists(); + assert + .dom(".user-notifications-list .notification.unread") + .exists({ count: 6 }); + + await click(".notification.liked-consolidated a"); + assert.strictEqual( + currentURL(), + "/u/eviltrout/notifications/likes-received?acting_username=aquaman" + ); + }); +}); diff --git a/app/assets/javascripts/discourse/tests/fixtures/notification-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/notification-fixtures.js index 0cfc61bb04b..9122200e311 100644 --- a/app/assets/javascripts/discourse/tests/fixtures/notification-fixtures.js +++ b/app/assets/javascripts/discourse/tests/fixtures/notification-fixtures.js @@ -37,7 +37,7 @@ export default { notification_type: NOTIFICATION_TYPES.liked_consolidated, acting_user_avatar_template: "/letter_avatar_proxy/v4/letter/o/f05b48/{size}.png", read: false, - data: { display_username: "aquaman", count: "5" }, + data: { username: "aquaman", display_username: "aquaman", count: 5 }, }, { id: 789,