FIX: Clicking a notification was triggering an error (#25583)

This commit is contained in:
Jarek Radosz 2024-02-07 00:21:44 +01:00 committed by GitHub
parent c8c20585a7
commit 21a830b53d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 18 deletions

View File

@ -61,11 +61,12 @@ export default class UserMenuBaseItem {
if (wantsNewWindow(event)) { if (wantsNewWindow(event)) {
return; return;
} }
closeUserMenu();
const href = this.linkHref;
if (href) {
DiscourseURL.routeTo(href);
}
event.preventDefault(); event.preventDefault();
closeUserMenu?.();
if (this.linkHref) {
DiscourseURL.routeTo(this.linkHref);
}
} }
} }

View File

@ -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 { test } from "qunit";
import User from "discourse/models/user"; import NotificationFixtures from "discourse/tests/fixtures/notification-fixtures";
import { import {
acceptance, acceptance,
exists,
publishToMessageBus, publishToMessageBus,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Category Notifications", function (needs) { acceptance("Category Notifications", function (needs) {
needs.user({ muted_category_ids: [1], indirectly_muted_category_ids: [2] }); needs.user({ muted_category_ids: [1], indirectly_muted_category_ids: [2] });
test("New category is muted when parent category is muted", async function (assert) { test("New category is muted when parent category is muted", async function (assert) {
await visit("/"); await visit("/");
const user = User.current(); const user = getOwner(this).lookup("service:current-user");
await publishToMessageBus("/categories", { await publishToMessageBus("/categories", {
categories: [ categories: [
{ {
@ -43,7 +45,7 @@ acceptance("Category Notifications", function (needs) {
}); });
acceptance( acceptance(
"User Notifications - there is no notifications yet", "User Notifications - there are no notifications yet",
function (needs) { function (needs) {
needs.user(); needs.user();
@ -55,15 +57,37 @@ acceptance(
}); });
}); });
test("It renders the empty state panel", async function (assert) { test("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) {
await visit("/u/eviltrout/notifications"); 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"
);
});
});

View File

@ -37,7 +37,7 @@ export default {
notification_type: NOTIFICATION_TYPES.liked_consolidated, notification_type: NOTIFICATION_TYPES.liked_consolidated,
acting_user_avatar_template: "/letter_avatar_proxy/v4/letter/o/f05b48/{size}.png", acting_user_avatar_template: "/letter_avatar_proxy/v4/letter/o/f05b48/{size}.png",
read: false, read: false,
data: { display_username: "aquaman", count: "5" }, data: { username: "aquaman", display_username: "aquaman", count: 5 },
}, },
{ {
id: 789, id: 789,