Skip to content

Commit

Permalink
DEV: Update tests/notification rendering for new API (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanlan authored Dec 11, 2023
1 parent 34a76e8 commit 1c1da79
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
33 changes: 31 additions & 2 deletions assets/javascripts/discourse/initializers/post-voting-icon.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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";
}
};
}
);
});
},
};
17 changes: 12 additions & 5 deletions test/javascripts/acceptance/notifications-test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1c1da79

Please sign in to comment.