eslint: Fix no-jquery/no-append-html errors that need test changes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-04-03 15:53:08 -07:00 committed by Tim Abbott
parent 382af5f79f
commit 8fb1117cef
21 changed files with 158 additions and 133 deletions

View File

@ -162,6 +162,12 @@ js_rules = RuleList(
"web/tests/",
"web/src/billing/",
},
"exclude_line": {
(
"web/src/common.ts",
'$(this).before($("<kbd>").text("Fn"), $("<span>").text(" + ").contents());',
),
},
},
{
"pattern": r"""report.success\(["']""",

View File

@ -89,8 +89,8 @@ export function render_empty_user_list_message_if_needed($container: JQuery): vo
return;
}
const empty_list_widget = render_empty_list_widget_for_list({empty_list_message});
$container.append(empty_list_widget);
const empty_list_widget_html = render_empty_list_widget_for_list({empty_list_message});
$container.append($(empty_list_widget_html));
}
export function build_user_sidebar(): number[] | undefined {

View File

@ -437,7 +437,7 @@ export class BuddyList extends BuddyListConf {
items: subscribed_users,
});
this.$users_matching_view_container = $(this.matching_view_list_selector);
this.$users_matching_view_container.append(subscribed_users_html);
this.$users_matching_view_container.append($(subscribed_users_html));
// Remove the empty list message before adding users
if (
@ -450,7 +450,7 @@ export class BuddyList extends BuddyListConf {
items: other_users,
});
this.$other_users_container = $(this.other_user_list_selector);
this.$other_users_container.append(other_users_html);
this.$other_users_container.append($(other_users_html));
// Invariant: more_user_ids.length >= items.length.
// (Usually they're the same, but occasionally user ids
@ -477,16 +477,18 @@ export class BuddyList extends BuddyListConf {
) {
const stream_edit_hash = hash_util.stream_edit_url(current_sub, "subscribers");
$("#buddy-list-users-matching-view-container").append(
render_view_all_subscribers({
stream_edit_hash,
}),
$(
render_view_all_subscribers({
stream_edit_hash,
}),
),
);
}
// We give a link to view the list of all users to help reduce confusion about
// there being hidden (inactive) "other" users.
if (has_inactive_other_users) {
$("#buddy-list-other-users-container").append(render_view_all_users());
$("#buddy-list-other-users-container").append($(render_view_all_users()));
}
}
@ -689,9 +691,9 @@ export class BuddyList extends BuddyListConf {
if (new_pos_in_all_users === this.render_count) {
this.render_count += 1;
if (is_subscribed_user) {
this.$users_matching_view_container.append(html);
this.$users_matching_view_container.append($(html));
} else {
this.$other_users_container.append(html);
this.$other_users_container.append($(html));
}
this.update_padding();
}
@ -702,7 +704,7 @@ export class BuddyList extends BuddyListConf {
this.render_count += 1;
const $li = this.find_li({key: user_id_following_insertion});
assert($li !== undefined);
$li.before(html);
$li.before($(html));
this.update_padding();
}
}

View File

@ -65,7 +65,7 @@ export function adjust_mac_kbd_tags(kbd_elem_class: string): void {
let key_text = $(this).text();
if (fn_shortcuts.has(key_text)) {
$(this).before("<kbd>Fn</kbd> + ");
$(this).before($("<kbd>").text("Fn"), $("<span>").text(" + ").contents());
$(this).addClass("arrow-key");
}
@ -88,7 +88,7 @@ export function adjust_mac_kbd_tags(kbd_elem_class: string): void {
const following_key = $(this).attr("data-mac-following-key");
if (following_key !== undefined) {
const $kbd_elem = $("<kbd>").text(following_key);
$(this).after(" + ", $kbd_elem);
$(this).after($("<span>").text(" + ").contents(), $kbd_elem);
}
});
}

View File

