From a3b573a07c40d9c8c4f4e609bbfc52d7b925633f Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 26 Aug 2018 15:15:12 +0000 Subject: [PATCH] tests: Test pasting into pill input area. --- frontend_tests/node_tests/input_pill.js | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index 03108461d9..1feae93403 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -7,6 +7,7 @@ zrequire('templates'); global.compile_template('input_pill'); set_global('blueslip', global.make_zblueslip()); +set_global('document', {}); var noop = function () {}; var example_img_link = 'http://example.com/example.png'; @@ -183,6 +184,43 @@ run_test('copy from pill', () => { assert.equal(copied_text, 'RED'); }); +run_test('paste to input', () => { + const info = set_up(); + const config = info.config; + const container = info.container; + const items = info.items; + + const widget = input_pill.create(config); + + const paste_handler = container.get_on_handler('paste', '.input'); + + var paste_text = 'blue,yellow'; + + const e = { + originalEvent: { + clipboardData: { + getData: (format) => { + assert.equal(format, 'text/plain'); + return paste_text; + }, + }, + }, + preventDefault: noop, + }; + + document.execCommand = (cmd, _, text) => { + assert.equal(cmd, 'insertText'); + container.find('.input').text(text); + }; + + paste_handler(e); + + assert.deepEqual(widget.items(), [ + items.blue, + items.yellow, + ]); +}); + run_test('left arrow on input', () => { const info = set_up(); const config = info.config;