Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
input_pill: Add test for `input` event handler.
Lalit5ea98cba545e
diff --git a/web/tests/input_pill.test.js b/web/tests/input_pill.test.jsindex 4748c65e3bb..55bb0d276f4 100644--- a/web/tests/input_pill.test.js+++ b/web/tests/input_pill.test.js@@ -643,7 +643,7 @@ run_test("appendValue/clear", ({mock_template}) => {assert.equal($pill_input[0].textContent, "");});-run_test("getCurrentText/onTextInputHook", ({mock_template}) => {+run_test("getCurrentText", ({mock_template}) => {mock_template("input_pill.hbs", true, (data, html) => {assert.equal(typeof data.display_value, "string");return html;@@ -659,15 +659,10 @@ run_test("getCurrentText/onTextInputHook", ({mock_template}) => {widget.appendValue("blue,red");assert.deepEqual(widget.items(), [items.blue, items.red]);- const onTextInputHook = () => {- assert.deepEqual(widget.items(), [items.blue, items.red]);- };- widget.onTextInputHook(onTextInputHook);-$pill_input.text("yellow");assert.equal(widget.getCurrentText(), "yellow");- const key_handler = $container.get_on_handler("input", ".input");+ const key_handler = $container.get_on_handler("keydown", ".input");key_handler({key: " ",preventDefault: noop,@@ -677,5 +672,35 @@ run_test("getCurrentText/onTextInputHook", ({mock_template}) => {preventDefault: noop,});- assert.deepEqual(widget.items(), [items.blue, items.red]);+ assert.deepEqual(widget.items(), [items.blue, items.red, items.yellow]);+});++run_test("onTextInputHook", () => {+ const info = set_up();+ const config = info.config;+ const widget = input_pill.create(config);+ const $container = info.$container;+ const $pill_input = info.$pill_input;++ let hookCalled = false;+ let currentText = "re";+ const onTextInputHook = () => {+ hookCalled = true;++ // Test that the hook always gets the correct updated text.+ assert.equal(widget.getCurrentText(), currentText);+ };++ widget.onTextInputHook(onTextInputHook);++ const input_handler = $container.get_on_handler("input", ".input");++ $pill_input.text(currentText);+ input_handler();++ currentText += "d";+ $pill_input.text(currentText);+ input_handler();++ assert.ok(hookCalled);});