@ -378,7 +378,7 @@ export function create<Key, Item = Key>(
// At this point, we have asserted we have all the information to replace
// the html now.
$html_item.replaceWith(html);
$html_item.replaceWith($(html));
},
clear() {

View File

@ -313,7 +313,9 @@ export class MessageListView {
_RENDER_THRESHOLD = 50;
_add_message_list_to_DOM() {
$("#message-lists-container").append(render_message_list({message_list_id: this.list.id}));
$("#message-lists-container").append(
$(render_message_list({message_list_id: this.list.id})),
);
}
_get_msg_timestring(message_container) {

View File

@ -8,7 +8,7 @@ import render_markdown_timestamp from "../templates/markdown_timestamp.hbs";
import * as blueslip from "./blueslip";
import {show_copied_confirmation} from "./copied_tooltip";
import {$t, $t_html} from "./i18n";
import {$t} from "./i18n";
import * as message_store from "./message_store";
import type {Message} from "./message_store";
import * as people from "./people";
@ -264,13 +264,13 @@ export const update_elements = ($content: JQuery): void => {
// If a spoiler block has no header content, it should have a default header.
// We do this client side to allow for i18n by the client.
if ($(this).html().trim().length === 0) {
$(this).append(`<p>${$t_html({defaultMessage: "Spoiler"})}</p>`);
$(this).append($("<p>").text($t({defaultMessage: "Spoiler"})));
}
// Add the expand/collapse button to spoiler blocks
const toggle_button_html =
'<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';
$(this).prepend(toggle_button_html);
$(this).prepend($(toggle_button_html));
});
// Display the view-code-in-playground and the copy-to-clipboard button inside the div.codehilite element,

View File

@ -681,23 +681,27 @@ export function do_populate_profile_fields(profile_fields_data) {
const display_in_profile_summary = profile_field.display_in_profile_summary === true;
const required = profile_field.required === true;
$profile_fields_table.append(
render_admin_profile_field_list({
profile_field: {
id: profile_field.id,
name: profile_field.name,
hint: profile_field.hint,
type: field_type_id_to_string(profile_field.type),
choices,
is_select_field: profile_field.type === field_types.SELECT.id,
is_external_account_field:
profile_field.type === field_types.EXTERNAL_ACCOUNT.id,
display_in_profile_summary,
valid_to_display_in_summary: is_valid_to_display_in_summary(profile_field.type),
required,
},
can_modify: current_user.is_admin,
realm_default_external_accounts: realm.realm_default_external_accounts,
}),
$(
render_admin_profile_field_list({
profile_field: {
id: profile_field.id,
name: profile_field.name,
hint: profile_field.hint,
type: field_type_id_to_string(profile_field.type),
choices,
is_select_field: profile_field.type === field_types.SELECT.id,
is_external_account_field:
profile_field.type === field_types.EXTERNAL_ACCOUNT.id,
display_in_profile_summary,
valid_to_display_in_summary: is_valid_to_display_in_summary(
profile_field.type,
),
required,
},
can_modify: current_user.is_admin,
realm_default_external_accounts: realm.realm_default_external_accounts,
}),
),
);
// Keeping counts of all display_in_profile_summary profile fields, to keep track.

View File

@ -402,7 +402,7 @@ export function zoom_in_topics(options: {stream_id: number | undefined}): void {
if (stream_id_for_elt($elt) === stream_id) {
$elt.show();
// Add search box for topics list.
$elt.children("div.bottom_left_row").append(render_filter_topics());
$elt.children("div.bottom_left_row").append($(render_filter_topics()));
$("#filter-topic-input").trigger("focus");
$("#clear_search_topic_button").hide();
} else {

View File

@ -7,7 +7,6 @@ import {
parseISO,
} from "date-fns";
import $ from "jquery";
import _ from "lodash";
import render_markdown_time_tooltip from "../templates/markdown_time_tooltip.hbs";
@ -343,8 +342,7 @@ function maybe_add_update_list_entry(entry: UpdateEntry): void {
}
function render_date_span($elem: JQuery, rendered_time: TimeRender): JQuery {
$elem.text("");
$elem.append(_.escape(rendered_time.time_str));
$elem.text(rendered_time.time_str);
return $elem.attr("data-tippy-content", rendered_time.formal_time_str);
}

View File

@ -1,3 +1,4 @@
import $ from "jquery";
import _ from "lodash";
import * as blueslip from "./blueslip";
@ -202,7 +203,7 @@ export function update<T>(
continue;
}
const rendered_dom = new_node.render();
$child_elems.eq(i).replaceWith(rendered_dom);
$child_elems.eq(i).replaceWith($(rendered_dom));
}
update_attrs(find(), new_opts.attrs, old_opts.attrs);

View File

@ -237,6 +237,7 @@ test("presence_list_full_update", ({override, mock_template}) => {
let presence_rows = [];
mock_template("presence_rows.hbs", false, (data) => {
presence_rows = [...presence_rows, ...data.presence_rows];
return "<presence-rows-stub>";
});
$("input.user-list-filter").trigger("focus");
@ -288,7 +289,7 @@ test("direct_message_update_dom_counts", () => {
test("handlers", ({override, override_rewire, mock_template}) => {
let filter_key_handlers;
mock_template("presence_rows.hbs", false, noop);
mock_template("presence_rows.hbs", false, () => "<presence-rows-stub>");
override(keydown_util, "handle", (opts) => {
filter_key_handlers = opts.handlers;
@ -402,7 +403,7 @@ test("handlers", ({override, override_rewire, mock_template}) => {
test("first/prev/next", ({override, override_rewire, mock_template}) => {
override_rewire(buddy_data, "user_matches_narrow", override_user_matches_narrow);
mock_template("presence_rows.hbs", false, noop);
mock_template("presence_rows.hbs", false, () => "<presence-rows-stub>");
override(padded_widget, "update_padding", noop);
stub_buddy_list_elements();
@ -480,13 +481,13 @@ test("render_empty_user_list_message", ({override, mock_template}) => {
const empty_list_message = "No matching users.";
mock_template("empty_list_widget_for_list.hbs", false, (data) => {
assert.equal(data.empty_list_message, empty_list_message);
return empty_list_message;
return "<empty-list-stub>";
});
let appended_data;
let $appended_data;
override(buddy_list, "$container", {
append(data) {
appended_data = data;
append($data) {
$appended_data = $data;
},
data() {
return empty_list_message;
@ -495,7 +496,7 @@ test("render_empty_user_list_message", ({override, mock_template}) => {
});
activity_ui.render_empty_user_list_message_if_needed(buddy_list.$container);
assert.equal(appended_data, empty_list_message);
assert.equal($appended_data.selector, "<empty-list-stub>");
});
test("insert_one_user_into_empty_list", ({override, mock_template}) => {
@ -523,13 +524,13 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
return html;
});
let users_matching_view_appended_html;
override(buddy_list.$users_matching_view_container, "append", (html) => {
users_matching_view_appended_html = html;
let $users_matching_view_appended;
override(buddy_list.$users_matching_view_container, "append", ($element) => {
$users_matching_view_appended = $element;
});
let other_users_appended_html;
override(buddy_list.$other_users_container, "append", (html) => {
other_users_appended_html = html;
let $other_users_appended;
override(buddy_list.$other_users_container, "append", ($element) => {
$other_users_appended = $element;
});
add_sub_and_set_as_current_narrow(rome_sub);
@ -537,33 +538,33 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
peer_data.set_subscribers(rome_sub.stream_id, [alice.user_id]);
activity_ui.redraw_user(alice.user_id);
assert.ok(users_matching_view_appended_html.includes('data-user-id="1"'));
assert.ok(users_matching_view_appended_html.includes("user_circle_green"));
assert.ok($users_matching_view_appended.selector.includes('data-user-id="1"'));
assert.ok($users_matching_view_appended.selector.includes("user_circle_green"));
clear_buddy_list(buddy_list);
buddy_list_add_other_user(alice.user_id, $alice_stub);
peer_data.set_subscribers(rome_sub.stream_id, []);
activity_ui.redraw_user(alice.user_id);
assert.ok(other_users_appended_html.includes('data-user-id="1"'));
assert.ok(other_users_appended_html.includes("user_circle_green"));
assert.ok($other_users_appended.selector.includes('data-user-id="1"'));
assert.ok($other_users_appended.selector.includes("user_circle_green"));
});
test("insert_alice_then_fred", ({override, mock_template}) => {
mock_template("presence_row.hbs", true, (_data, html) => html);
let other_users_appended_html;
override(buddy_list.$other_users_container, "append", (html) => {
other_users_appended_html = html;
let $other_users_appended;
override(buddy_list.$other_users_container, "append", ($element) => {
$other_users_appended = $element;
});
override(padded_widget, "update_padding", noop);
activity_ui.redraw_user(alice.user_id);
assert.ok(other_users_appended_html.includes('data-user-id="1"'));
assert.ok(other_users_appended_html.includes("user_circle_green"));
assert.ok($other_users_appended.selector.includes('data-user-id="1"'));
assert.ok($other_users_appended.selector.includes("user_circle_green"));
activity_ui.redraw_user(fred.user_id);
assert.ok(other_users_appended_html.includes('data-user-id="2"'));
assert.ok(other_users_appended_html.includes("user_circle_green"));
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
assert.ok($other_users_appended.selector.includes("user_circle_green"));
});
test("insert_fred_then_alice_then_rename, both as users matching view", ({
@ -575,21 +576,21 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({
add_sub_and_set_as_current_narrow(rome_sub);
peer_data.set_subscribers(rome_sub.stream_id, [alice.user_id, fred.user_id]);
let users_matching_view_appended_html;
override(buddy_list.$users_matching_view_container, "append", (html) => {
users_matching_view_appended_html = html;
let $users_matching_view_appended;
override(buddy_list.$users_matching_view_container, "append", ($element) => {
$users_matching_view_appended = $element;
});
override(padded_widget, "update_padding", noop);
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
buddy_list_add_user_matching_view(fred.user_id, $fred_stub);
activity_ui.redraw_user(fred.user_id);
assert.ok(users_matching_view_appended_html.includes('data-user-id="2"'));
assert.ok(users_matching_view_appended_html.includes("user_circle_green"));
assert.ok($users_matching_view_appended.selector.includes('data-user-id="2"'));
assert.ok($users_matching_view_appended.selector.includes("user_circle_green"));
let inserted_html;
$fred_stub.before = (html) => {
inserted_html = html;
let $inserted;
$fred_stub.before = ($element) => {
$inserted = $element;
};
let fred_removed;
@ -598,8 +599,8 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({
};
activity_ui.redraw_user(alice.user_id);
assert.ok(inserted_html.includes('data-user-id="1"'));
assert.ok(inserted_html.includes("user_circle_green"));
assert.ok($inserted.selector.includes('data-user-id="1"'));
assert.ok($inserted.selector.includes("user_circle_green"));
// Next rename fred to Aaron.
const fred_with_new_name = {
@ -609,13 +610,13 @@ test("insert_fred_then_alice_then_rename, both as users matching view", ({
};
people.add_active_user(fred_with_new_name);
$alice_stub.before = (html) => {
inserted_html = html;
$alice_stub.before = ($element) => {
$inserted = $element;
};
activity_ui.redraw_user(fred_with_new_name.user_id);
assert.ok(fred_removed);
assert.ok(users_matching_view_appended_html.includes('data-user-id="2"'));
assert.ok($users_matching_view_appended.selector.includes('data-user-id="2"'));
// restore old Fred data
people.add_active_user(fred);
@ -627,9 +628,9 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override, mock
add_sub_and_set_as_current_narrow(rome_sub);
peer_data.set_subscribers(rome_sub.stream_id, []);
let other_users_appended_html;
override(buddy_list.$other_users_container, "append", (html) => {
other_users_appended_html = html;
let $other_users_appended;
override(buddy_list.$other_users_container, "append", ($element) => {
$other_users_appended = $element;
});
override(padded_widget, "update_padding", noop);
@ -637,12 +638,12 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override, mock
buddy_list_add_other_user(fred.user_id, $fred_stub);
activity_ui.redraw_user(fred.user_id);
assert.ok(other_users_appended_html.includes('data-user-id="2"'));
assert.ok(other_users_appended_html.includes("user_circle_green"));
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
assert.ok($other_users_appended.selector.includes("user_circle_green"));
let inserted_html;
$fred_stub.before = (html) => {
inserted_html = html;
let $inserted;
$fred_stub.before = ($element) => {
$inserted = $element;
};
let fred_removed;
@ -651,8 +652,8 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override, mock
};
activity_ui.redraw_user(alice.user_id);
assert.ok(inserted_html.includes('data-user-id="1"'));
assert.ok(inserted_html.includes("user_circle_green"));
assert.ok($inserted.selector.includes('data-user-id="1"'));
assert.ok($inserted.selector.includes("user_circle_green"));
// Next rename fred to Aaron.
const fred_with_new_name = {
@ -662,13 +663,13 @@ test("insert_fred_then_alice_then_rename, both as other users", ({override, mock
};
people.add_active_user(fred_with_new_name);
$alice_stub.before = (html) => {
inserted_html = html;
$alice_stub.before = ($element) => {
$inserted = $element;
};
activity_ui.redraw_user(fred_with_new_name.user_id);
assert.ok(fred_removed);
assert.ok(other_users_appended_html.includes('data-user-id="2"'));
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
// restore old Fred data
people.add_active_user(fred);
@ -769,7 +770,7 @@ test("initialize", ({override, mock_template}) => {
buddy_list.$other_users_container = $("#buddy-list-other-users");
buddy_list.$other_users_container.append = noop;
stub_buddy_list_elements();
mock_template("empty_list_widget_for_list.hbs", false, noop);
mock_template("empty_list_widget_for_list.hbs", false, () => "<empty-list-stub>");
clear_buddy_list(buddy_list);
page_params.presences = {};
}

View File

@ -62,15 +62,15 @@ run_test("basics", ({override, mock_template}) => {
const buddy_list = new BuddyList();
init_simulated_scrolling();
override(buddy_list, "items_to_html", () => "html-stub");
override(buddy_list, "items_to_html", () => "<html-stub>");
override(message_viewport, "height", () => 550);
override(padded_widget, "update_padding", noop);
stub_buddy_list_elements();
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
let appended_to_users_matching_view;
$("#buddy-list-users-matching-view").append = (html) => {
assert.equal(html, "html-stub");
$("#buddy-list-users-matching-view").append = ($element) => {
assert.equal($element.selector, "<html-stub>");
appended_to_users_matching_view = true;
};
@ -98,29 +98,29 @@ run_test("split list", ({override, override_rewire, mock_template}) => {
const buddy_list = new BuddyList();
init_simulated_scrolling();
stub_buddy_list_elements();
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
override_rewire(buddy_data, "user_matches_narrow", override_user_matches_narrow);
override(buddy_list, "items_to_html", (opts) => {
if (opts.items.length > 0) {
return "html-stub";
return "<html-stub>";
}
return "empty-list";
return "<empty-list-stub>";
});
override(message_viewport, "height", () => 550);
override(padded_widget, "update_padding", noop);
let appended_to_users_matching_view = false;
$("#buddy-list-users-matching-view").append = (html) => {
if (html === "html-stub") {
$("#buddy-list-users-matching-view").append = ($element) => {
if ($element.selector === "<html-stub>") {
appended_to_users_matching_view = true;
}
};
let appended_to_other_users = false;
$("#buddy-list-other-users").append = (html) => {
if (html === "html-stub") {
$("#buddy-list-other-users").append = ($element) => {
if ($element.selector === "<html-stub>") {
appended_to_other_users = true;
}
};
@ -159,7 +159,7 @@ run_test("find_li", ({override, mock_template}) => {
const buddy_list = new BuddyList();
override(buddy_list, "fill_screen_with_content", noop);
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
stub_buddy_list_elements();
clear_buddy_list(buddy_list);
@ -182,7 +182,7 @@ run_test("fill_screen_with_content early break on big list", ({override, mock_te
const buddy_list = new BuddyList();
const elem = init_simulated_scrolling();
stub_buddy_list_elements();
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
let chunks_inserted = 0;
override(buddy_list, "render_more", () => {
@ -224,12 +224,12 @@ run_test("big_list", ({override, override_rewire, mock_template}) => {
override(padded_widget, "update_padding", noop);
override(message_viewport, "height", () => 550);
override_rewire(buddy_data, "user_matches_narrow", override_user_matches_narrow);
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
let items_to_html_call_count = 0;
override(buddy_list, "items_to_html", () => {
items_to_html_call_count += 1;
return "html-stub";
return "<html-stub>";
});
const num_users = 300;
@ -354,7 +354,7 @@ run_test("scrolling", ({override, mock_template}) => {
override(buddy_list, "fill_screen_with_content", () => {
tried_to_fill = true;
});
mock_template("buddy_list/view_all_users.hbs", false, noop);
mock_template("buddy_list/view_all_users.hbs", false, () => "<view-all-users-stub>");
stub_buddy_list_elements();
init_simulated_scrolling();
stub_buddy_list_elements();

View File

@ -98,9 +98,9 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => {
]);
const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]);
const inserted_fn_key = "<kbd>Fn</kbd> + ";
override(navigator, "platform", "MacIntel");
$("<span>").contents = () => $("<contents-stub>");
const test_items = [];
let key_no = 1;
@ -112,13 +112,13 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => {
assert.equal($stub.hasClass("arrow-key"), false);
if (fn_shortcuts.has(old_key)) {
$stub.before = ($elem) => {
assert.equal($elem, inserted_fn_key);
assert.equal($elem.selector, "<kbd>");
};
}
if (old_key === "data-mac-following-key") {
$stub.attr("data-mac-following-key", "⌥");
$stub.after = (plus, $elem) => {
assert.equal(plus, " + ");
$stub.after = ($plus, $elem) => {
assert.equal($plus.selector, "<contents-stub>");
assert.equal($elem.selector, "<kbd>");
assert.equal($elem.text(), $stub.attr("data-mac-following-key"));
};

View File

@ -686,8 +686,8 @@ run_test("render item", () => {
// Return a JQuery stub for the original HTML.
// We want this to be called when we replace
// the existing HTML with newly rendered HTML.
replaceWith(html) {
assert.equal(new_html, html);
replaceWith($element) {
assert.equal(new_html, $element.html());
called = true;
$container.$appended_data.replace(regex, new_html);
},

View File

@ -37,7 +37,7 @@ let next_timestamp = 1500000000;
function test(label, f) {
run_test(label, ({override, mock_template}) => {
muted_users.set_muted_users([]);
mock_template("message_list.hbs", false, noop);
mock_template("message_list.hbs", false, () => "<message-list-stub>");
f({override, mock_template});
});
}
@ -430,7 +430,7 @@ test("muted_message_vars", () => {
});
test("merge_message_groups", ({mock_template}) => {
mock_template("message_list.hbs", false, noop);
mock_template("message_list.hbs", false, () => "<message-list-stub>");
// MessageListView has lots of DOM code, so we are going to test the message
// group merging logic on its own.
@ -714,7 +714,7 @@ test("merge_message_groups", ({mock_template}) => {
});
test("render_windows", ({mock_template}) => {
mock_template("message_list.hbs", false, noop);
mock_template("message_list.hbs", false, () => "<message-list-stub>");
// We only render up to 400 messages at a time in our message list,
// and we only change the window (which is a range, really, with
// start/end) when the pointer moves outside of the window or close

View File

@ -2,6 +2,7 @@
const {strict: assert} = require("assert");
const {$t} = require("./lib/i18n");
const {mock_cjs, mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
@ -489,6 +490,10 @@ run_test("spoiler-header", () => {
const $content = get_content_element();
const $header = $.create("div.spoiler-header");
$content.set_find_results("div.spoiler-header", $array([$header]));
let $prepended;
$header.prepend = ($element) => {
$prepended = $element;
};
// Test that the show/hide button gets added to a spoiler header.
const label = "My spoiler header";
@ -496,7 +501,8 @@ run_test("spoiler-header", () => {
'<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';
$header.html(label);
rm.update_elements($content);
assert.equal(toggle_button_html + label, $header.html());
assert.equal(label, $header.html());
assert.equal($prepended.selector, toggle_button_html);
});
run_test("spoiler-header-empty-fill", () => {
@ -504,13 +510,23 @@ run_test("spoiler-header-empty-fill", () => {
const $content = get_content_element();
const $header = $.create("div.spoiler-header");
$content.set_find_results("div.spoiler-header", $array([$header]));
let $appended;
$header.append = ($element) => {
$appended = $element;
};
let $prepended;
$header.prepend = ($element) => {
$prepended = $element;
};
// Test that an empty header gets the default text applied (through i18n filter).
const toggle_button_html =
'<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';
$header.empty();
rm.update_elements($content);
assert.equal(toggle_button_html + "<p>translated HTML: Spoiler</p>", $header.html());
assert.equal($appended.selector, "<p>");
assert.equal($appended.text(), $t({defaultMessage: "Spoiler"}));
assert.equal($prepended.selector, toggle_button_html);
});
function assert_clipboard_setup() {

View File

@ -87,7 +87,7 @@ run_test("populate_profile_fields", ({mock_template}) => {
const template_data = [];
mock_template("settings/admin_profile_field_list.hbs", false, (data) => {
template_data.push(data);
return "whatever";
return "<admin-profile-field-list-stub>";
});
const fields_data = [

View File

@ -375,11 +375,11 @@ test_ui("zoom_in_and_zoom_out", ({mock_template}) => {
};
stream_list.initialize_stream_cursor();
mock_template("filter_topics.hbs", false, () => "filter-topics-stub");
mock_template("filter_topics.hbs", false, () => "<filter-topics-stub>");
let filter_topics_appended = false;
$stream_li1.children = () => ({
append(html) {
assert.equal(html, "filter-topics-stub");
append($element) {
assert.equal($element.selector, "<filter-topics-stub>");
filter_topics_appended = true;
},
});

View File

@ -350,7 +350,7 @@ run_test("render_date_renders_time_html", () => {
MockDate.set(today.getTime());
const message_time = today;
const expected_html = $t({defaultMessage: "Today"});
const expected_text = $t({defaultMessage: "Today"});
const attrs = {};
const $span_stub = $("<span>");
@ -360,13 +360,8 @@ run_test("render_date_renders_time_html", () => {
return $span_stub;
};
$span_stub.append = (str) => {
$span_stub.html(str);
return $span_stub;
};
const $actual = timerender.render_date(message_time);
assert.equal($actual.html(), expected_html);
assert.equal($actual.text(), expected_text);
assert.equal(attrs["data-tippy-content"], "Friday, April 12, 2019");
assert.equal(attrs.class, "timerender0");

View File

@ -180,15 +180,15 @@ run_test("partial updates", () => {
throw new Error("should not replace entire html");
};
let patched_html;
let $patched;
find = () => ({
children: () => ({
eq(i) {
assert.equal(i, 0);
return {
replaceWith(html) {
patched_html = html;
replaceWith($element) {
$patched = $element;
},
};
},
@ -206,7 +206,7 @@ run_test("partial updates", () => {
const new_ul = vdom.ul(new_opts);
vdom.update(replace_content, find, new_ul, ul);
assert.equal(patched_html, "<li>modified1</li>");
assert.equal($patched.selector, "<li>modified1</li>");
});
run_test("eq_array easy cases", () => {