Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zjquery: Move before method to FakeElement.
Anders Kaseorga5a4749250b9
diff --git a/web/tests/activity.test.cjs b/web/tests/activity.test.cjsindex 82cc0741835..98cea772307 100644--- a/web/tests/activity.test.cjs+++ b/web/tests/activity.test.cjs@@ -463,9 +463,9 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({overriassert.ok($users_matching_view_appended.selector.includes('data-user-id="2"'));assert.ok($users_matching_view_appended.selector.includes("user-circle-active"));- let $inserted;- $fred_stub.before = ($element) => {- $inserted = $element;+ let inserted;+ $fred_stub[0].before = (element) => {+ inserted = element;};let fred_removed;@@ -474,8 +474,8 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({overri};activity_ui.redraw_user(alice.user_id);- assert.ok($inserted.selector.includes('data-user-id="1"'));- assert.ok($inserted.selector.includes("user-circle-active"));+ assert.ok(inserted.innerHTML.includes('data-user-id="1"'));+ assert.ok(inserted.innerHTML.includes("user-circle-active"));// Next rename fred to Aaron.const fred_with_new_name = {@@ -485,8 +485,8 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({overri};people.add_active_user(fred_with_new_name);- $alice_stub.before = ($element) => {- $inserted = $element;+ $alice_stub[0].before = (element) => {+ inserted = element;};activity_ui.redraw_user(fred_with_new_name.user_id);@@ -515,9 +515,9 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override}) =>assert.ok($other_users_appended.selector.includes('data-user-id="2"'));assert.ok($other_users_appended.selector.includes("user-circle-active"));- let $inserted;- $fred_stub.before = ($element) => {- $inserted = $element;+ let inserted;+ $fred_stub[0].before = (element) => {+ inserted = element;};let fred_removed;@@ -526,8 +526,8 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override}) =>};activity_ui.redraw_user(alice.user_id);- assert.ok($inserted.selector.includes('data-user-id="1"'));- assert.ok($inserted.selector.includes("user-circle-active"));+ assert.ok(inserted.innerHTML.includes('data-user-id="1"'));+ assert.ok(inserted.innerHTML.includes("user-circle-active"));// Next rename fred to Aaron.const fred_with_new_name = {@@ -537,8 +537,8 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override}) =>};people.add_active_user(fred_with_new_name);- $alice_stub.before = ($element) => {- $inserted = $element;+ $alice_stub[0].before = (element) => {+ inserted = element;};activity_ui.redraw_user(fred_with_new_name.user_id);diff --git a/web/tests/compose_validate.test.cjs b/web/tests/compose_validate.test.cjsindex 2c645d2168a..127ee7a106b 100644--- a/web/tests/compose_validate.test.cjs+++ b/web/tests/compose_validate.test.cjs@@ -165,7 +165,7 @@ function initialize_pm_pill(mock_template) {const $pm_pill_container = $.create("fake-pm-pill-container");$("#private_message_recipient").set_parent($pm_pill_container);$pm_pill_container.set_find_results(".input", $("#private_message_recipient"));- $("#private_message_recipient").before = noop;+ $("#private_message_recipient")[0].before = noop;compose_pm_pill.initialize({on_pill_create_or_remove: compose_recipient.update_compose_area_placeholder_text,diff --git a/web/tests/input_pill.test.cjs b/web/tests/input_pill.test.cjsindex 7638d2ac988..2ab33c4ca2a 100644--- a/web/tests/input_pill.test.cjs+++ b/web/tests/input_pill.test.cjs@@ -54,9 +54,9 @@ run_test("basics", ({mock_template}) => {let inserted_before;const expected_html = pill_html("JavaScript");- $pill_input.before = ($elem) => {+ $pill_input[0].before = (element) => {inserted_before = true;- assert.equal($elem.html(), expected_html);+ assert.equal(element.innerHTML, expected_html);};widget.appendValidatedData(item);@@ -88,7 +88,7 @@ function set_up() {};const $pill_input = $.create("pill_input");- $pill_input.before = noop;+ $pill_input[0].before = noop;const create_item_from_text = (text) => items[text];@@ -345,8 +345,8 @@ run_test("insert_remove", ({mock_template}) => {const $container = info.$container;const inserted_html = [];- $pill_input.before = ($elem) => {- inserted_html.push($elem.html());+ $pill_input[0].before = (element) => {+ inserted_html.push(element.innerHTML);};const widget = input_pill.create(config);@@ -574,7 +574,7 @@ run_test("appendValue/clear", ({mock_template}) => {get_display_value_from_item: (s) => s.color_name,};- $pill_input.before = noop;+ $pill_input[0].before = noop;const widget = input_pill.create(config);diff --git a/web/tests/lib/zjquery_element.cjs b/web/tests/lib/zjquery_element.cjsindex d461824b823..da819bfb99c 100644--- a/web/tests/lib/zjquery_element.cjs+++ b/web/tests/lib/zjquery_element.cjs@@ -196,6 +196,13 @@ class FakeElement extends RejectMissing {}}+function dom_args(args) {+ return args.flat().flatMap((arg) => {+ assert.equal(typeof arg, "object");+ return arg.__zjquery ? [...arg] : [arg];+ });+}+// TODO: convert this to a true classexports.FakeJQuery = function (selector, opts) {const $self = {@@ -228,6 +235,11 @@ exports.FakeJQuery = function (selector, opts) {}return this;},+ before(...args) {+ assert.equal(this.length, 1);+ this[0].before(...dom_args(args));+ return this;+ },caret(...args) {if (args.length === 0) {return this[0]?.selectionStart;diff --git a/web/tests/pill_typeahead.test.cjs b/web/tests/pill_typeahead.test.cjsindex cf35a8bce73..0948584c32b 100644--- a/web/tests/pill_typeahead.test.cjs+++ b/web/tests/pill_typeahead.test.cjs@@ -163,7 +163,7 @@ run_test("set_up_user", ({mock_template, override, override_rewire}) => {mock_template("input_pill.hbs", true, (_data, html) => html);let input_pill_typeahead_called = false;const $fake_input = $.create(".input");- $fake_input.before = noop;+ $fake_input[0].before = noop;const $container = $.create(".pill-container");$container.set_find_results(".input", $fake_input);@@ -255,7 +255,7 @@ run_test("set_up_stream", ({mock_template, override, override_rewire}) => {mock_template("input_pill.hbs", true, (_data, html) => html);let input_pill_typeahead_called = false;const $fake_input = $.create(".input");- $fake_input.before = noop;+ $fake_input[0].before = noop;const $container = $.create(".pill-container");$container.set_find_results(".input", $fake_input);@@ -348,7 +348,7 @@ run_test("set_up_user_group", ({mock_template, override, override_rewire}) => {let input_pill_typeahead_called = false;const $fake_input = $.create(".input");- $fake_input.before = noop;+ $fake_input[0].before = noop;const $container = $.create(".pill-container");$container.set_find_results(".input", $fake_input);@@ -440,7 +440,7 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {mock_template("input_pill.hbs", true, (_data, html) => html);let input_pill_typeahead_called = false;const $fake_input = $.create(".input");- $fake_input.before = noop;+ $fake_input[0].before = noop;const $container = $.create(".pill-container");$container.set_find_results(".input", $fake_input);@@ -700,7 +700,7 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_rlet input_pill_typeahead_called = false;const $fake_input = $.create(".input");- $fake_input.before = noop;+ $fake_input[0].before = noop;const $container = $.create(".pill-container");$container.set_find_results(".input", $fake_input);diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjsindex addd939d4c4..c817ef3eae1 100644--- a/web/tests/search.test.cjs+++ b/web/tests/search.test.cjs@@ -25,7 +25,7 @@ function stub_pills() {const $pill_container = $("#searchbox-input-container.pill-container");const $pill_input = $.create("pill_input");$pill_container.set_find_results(".input", $pill_input);- $pill_input.before = noop;+ $pill_input[0].before = noop;}set_global("getSelection", () => ({