2022-11-02 21:41:30 +08:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
|
|
|
|
|
|
|
module("Discourse Chat | Unit | slugify-channel", function () {
|
2022-11-09 08:28:31 +08:00
|
|
|
test("defaults for title", function (assert) {
|
2024-11-04 04:04:38 +08:00
|
|
|
assert.strictEqual(slugifyChannel({ title: "Foo bar" }), "foo-bar");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-11-09 08:28:31 +08:00
|
|
|
test("a very long name for the title", function (assert) {
|
2022-11-02 21:41:30 +08:00
|
|
|
const string =
|
|
|
|
"xAq8l5ca2CtEToeMLe2pEr2VUGQBx3HPlxbkDExKrJHp4f7jCVw9id1EQv1N1lYMRdAIiZNnn94Kr0uU0iiEeVO4XkBVmpW8Mknmd";
|
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
assert.strictEqual(
|
2022-11-09 08:28:31 +08:00
|
|
|
slugifyChannel({ title: string }),
|
|
|
|
string.toLowerCase().slice(0, -1)
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-11-09 08:28:31 +08:00
|
|
|
test("a cyrillic name for the title", function (assert) {
|
2022-11-02 21:41:30 +08:00
|
|
|
const string = "Русская литература и фольклор";
|
|
|
|
|
2024-11-04 04:04:38 +08:00
|
|
|
assert.strictEqual(
|
2022-11-09 08:28:31 +08:00
|
|
|
slugifyChannel({ title: string }),
|
|
|
|
"русская-литература-и-фольклор"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("channel has escapedTitle", function (assert) {
|
2024-11-04 04:04:38 +08:00
|
|
|
assert.strictEqual(slugifyChannel({ escapedTitle: "Foo bar" }), "foo-bar");
|
2022-11-09 08:28:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("channel has slug and title", function (assert) {
|
2024-11-04 04:04:38 +08:00
|
|
|
assert.strictEqual(
|
2022-11-09 08:28:31 +08:00
|
|
|
slugifyChannel({ title: "Foo bar", slug: "some-other-thing" }),
|
|
|
|
"some-other-thing",
|
|
|
|
"slug takes priority"
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|