snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
216
web/tests/topic_link_util.test.cjs
Normal file
216
web/tests/topic_link_util.test.cjs
Normal file
@@ -0,0 +1,216 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {make_stream} = require("./lib/example_stream.cjs");
|
||||
const {zrequire, mock_esm} = require("./lib/namespace.cjs");
|
||||
const {run_test} = require("./lib/test.cjs");
|
||||
|
||||
const topic_link_util = zrequire("topic_link_util");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const settings_config = zrequire("settings_config");
|
||||
mock_esm("../src/user_settings", {
|
||||
user_settings: {
|
||||
web_channel_default_view: settings_config.web_channel_default_view_values.channel_feed.code,
|
||||
},
|
||||
});
|
||||
mock_esm("../src/state_data", {
|
||||
realm: {realm_empty_topic_display_name: "general chat"},
|
||||
});
|
||||
|
||||
const sweden_stream = make_stream({
|
||||
name: "Sweden",
|
||||
description: "Cold, mountains and home decor.",
|
||||
stream_id: 1,
|
||||
subscribed: true,
|
||||
type: "stream",
|
||||
});
|
||||
|
||||
const denmark_stream = make_stream({
|
||||
name: "Denmark",
|
||||
description: "Vikings and boats, in a serene and cold weather.",
|
||||
stream_id: 2,
|
||||
subscribed: true,
|
||||
type: "stream",
|
||||
});
|
||||
|
||||
const dollar_stream = make_stream({
|
||||
name: "$$MONEY$$",
|
||||
description: "Money money money",
|
||||
stream_id: 6,
|
||||
subscribed: true,
|
||||
type: "stream",
|
||||
});
|
||||
|
||||
const markdown_stream = make_stream({
|
||||
name: "Markdown [md]",
|
||||
description: "markdown",
|
||||
stream_id: 7,
|
||||
subscribed: true,
|
||||
type: "stream",
|
||||
});
|
||||
|
||||
stream_data.add_sub_for_tests(sweden_stream);
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
stream_data.add_sub_for_tests(dollar_stream);
|
||||
stream_data.add_sub_for_tests(markdown_stream);
|
||||
|
||||
run_test("stream_link_syntax_test", () => {
|
||||
assert.equal(topic_link_util.get_stream_link_syntax("Sweden"), "#**Sweden**");
|
||||
assert.equal(topic_link_util.get_stream_link_syntax("Denmark"), "#**Denmark**");
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_link_syntax("$$MONEY$$"),
|
||||
"[#$$MONEY$$](#narrow/channel/6)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_link_syntax("Markdown [md]"),
|
||||
"[#Markdown [md]](#narrow/channel/7-Markdown-.5Bmd.5D)",
|
||||
);
|
||||
});
|
||||
|
||||
run_test("stream_topic_link_syntax_test", () => {
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "topic"),
|
||||
"#**Sweden>topic**",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "test `test` test"),
|
||||
"[#Sweden > test `test` test](#narrow/channel/1-Sweden/topic/test.20.60test.60.20test)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Denmark", "test `test` test`s"),
|
||||
"[#Denmark > test `test` test`s](#narrow/channel/2-Denmark/topic/test.20.60test.60.20test.60s)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "error due to *"),
|
||||
"[#Sweden > error due to *](#narrow/channel/1-Sweden/topic/error.20due.20to.20.2A)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "*asterisk"),
|
||||
"[#Sweden > *asterisk](#narrow/channel/1-Sweden/topic/.2Aasterisk)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "greaterthan>"),
|
||||
"[#Sweden > greaterthan>](#narrow/channel/1-Sweden/topic/greaterthan.3E)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("$$MONEY$$", "dollar"),
|
||||
"[#$$MONEY$$ > dollar](#narrow/channel/6/topic/dollar)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "swe$$dish"),
|
||||
"[#Sweden > swe$$dish](#narrow/channel/1-Sweden/topic/swe.24.24dish)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_fallback_markdown_link("Sweden"),
|
||||
"[#Sweden](#narrow/channel/1-Sweden)",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_fallback_markdown_link("$$MONEY$$"),
|
||||
"[#$$MONEY$$](#narrow/channel/6)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_fallback_markdown_link("Markdown [md]"),
|
||||
"[#Markdown [md]](#narrow/channel/7-Markdown-.5Bmd.5D)",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "&ab"),
|
||||
"[#Sweden > &ab](#narrow/channel/1-Sweden/topic/.26ab)",
|
||||
);
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "&ab]"),
|
||||
"[#Sweden > &ab]](#narrow/channel/1-Sweden/topic/.26ab.5D)",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("Sweden", "&a[b"),
|
||||
"[#Sweden > &a[b](#narrow/channel/1-Sweden/topic/.26a.5Bb)",
|
||||
);
|
||||
|
||||
assert.equal(topic_link_util.get_stream_topic_link_syntax("Sweden", ""), "#**Sweden>**");
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_stream_topic_link_syntax("$$MONEY$$", ""),
|
||||
"[#$$MONEY$$ > translated: general chat](#narrow/channel/6/topic/)",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_fallback_markdown_link("Sweden", "abc", 123),
|
||||
"[#Sweden > abc @ 💬](#narrow/channel/1-Sweden/topic/abc/near/123)",
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.get_fallback_markdown_link("Sweden", "", 123),
|
||||
"[#Sweden > translated: general chat @ 💬](#narrow/channel/1-Sweden/topic//near/123)",
|
||||
);
|
||||
|
||||
// Only for full coverage of the module.
|
||||
assert.equal(topic_link_util.escape_invalid_stream_topic_characters("Sweden"), "Sweden");
|
||||
assert.equal(
|
||||
topic_link_util.as_html_link_syntax_unsafe("test", "example.com"),
|
||||
'<a href="example.com">test</a>',
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
topic_link_util.html_unescape_invalid_stream_topic_characters("$$MONEY$$"),
|
||||
"$$MONEY$$",
|
||||
);
|
||||
});
|
||||
|
||||
run_test("get_topic_link_content_with_stream_name", () => {
|
||||
assert.deepEqual(
|
||||
topic_link_util.get_topic_link_content_with_stream_name({
|
||||
stream_name: sweden_stream.name,
|
||||
topic_name: "abc",
|
||||
message_id: 123,
|
||||
}),
|
||||
{
|
||||
label_text_markdown: "#Sweden > abc @ 💬",
|
||||
label_text_plain: "#Sweden > abc @ 💬",
|
||||
url: "#narrow/channel/1-Sweden/topic/abc/near/123",
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
topic_link_util.get_topic_link_content_with_stream_name({
|
||||
stream_name: sweden_stream.name,
|
||||
topic_name: "a",
|
||||
message_id: 123,
|
||||
}),
|
||||
{
|
||||
label_text_markdown: "#Sweden > a @ 💬",
|
||||
label_text_plain: "#Sweden > a @ 💬",
|
||||
url: "#narrow/channel/1-Sweden/topic/a.21.5Bb.5D.28c.29/near/123",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
run_test("get_topic_link_content_with_stream_id", () => {
|
||||
assert.deepEqual(
|
||||
topic_link_util.get_topic_link_content_with_stream_id({
|
||||
stream_id: sweden_stream.stream_id,
|
||||
topic_name: "abc",
|
||||
message_id: 123,
|
||||
}),
|
||||
{
|
||||
label_text_markdown: "#Sweden > abc @ 💬",
|
||||
label_text_plain: "#Sweden > abc @ 💬",
|
||||
url: "#narrow/channel/1-Sweden/topic/abc/near/123",
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
topic_link_util.get_topic_link_content_with_stream_id({
|
||||
stream_id: sweden_stream.stream_id,
|
||||
topic_name: "<abc>",
|
||||
message_id: 123,
|
||||
}),
|
||||
{
|
||||
label_text_markdown: "#Sweden > <abc> @ 💬",
|
||||
label_text_plain: "#Sweden > <abc> @ 💬",
|
||||
url: "#narrow/channel/1-Sweden/topic/.3Cabc.3E/near/123",
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user