Prior to this commit, we had a default Glimmer component that was responsible for handling generic rendering of notifications in the user menu, and many notification types had a custom Glimmer component that inherited from the default component to customize how they were rendered. That implementation was less than ideal because it meant plugins would have to create Glimmer components to customize notification types added by them and that would make the surface area of the API too big. This commit changes the implementation so there's only one Glimmer component for rendering notifications, and then notification types that need to be customized can create a regular JavaScript class - `renderDirector` in the code - that provides the Glimmer component with the content it should display. We also introduce an API for plugins to register a renderer for a notification type or override an existing one. Some of the changes are partially extracted from https://github.com/discourse/discourse/pull/17379.
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
|
import { test } from "qunit";
|
|
import { createRenderDirector } from "discourse/tests/helpers/reviewable-items-helper";
|
|
import { htmlSafe } from "@ember/template";
|
|
import { emojiUnescape } from "discourse/lib/text";
|
|
import UserMenuReviewable from "discourse/models/user-menu-reviewable";
|
|
import I18n from "I18n";
|
|
|
|
function getReviewable(overrides = {}) {
|
|
return UserMenuReviewable.create(
|
|
Object.assign(
|
|
{
|
|
flagger_username: "sayo2",
|
|
id: 17,
|
|
pending: false,
|
|
topic_fancy_title: "anything hello world",
|
|
type: "ReviewableQueuedPost",
|
|
},
|
|
overrides
|
|
)
|
|
);
|
|
}
|
|
|
|
discourseModule("Unit | Reviewable Items | queued-post", function () {
|
|
test("description", function (assert) {
|
|
const reviewable = getReviewable({
|
|
topic_fancy_title: "This is safe title <a> :heart:",
|
|
});
|
|
const director = createRenderDirector(
|
|
reviewable,
|
|
"ReviewableQueuedPost",
|
|
this.siteSettings
|
|
);
|
|
assert.deepEqual(
|
|
director.description,
|
|
htmlSafe(
|
|
I18n.t("user_menu.reviewable.new_post_in_topic", {
|
|
title: `This is safe title <a> ${emojiUnescape(":heart:")}`,
|
|
})
|
|
),
|
|
"contains the fancy title without escaping because it's already safe"
|
|
);
|
|
|
|
delete reviewable.topic_fancy_title;
|
|
reviewable.payload_title = "This is unsafe title <a> :heart:";
|
|
assert.deepEqual(
|
|
director.description,
|
|
htmlSafe(
|
|
I18n.t("user_menu.reviewable.new_post_in_topic", {
|
|
title: `This is unsafe title <a> ${emojiUnescape(":heart:")}`,
|
|
})
|
|
),
|
|
"contains the payload title escaped and correctly unescapes emojis"
|
|
);
|
|
});
|
|
});
|