"use strict"; const {strict: assert} = require("assert"); const {JSDOM} = require("jsdom"); const {mock_esm, set_global, zrequire} = require("./lib/namespace"); const jquery = require("./lib/real_jquery"); const {run_test} = require("./lib/test"); const {page_params} = require("./lib/zpage_params"); const {window} = new JSDOM("
Hello world
"); const {document} = window; const $ = jquery(window); const compose_ui = mock_esm("../src/compose_ui"); set_global("document", document); const copy_and_paste = zrequire("copy_and_paste"); // Super stripped down version of the code in the drag-mock library // https://github.com/andywer/drag-mock/blob/6d46c7c0ffd6a4d685e6612a90cd58cda80f30fc/src/DataTransfer.js class DataTransfer { dataByFormat = {}; getData(dataFormat) { return this.dataByFormat[dataFormat]; } setData(dataFormat, data) { this.dataByFormat[dataFormat] = data; } } const createPasteEvent = function () { const clipboardData = new DataTransfer(); const pasteEvent = new window.Event("paste"); pasteEvent.clipboardData = clipboardData; return new $.Event(pasteEvent); }; run_test("paste_handler", () => { page_params.development_environment = true; let input = ' love the Zulip Organization.'; assert.equal( copy_and_paste.paste_handler_converter(input), " love the **Zulip** **Organization**.", ); input = 'TheJSDOM
constructor';
assert.equal(copy_and_paste.paste_handler_converter(input), "The `JSDOM` constructor");
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",
);
input =
'Contributing guide';
assert.equal(
copy_and_paste.paste_handler_converter(input),
"[Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)",
);
input =
'1. text';
assert.equal(copy_and_paste.paste_handler_converter(input), "1. text");
input =
'text
"; let event = createPasteEvent(); event.originalEvent.clipboardData.setData("text/html", data); let insert_syntax_and_focus_called = false; compose_ui.insert_syntax_and_focus = function () { insert_syntax_and_focus_called = true; }; copy_and_paste.paste_handler(event); assert.ok(insert_syntax_and_focus_called); data = ''; event = createPasteEvent(); event.originalEvent.clipboardData.setData("text/html", data); insert_syntax_and_focus_called = false; copy_and_paste.paste_handler(event); assert.ok(!insert_syntax_and_focus_called); });
Test list: