zjquery: Remove bogus remove().

This commit is contained in:
Steve Howell 2021-02-25 15:07:04 +00:00 committed by Steve Howell
parent bd034f5767
commit 5437a16602
10 changed files with 52 additions and 4 deletions

View File

@ -517,6 +517,11 @@ test_ui("insert_fred_then_alice_then_rename", (override) => {
inserted_html = html; inserted_html = html;
}; };
let fred_removed;
fred_stub.remove = () => {
fred_removed = true;
};
activity.redraw_user(alice.user_id); activity.redraw_user(alice.user_id);
assert(inserted_html.indexOf('data-user-id="1"') > 0); assert(inserted_html.indexOf('data-user-id="1"') > 0);
assert(inserted_html.indexOf("user_circle_green") > 0); assert(inserted_html.indexOf("user_circle_green") > 0);
@ -537,6 +542,7 @@ test_ui("insert_fred_then_alice_then_rename", (override) => {
}; };
activity.redraw_user(fred_with_new_name.user_id); activity.redraw_user(fred_with_new_name.user_id);
assert(fred_removed);
assert(appended_html.indexOf('data-user-id="2"') > 0); assert(appended_html.indexOf('data-user-id="2"') > 0);
// restore old Fred data // restore old Fred data

View File

@ -26,6 +26,8 @@ run_test("render_alert_words_ui", () => {
const alert_word_items = $.create("alert_word_items"); const alert_word_items = $.create("alert_word_items");
word_list.set_find_results(".alert-word-item", alert_word_items); word_list.set_find_results(".alert-word-item", alert_word_items);
alert_word_items.remove = () => {};
stub_templates((name, args) => { stub_templates((name, args) => {
assert.equal(name, "settings/alert_word_settings_item"); assert.equal(name, "settings/alert_word_settings_item");
return "stub-" + args.word; return "stub-" + args.word;

View File

@ -32,6 +32,11 @@ run_test("copy_data_attribute_value", (override) => {
const input = $.create("input"); const input = $.create("input");
let removed;
input.remove = () => {
removed = true;
};
override(document, "createElement", () => input); override(document, "createElement", () => input);
override(document, "execCommand", noop); override(document, "execCommand", noop);
@ -60,6 +65,7 @@ run_test("copy_data_attribute_value", (override) => {
faded_in = true; faded_in = true;
}; };
common.copy_data_attribute_value(elem, "admin-emails"); common.copy_data_attribute_value(elem, "admin-emails");
assert(removed);
assert(faded_in); assert(faded_in);
assert(faded_out); assert(faded_out);
}); });

View File

@ -314,7 +314,7 @@ test_ui("validate", () => {
assert.equal($("#compose-error-msg").html(), i18n.t("Please specify a topic")); assert.equal($("#compose-error-msg").html(), i18n.t("Please specify a topic"));
}); });
test_ui("get_invalid_recipient_emails", () => { test_ui("get_invalid_recipient_emails", (override) => {
const welcome_bot = { const welcome_bot = {
email: "welcome-bot@example.com", email: "welcome-bot@example.com",
user_id: 124, user_id: 124,
@ -330,7 +330,7 @@ test_ui("get_invalid_recipient_emails", () => {
people.initialize(page_params.user_id, params); people.initialize(page_params.user_id, params);
compose_state.private_message_recipient("welcome-bot@example.com"); override(compose_state, "private_message_recipient", () => "welcome-bot@example.com");
assert.deepEqual(compose.get_invalid_recipient_emails(), []); assert.deepEqual(compose.get_invalid_recipient_emails(), []);
}); });

View File

@ -403,6 +403,18 @@ run_test("insert_remove", () => {
assert.equal(pill_input.text(), ""); assert.equal(pill_input.text(), "");
assert.equal(widget.is_pending(), false); assert.equal(widget.is_pending(), false);
let color_removed;
function set_colored_removed_func(color) {
return () => {
color_removed = color;
};
}
const pills = widget._get_pills_for_testing();
for (const pill of pills) {
pill.$element.remove = set_colored_removed_func(pill.item.display_value);
}
const BACKSPACE = 8; const BACKSPACE = 8;
let key_handler = container.get_on_handler("keydown", ".input"); let key_handler = container.get_on_handler("keydown", ".input");
@ -415,6 +427,7 @@ run_test("insert_remove", () => {
}); });
assert(removed); assert(removed);
assert.equal(color_removed, "YELLOW");
assert.deepEqual(widget.items(), [items.blue, items.red]); assert.deepEqual(widget.items(), [items.blue, items.red]);
@ -444,6 +457,7 @@ run_test("insert_remove", () => {
preventDefault: noop, preventDefault: noop,
}); });
assert.equal(color_removed, "BLUE");
assert(next_pill_focused); assert(next_pill_focused);
}); });
@ -458,6 +472,11 @@ run_test("exit button on pill", () => {
widget.appendValue("blue,red"); widget.appendValue("blue,red");
const pills = widget._get_pills_for_testing();
for (const pill of pills) {
pill.$element.remove = () => {};
}
let next_pill_focused = false; let next_pill_focused = false;
const next_pill_stub = { const next_pill_stub = {

View File

@ -56,6 +56,8 @@ run_test("settings", () => {
return topic_tr_html; return topic_tr_html;
}; };
topic_tr_html.remove = () => {};
let topic_data_called = 0; let topic_data_called = 0;
topic_tr_html.attr = (opts) => { topic_tr_html.attr = (opts) => {
if (opts === "data-stream-id") { if (opts === "data-stream-id") {

View File

@ -99,7 +99,9 @@ run_test("unloaded", () => {
}); });
function simulate_realm_domains_table() { function simulate_realm_domains_table() {
$("#realm_domains_table tbody").set_find_results("tr", $.create("realm-tr-stub")); const tr_stub = $.create("realm-tr-stub");
$("#realm_domains_table tbody").set_find_results("tr", tr_stub);
tr_stub.remove = () => {};
let appended; let appended;
$("#realm_domains_table tbody").append = (html) => { $("#realm_domains_table tbody").append = (html) => {

View File

@ -54,6 +54,9 @@ function test_populate(opts) {
table[0] = "stub"; table[0] = "stub";
rows.remove = () => {};
form.remove = () => {};
let num_appends = 0; let num_appends = 0;
table.append = () => { table.append = () => {
num_appends += 1; num_appends += 1;

View File

@ -22,6 +22,7 @@ const get_spoiler_elem = (title) => {
const block = $.create(`block-${title}`); const block = $.create(`block-${title}`);
const header = $.create(`header-${title}`); const header = $.create(`header-${title}`);
const content = $.create(`content-${title}`); const content = $.create(`content-${title}`);
content.remove = () => {};
header.text(title); header.text(title);
block.set_find_results(".spoiler-header", header); block.set_find_results(".spoiler-header", header);
block.set_find_results(".spoiler-content", content); block.set_find_results(".spoiler-content", content);

View File

@ -342,7 +342,14 @@ function make_new_elem(selector, opts) {
return self; return self;
}, },
remove() { remove() {
return self; throw new Error(`
We don't support remove in zjuery.
You can do $(...).remove = ... if necessary.
But you are probably writing too deep a test
for node testing.
`);
}, },
removeData: noop, removeData: noop,
replaceWith() { replaceWith() {