mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 17:05:57 +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.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import { module, test } from "qunit";
|
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
|
|
|
module("Discourse Chat | Unit | slugify-channel", function () {
|
|
test("defaults for title", function (assert) {
|
|
assert.equal(slugifyChannel({ title: "Foo bar" }), "foo-bar");
|
|
});
|
|
|
|
test("a very long name for the title", function (assert) {
|
|
const string =
|
|
"xAq8l5ca2CtEToeMLe2pEr2VUGQBx3HPlxbkDExKrJHp4f7jCVw9id1EQv1N1lYMRdAIiZNnn94Kr0uU0iiEeVO4XkBVmpW8Mknmd";
|
|
|
|
assert.equal(
|
|
slugifyChannel({ title: string }),
|
|
string.toLowerCase().slice(0, -1)
|
|
);
|
|
});
|
|
|
|
test("a cyrillic name for the title", function (assert) {
|
|
const string = "Русская литература и фольклор";
|
|
|
|
assert.equal(
|
|
slugifyChannel({ title: string }),
|
|
"русская-литература-и-фольклор"
|
|
);
|
|
});
|
|
|
|
test("channel has escapedTitle", function (assert) {
|
|
assert.equal(slugifyChannel({ escapedTitle: "Foo bar" }), "foo-bar");
|
|
});
|
|
|
|
test("channel has slug and title", function (assert) {
|
|
assert.equal(
|
|
slugifyChannel({ title: "Foo bar", slug: "some-other-thing" }),
|
|
"some-other-thing",
|
|
"slug takes priority"
|
|
);
|
|
});
|
|
});
|