From 1c1da792234578cc9223ef7bcb6a39b47db7f97f Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Mon, 11 Dec 2023 10:56:29 -0600 Subject: [PATCH] DEV: Update tests/notification rendering for new API (#178) --- .../initializers/post-voting-icon.js | 33 +++++++++++++++++-- .../acceptance/notifications-test.js | 17 +++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/initializers/post-voting-icon.js b/assets/javascripts/discourse/initializers/post-voting-icon.js index 182d9d68..9562d362 100644 --- a/assets/javascripts/discourse/initializers/post-voting-icon.js +++ b/assets/javascripts/discourse/initializers/post-voting-icon.js @@ -1,4 +1,7 @@ import { withPluginApi } from "discourse/lib/plugin-api"; +import { postUrl } from "discourse/lib/utilities"; +import I18n from "I18n"; +import { buildAnchorId } from "../components/post-voting-comment"; export default { name: "post-voting-icon", @@ -9,8 +12,34 @@ export default { return; } - withPluginApi("1.2.0", (api) => { - api.replaceIcon("notification.question_answer_user_commented", "comment"); + withPluginApi("1.18.0", (api) => { + api.registerNotificationTypeRenderer( + "question_answer_user_commented", + (NotificationTypeBase) => { + return class extends NotificationTypeBase { + get linkTitle() { + return I18n.t( + "notifications.titles.question_answer_user_commented" + ); + } + + get linkHref() { + const url = postUrl( + this.notification.slug, + this.topicId, + this.notification.post_number + ); + return `${url}#${buildAnchorId( + this.notification.data.post_voting_comment_id + )}`; + } + + get icon() { + return "comment"; + } + }; + } + ); }); }, }; diff --git a/test/javascripts/acceptance/notifications-test.js b/test/javascripts/acceptance/notifications-test.js index da197c31..06e572a4 100644 --- a/test/javascripts/acceptance/notifications-test.js +++ b/test/javascripts/acceptance/notifications-test.js @@ -1,10 +1,11 @@ import { visit } from "@ember/test-helpers"; import { test } from "qunit"; -import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import I18n from "I18n"; acceptance("Discourse Post Voting - notifications", function (needs) { needs.user(); + needs.settings({ post_voting_enabled: true }); needs.pretender((server, helper) => { server.get("/notifications", () => { @@ -32,12 +33,18 @@ acceptance("Discourse Post Voting - notifications", function (needs) { test("viewing comments notifications", async (assert) => { await visit("/u/eviltrout/notifications"); - const notification = queryAll("ul.notifications")[0]; + const notification = query(".user-notifications-list .notification"); assert.strictEqual( - notification.textContent, - "someuser some fancy title", - "displays the username of user that commented and topic's title in notification" + notification.querySelector(".item-label").textContent.trim(), + "someuser", + "Renders username" + ); + + assert.strictEqual( + notification.querySelector(".item-description").textContent.trim(), + "some fancy title", + "Renders description" ); assert.ok(