global.stub_out_jquery(); set_global('page_params', { development_environment: true, }); set_global('compose_ui', {}); const { JSDOM } = require("jsdom"); const { window } = new JSDOM('

Hello world

'); const { document } = window; global.document = document; global.$ = require('jquery')(window); zrequire('toMarkdown', 'node_modules/to-markdown/dist/to-markdown.js'); var 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 var DataTransfer = function () { this.dataByFormat = {}; }; DataTransfer.prototype.getData = function (dataFormat) { return this.dataByFormat[dataFormat]; }; DataTransfer.prototype.setData = function (dataFormat, data) { this.dataByFormat[dataFormat] = data; }; var createPasteEvent = function () { var clipboardData = new DataTransfer(); var pasteEvent = new window.Event('paste'); pasteEvent.clipboardData = clipboardData; return $.Event(pasteEvent); }; run_test('paste_handler', () => { var input = ' love the Zulip Organization.'; assert.equal(copy_and_paste.paste_handler_converter(input), 'love the **Zulip****Organization**.'); input = 'The JSDOM 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 to Zulip'; assert.equal(copy_and_paste.paste_handler_converter(input), '[Contributing to Zulip](https://zulip.readthedocs.io/en/latest/overview/contributing.html)'); input = '1. text'; assert.equal(copy_and_paste.paste_handler_converter(input), '1. text'); input = '

Zulip overview

'; assert.equal(copy_and_paste.paste_handler_converter(input), 'Zulip overview'); input = 'This text is italic'; assert.equal(copy_and_paste.paste_handler_converter(input), '*This text is italic*'); input = '

Test List:

  • Item 1
  • Item 2
'; assert.equal(copy_and_paste.paste_handler_converter(input), 'Test List:\n* Item 1\n* Item 2'); input = '
Test List:
'; assert.equal(copy_and_paste.paste_handler_converter(input), 'Test List:\n* Item 1\n* Item 2'); var data = '

text

'; var event = createPasteEvent(); event.originalEvent.clipboardData.setData('text/html', data); var 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(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(!insert_syntax_and_focus_called); });