2022-02-25 19:34:01 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
|
|
|
const {run_test} = require("../zjsunit/test");
|
|
|
|
|
|
|
|
const internal_url = zrequire("../shared/js/internal_url");
|
|
|
|
|
|
|
|
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);
|
2022-02-28 23:44:25 +01:00
|
|
|
assert.equal(result, "#narrow/stream/123-a-test-stream");
|
|
|
|
});
|
|
|
|
|
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);
|
2022-02-28 23:44:25 +01:00
|
|
|
assert.equal(result, "#narrow/stream/123-a-test-stream/topic/test.20topic");
|
|
|
|
});
|