2024-06-10 09:02:16 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2024-06-10 09:02:16 +02:00
|
|
|
|
2024-11-12 03:59:37 +01:00
|
|
|
const {zrequire} = require("./lib/namespace.js");
|
|
|
|
const {run_test} = require("./lib/test.js");
|
2024-06-10 09:02:16 +02:00
|
|
|
|
|
|
|
const topic_link_util = zrequire("topic_link_util");
|
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
|
|
|
|
const sweden_stream = {
|
|
|
|
name: "Sweden",
|
|
|
|
description: "Cold, mountains and home decor.",
|
|
|
|
stream_id: 1,
|
|
|
|
subscribed: true,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
|
|
|
const denmark_stream = {
|
|
|
|
name: "Denmark",
|
|
|
|
description: "Vikings and boats, in a serene and cold weather.",
|
|
|
|
stream_id: 2,
|
|
|
|
subscribed: true,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
|
|
|
const dollar_stream = {
|
|
|
|
name: "$$MONEY$$",
|
|
|
|
description: "Money money money",
|
|
|
|
stream_id: 6,
|
|
|
|
subscribed: true,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_data.add_sub(sweden_stream);
|
|
|
|
stream_data.add_sub(denmark_stream);
|
|
|
|
stream_data.add_sub(dollar_stream);
|
|
|
|
|
|
|
|
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>to", "topic"),
|
|
|
|
"#**Sweden>topic**",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>t", "test `test` test"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > test `test` test](#narrow/channel/1-Sweden/topic/test.20.60test.60.20test)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Denmark>t", "test `test` test`s"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Denmark > test `test` test`s](#narrow/channel/2-Denmark/topic/test.20.60test.60.20test.60s)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>typeah", "error due to *"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > error due to *](#narrow/channel/1-Sweden/topic/error.20due.20to.20*)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>t", "*asterisk"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > *asterisk](#narrow/channel/1-Sweden/topic/*asterisk)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>gibberish", "greaterthan>"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > greaterthan>](#narrow/channel/1-Sweden/topic/greaterthan.3E)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**$$MONEY$$>t", "dollar"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#$$MONEY$$ > dollar](#narrow/channel/6-.24.24MONEY.24.24/topic/dollar)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>t", "swe$$dish"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > swe$$dish](#narrow/channel/1-Sweden/topic/swe.24.24dish)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_fallback_markdown_link("Sweden"),
|
2024-10-03 18:37:58 +02:00
|
|
|
"[#Sweden](#narrow/channel/1-Sweden)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_fallback_markdown_link("$$MONEY$$"),
|
2024-10-03 18:37:58 +02:00
|
|
|
"[#$$MONEY$$](#narrow/channel/6-.24.24MONEY.24.24)",
|
2024-06-10 09:02:16 +02:00
|
|
|
);
|
|
|
|
|
2024-10-19 18:23:56 +02:00
|
|
|
assert.equal(
|
|
|
|
topic_link_util.get_stream_topic_link_syntax("#**Sweden>&ab", "&ab"),
|
2024-10-27 14:41:28 +01:00
|
|
|
"[#Sweden > &ab](#narrow/channel/1-Sweden/topic/.26ab)",
|
2024-10-19 18:23:56 +02:00
|
|
|
);
|
|
|
|
|
2024-06-10 09:02:16 +02:00
|
|
|
// Only for full coverage of the module.
|
|
|
|
assert.equal(topic_link_util.escape_invalid_stream_topic_characters("Sweden"), "Sweden");
|
|
|
|
});
|