"use strict"; const assert = require("node:assert/strict"); const {zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); const copy_and_paste = zrequire("copy_and_paste"); const stream_data = zrequire("stream_data"); stream_data.add_sub({ stream_id: 4, name: "Rome", }); stream_data.add_sub({ stream_id: 5, name: "Romeo`s lair", }); run_test("try_stream_topic_syntax_text", () => { const test_cases = [ [ "http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/old.20FAILED.20EXPORT", "#**Rome>old FAILED EXPORT**", ], [ "http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/100.25.20profits", "#**Rome>100% profits**", ], [ "http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/old.20API.20wasn't.20compiling.20erratically", "#**Rome>old API wasn't compiling erratically**", ], ["http://different.origin.com/#narrow/channel/4-Rome/topic/old.20FAILED.20EXPORT"], // malformed urls ["http://zulip.zulipdev.com/narrow/channel/4-Rome/topic/old.20FAILED.20EXPORT"], ["http://zulip.zulipdev.com/#not_narrow/channel/4-Rome/topic/old.20FAILED.20EXPORT"], ["http://zulip.zulipdev.com/#narrow/not_stream/4-Rome/topic/old.20FAILED.20EXPORT"], ["http://zulip.zulipdev.com/#narrow/channel/4-Rome/not_topic/old.20FAILED.20EXPORT"], ["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/old.20FAILED.20EXPORT/near/100"], ["http://zulip.zulipdev.com/#narrow/channel/4-Rome/", "#**Rome**"], ["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic"], ["http://zulip.zulipdev.com/#narrow/topic/cheese"], ["http://zulip.zulipdev.com/#narrow/topic/pizza/stream/Rome"], // When a url containing characters which are known to produce broken // #**stream>topic** urls is pasted, a normal markdown link syntax is produced. [ "http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/100.25.20profits.60", "[#Rome>100% profits`](#narrow/channel/4-Rome/topic/100.25.20profits.60)", ], [ "http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/100.25.20*profits", "[#Rome>100% *profits](#narrow/channel/4-Rome/topic/100.25.20*profits)", ], [ "http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/.24.24 100.25.20profits", "[#Rome>$$ 100% profits](#narrow/channel/4-Rome/topic/.24.24.20100.25.20profits)", ], [ "http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/>100.25.20profits", "[#Rome>>100% profits](#narrow/channel/4-Rome/topic/.3E100.25.20profits)", ], [ "http://zulip.zulipdev.com/#narrow/stream/5-Romeo.60s-lair/topic/normal", "[#Romeo`s lair>normal](#narrow/channel/5-Romeo.60s-lair/topic/normal)", ], ]; for (const test_case of test_cases) { const result = copy_and_paste.try_stream_topic_syntax_text(test_case[0]); const expected = test_case[1] ?? null; assert.equal(result, expected, "Failed for url: " + test_case[0]); } }); run_test("maybe_transform_html", () => { // Copied HTML from VS Code let paste_html = `
" + escaped_paste_text + "
";
assert.equal(copy_and_paste.maybe_transform_html(paste_html, paste_text), expected_output);
// Untransformed HTML
paste_html = "JSDOM
constructor';
assert.equal(copy_and_paste.paste_handler_converter(input), "The `JSDOM` constructor");
// A python code block
input = `zulip code block in python
print("hello")\nprint("world")
single line
';
assert.equal(copy_and_paste.paste_handler_converter(input), "`single line`");
// Raw links without custom text
input =
'https://zulip.readthedocs.io/en/latest/subsystems/logging.html';
assert.equal(
copy_and_paste.paste_handler_converter(input),
"https://zulip.readthedocs.io/en/latest/subsystems/logging.html",
);
// Links with custom text
input =
'Contributing guide';
assert.equal(
copy_and_paste.paste_handler_converter(input),
"[Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)",
);
// Only numbered list (list style retained)
input =
'normal text
'; assert.equal(copy_and_paste.paste_handler_converter(input), "# Zulip overview\n\nnormal text"); // Only heading (strip heading style) input = 'paragraph 1
paragraph 2
'; assert.equal(copy_and_paste.paste_handler_converter(input), "paragraph 1\n\nparagraph 2"); // Pasting from external sources // Pasting list from GitHub input = '
Test list: