DEV: Apply model transformations for the assigns list in the experimental user menu (#372)
This commit is contained in:
parent
7e85101b89
commit
7b08ab425c
|
@ -5,6 +5,7 @@ import UserMenuAssignItem from "discourse/plugins/discourse-assign/discourse-ass
|
|||
import Notification from "discourse/models/notification";
|
||||
import I18n from "I18n";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import Topic from "discourse/models/topic";
|
||||
|
||||
export default class UserMenuAssignNotificationsList extends UserMenuNotificationsList {
|
||||
get dismissTypes() {
|
||||
|
@ -35,25 +36,27 @@ export default class UserMenuAssignNotificationsList extends UserMenuNotificatio
|
|||
return "user-menu/assigns-list-empty-state";
|
||||
}
|
||||
|
||||
fetchItems() {
|
||||
return ajax("/assign/user-menu-assigns.json").then((data) => {
|
||||
const content = [];
|
||||
data.notifications.forEach((rawNotification) => {
|
||||
const notification = Notification.create(rawNotification);
|
||||
content.push(
|
||||
new UserMenuNotificationItem({
|
||||
notification,
|
||||
currentUser: this.currentUser,
|
||||
siteSettings: this.siteSettings,
|
||||
site: this.site,
|
||||
})
|
||||
);
|
||||
});
|
||||
async fetchItems() {
|
||||
const data = await ajax("/assign/user-menu-assigns.json");
|
||||
const content = [];
|
||||
|
||||
const notifications = data.notifications.map((n) => Notification.create(n));
|
||||
await Notification.applyTransformations(notifications);
|
||||
notifications.forEach((notification) => {
|
||||
content.push(
|
||||
...data.topics.map((assign) => new UserMenuAssignItem({ assign }))
|
||||
new UserMenuNotificationItem({
|
||||
notification,
|
||||
currentUser: this.currentUser,
|
||||
siteSettings: this.siteSettings,
|
||||
site: this.site,
|
||||
})
|
||||
);
|
||||
return content;
|
||||
});
|
||||
|
||||
const topics = data.topics.map((t) => Topic.create(t));
|
||||
await Topic.applyTransformations(topics);
|
||||
content.push(...topics.map((assign) => new UserMenuAssignItem({ assign })));
|
||||
return content;
|
||||
}
|
||||
|
||||
dismissWarningModal() {
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
import { click, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
const USER_MENU_ASSIGN_RESPONSE = {
|
||||
notifications: [
|
||||
|
@ -448,4 +449,37 @@ acceptance("Discourse Assign | experimental user menu", function (needs) {
|
|||
"empty state body has user-plus icon"
|
||||
);
|
||||
});
|
||||
|
||||
test("assigns tab applies model transformations", async function (assert) {
|
||||
withPluginApi("0.1", (api) => {
|
||||
api.registerModelTransformer("notification", (notifications) => {
|
||||
notifications.forEach((notification) => {
|
||||
notification.fancy_title = `notificationModelTransformer ${notification.fancy_title}`;
|
||||
});
|
||||
});
|
||||
api.registerModelTransformer("topic", (topics) => {
|
||||
topics.forEach((topic) => {
|
||||
topic.fancy_title = `topicModelTransformer ${topic.fancy_title}`;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await visit("/");
|
||||
await click(".d-header-icons .current-user");
|
||||
await click("#user-menu-button-assign-list");
|
||||
|
||||
const notifications = queryAll(
|
||||
"#quick-access-assign-list ul li.notification"
|
||||
);
|
||||
assert.strictEqual(
|
||||
notifications[0].textContent.replace(/\s+/g, " ").trim(),
|
||||
"tony notificationModelTransformer Test poll topic please bear with me"
|
||||
);
|
||||
|
||||
const assigns = queryAll("#quick-access-assign-list ul li.assign");
|
||||
assert.strictEqual(
|
||||
assigns[0].textContent.replace(/\s+/g, " ").trim(),
|
||||
"topicModelTransformer Howdy this my test topic with emoji !"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue