From df88291d980d5a9ea9e62dd0873b2f36845565d0 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 27 Jun 2021 13:13:19 +0000 Subject: [PATCH] node tests: Use mock_template for input_pill. --- frontend_tests/node_tests/input_pill.js | 69 ++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index 847416153e..eca25f6d4d 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, mock_template, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const blueslip = require("../zjsunit/zblueslip"); const $ = require("../zjsunit/zjquery"); @@ -20,6 +20,8 @@ set_global("getSelection", () => ({ anchorOffset: 0, })); +const render_input_pill = mock_template("input_pill", true); + const input_pill = zrequire("input_pill"); function pill_html(value, data_id, img_src) { @@ -52,6 +54,11 @@ run_test("random_id", () => { }); run_test("basics", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(data.display_value, "JavaScript"); + return html; + }); + override_random_id({override}); const config = {}; @@ -143,6 +150,11 @@ function set_up() { } run_test("copy from pill", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.ok(["BLUE", "RED"].includes(data.display_value)); + return html; + }); + override_random_id({override}); const info = set_up(); const config = info.config; @@ -181,7 +193,12 @@ run_test("copy from pill", ({override}) => { assert.equal(copied_text, "RED"); }); -run_test("paste to input", () => { +run_test("paste to input", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.has_image, "boolean"); + return html; + }); + const info = set_up(); const config = info.config; const container = info.container; @@ -223,7 +240,12 @@ run_test("paste to input", () => { assert.ok(entered); }); -run_test("arrows on pills", () => { +run_test("arrows on pills", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.has_image, "boolean"); + return html; + }); + const info = set_up(); const config = info.config; const container = info.container; @@ -271,7 +293,12 @@ run_test("arrows on pills", () => { assert.ok(next_focused); }); -run_test("left arrow on input", () => { +run_test("left arrow on input", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + return html; + }); + const info = set_up(); const config = info.config; const container = info.container; @@ -300,7 +327,12 @@ run_test("left arrow on input", () => { assert.ok(last_pill_focused); }); -run_test("comma", () => { +run_test("comma", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + return html; + }); + const info = set_up(); const config = info.config; const items = info.items; @@ -333,7 +365,12 @@ run_test("comma", () => { assert.deepEqual(widget.items(), [items.blue, items.red, items.yellow]); }); -run_test("Enter key with text", () => { +run_test("Enter key with text", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + return html; + }); + const info = set_up(); const config = info.config; const items = info.items; @@ -359,6 +396,12 @@ run_test("Enter key with text", () => { }); run_test("insert_remove", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + assert.ok(html.startsWith, "
{ }); run_test("exit button on pill", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + assert.ok(html.startsWith, "
{ container_click_handler.call(this_, {target: this_}); }); -run_test("appendValue/clear", () => { +run_test("appendValue/clear", ({override}) => { + override(render_input_pill, "f", (data, html) => { + assert.equal(typeof data.display_value, "string"); + assert.ok(html.startsWith, "