mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 09:23:39 +08:00
c6764d8c74
This commit automatically ensures that category channels have slugs when they are created or updated based on the channel name, category name, or existing slug. The behaviour has been copied from the Category model. We also include a backfill here with a simplified version of Slug.for with deduplication to fill the slugs for already created Category chat channels. The channel slug is also now used for chat notifications, and for the UI and navigation for chat. `slugifyChannel` is still used, but now does the following fallback: * Uses channel.slug if it is present * Uses channel.escapedTitle if it is present * Uses channel.title if it is present In future we may want to remove this altogether and always rely on the slug being present, but this is currently not possible because we are not generating slugs for DM channels at this point.
140 lines
4.0 KiB
JavaScript
140 lines
4.0 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
|
import { render } from "@ember/test-helpers";
|
|
import { deepMerge } from "discourse-common/lib/object";
|
|
import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types";
|
|
import Notification from "discourse/models/notification";
|
|
import hbs from "htmlbars-inline-precompile";
|
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
|
import I18n from "I18n";
|
|
|
|
function getNotification(overrides = {}) {
|
|
return Notification.create(
|
|
deepMerge(
|
|
{
|
|
id: 11,
|
|
notification_type: NOTIFICATION_TYPES.chat_invitation,
|
|
read: false,
|
|
data: {
|
|
message: "chat.mention_notification",
|
|
mentioned_by_username: "eviltrout",
|
|
chat_channel_id: 9,
|
|
chat_message_id: 2,
|
|
chat_channel_title: "Site",
|
|
},
|
|
},
|
|
overrides
|
|
)
|
|
);
|
|
}
|
|
|
|
module(
|
|
"Discourse Chat | Widget | chat-mention-notification-item",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("generated link", async function (assert) {
|
|
this.set("args", getNotification());
|
|
const data = this.args.data;
|
|
await render(
|
|
hbs`<MountWidget @widget="chat-mention-notification-item" @args={{this.args}} />`
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a div").innerHTML.trim(),
|
|
I18n.t("notifications.popup.chat_mention.direct_html", {
|
|
username: "eviltrout",
|
|
identifier: null,
|
|
channel: "Site",
|
|
})
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a").getAttribute("href"),
|
|
`/chat/channel/${data.chat_channel_id}/${slugifyChannel({
|
|
title: data.chat_channel_title,
|
|
})}?messageId=${data.chat_message_id}`
|
|
);
|
|
});
|
|
}
|
|
);
|
|
|
|
module(
|
|
"Discourse Chat | Widget | chat-group-mention-notification-item",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("generated link", async function (assert) {
|
|
this.set(
|
|
"args",
|
|
getNotification({
|
|
data: {
|
|
mentioned_by_username: "eviltrout",
|
|
identifier: "moderators",
|
|
},
|
|
})
|
|
);
|
|
const data = this.args.data;
|
|
await render(
|
|
hbs`<MountWidget @widget="chat-group-mention-notification-item" @args={{this.args}} />`
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a div").innerHTML.trim(),
|
|
I18n.t("notifications.popup.chat_mention.other_html", {
|
|
username: "eviltrout",
|
|
identifier: "@moderators",
|
|
channel: "Site",
|
|
})
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a").getAttribute("href"),
|
|
`/chat/channel/${data.chat_channel_id}/${slugifyChannel({
|
|
title: data.chat_channel_title,
|
|
})}?messageId=${data.chat_message_id}`
|
|
);
|
|
});
|
|
}
|
|
);
|
|
|
|
module(
|
|
"Discourse Chat | Widget | chat-group-mention-notification-item (@all)",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("generated link", async function (assert) {
|
|
this.set(
|
|
"args",
|
|
getNotification({
|
|
data: {
|
|
mentioned_by_username: "eviltrout",
|
|
identifier: "all",
|
|
},
|
|
})
|
|
);
|
|
const data = this.args.data;
|
|
await render(
|
|
hbs`<MountWidget @widget="chat-group-mention-notification-item" @args={{this.args}} />`
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a div").innerHTML.trim(),
|
|
I18n.t("notifications.popup.chat_mention.other_html", {
|
|
username: "eviltrout",
|
|
identifier: "@all",
|
|
channel: "Site",
|
|
})
|
|
);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-invitation a").getAttribute("href"),
|
|
`/chat/channel/${data.chat_channel_id}/${slugifyChannel({
|
|
title: data.chat_channel_title,
|
|
})}?messageId=${data.chat_message_id}`
|
|
);
|
|
});
|
|
}
|
|
);
|