2022-02-25 19:34:01 +01:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2022-02-25 19:34:01 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2022-02-25 19:34:01 +01:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const internal_url = zrequire("../shared/src/internal_url");
|
2022-02-25 19:34:01 +01:00
|
|
|
|
|
|
|
run_test("test encodeHashComponent", () => {
|
|
|
|
const decoded = "https://www.zulipexample.com";
|
|
|
|
const encoded = "https.3A.2F.2Fwww.2Ezulipexample.2Ecom";
|
|
|
|
const result = internal_url.encodeHashComponent(decoded);
|
|
|
|
assert.equal(result, encoded);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("test decodeHashComponent", () => {
|
|
|
|
const decoded = "https://www.zulipexample.com";
|
|
|
|
const encoded = "https.3A.2F.2Fwww.2Ezulipexample.2Ecom";
|
|
|
|
const result = internal_url.decodeHashComponent(encoded);
|
|
|
|
assert.equal(result, decoded);
|
|
|
|
});
|
2022-02-28 22:04:13 +01:00
|
|
|
|
|
|
|
run_test("test stream_id_to_slug", () => {
|
|
|
|
const maybe_get_stream_name = () => "onetwo three";
|
|
|
|
const result = internal_url.stream_id_to_slug(123, maybe_get_stream_name);
|
|
|
|
assert.equal(result, "123-onetwo-three");
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("test stream_id_to_slug failed lookup", () => {
|
|
|
|
const maybe_get_stream_name = () => undefined;
|
|
|
|
const result = internal_url.stream_id_to_slug(123, maybe_get_stream_name);
|
|
|
|
assert.equal(result, "123-unknown");
|
|
|
|
});
|
2022-02-28 23:12:26 +01:00
|
|
|
|
|
|
|
run_test("test encode_stream_id", () => {
|
|
|
|
const maybe_get_stream_name = () => "stream (with brackets)";
|
|
|
|
const result = internal_url.encode_stream_id(123, maybe_get_stream_name);
|
|
|
|
assert.equal(result, "123-stream-.28with-brackets.29");
|
|
|
|
});
|
2022-02-28 23:44:25 +01:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
run_test("test by_stream_url", () => {
|
2022-02-28 23:44:25 +01:00
|
|
|
const maybe_get_stream_name = () => "a test stream";
|
2022-03-01 19:14:26 +01:00
|
|
|
const result = internal_url.by_stream_url(123, maybe_get_stream_name);
|
2024-10-03 18:37:58 +02:00
|
|
|
assert.equal(result, "#narrow/channel/123-a-test-stream");
|
2022-02-28 23:44:25 +01:00
|
|
|
});
|
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
run_test("test by_stream_topic_url", () => {
|
2022-02-28 23:44:25 +01:00
|
|
|
const maybe_get_stream_name = () => "a test stream";
|
2022-03-01 19:14:26 +01:00
|
|
|
const result = internal_url.by_stream_topic_url(123, "test topic", maybe_get_stream_name);
|
2024-10-03 18:37:58 +02:00
|
|
|
assert.equal(result, "#narrow/channel/123-a-test-stream/topic/test.20topic");
|
2022-02-28 23:44:25 +01:00
|
|
|
});
|