diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 4726e4e279..2d95b545a5 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -162,6 +162,12 @@ js_rules = RuleList( "web/tests/", "web/src/billing/", }, + "exclude_line": { + ( + "web/src/common.ts", + '$(this).before($("").text("Fn"), $("").text(" + ").contents());', + ), + }, }, { "pattern": r"""report.success\(["']""", diff --git a/web/src/activity_ui.ts b/web/src/activity_ui.ts index 2fae6b849d..0748538524 100644 --- a/web/src/activity_ui.ts +++ b/web/src/activity_ui.ts @@ -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 { diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts index 758955c78b..3531d8abc7 100644 --- a/web/src/buddy_list.ts +++ b/web/src/buddy_list.ts @@ -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(); } } diff --git a/web/src/common.ts b/web/src/common.ts index 9d9e6342b3..ee2c5694ca 100644 --- a/web/src/common.ts +++ b/web/src/common.ts @@ -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("Fn + "); + $(this).before($("").text("Fn"), $("").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 = $("").text(following_key); - $(this).after(" + ", $kbd_elem); + $(this).after($("").text(" + ").contents(), $kbd_elem); } }); } diff --git a/web/src/list_widget.ts b/web/src/list_widget.ts index e8664adff0..1d96ec47b4 100644 --- a/web/src/list_widget.ts +++ b/web/src/list_widget.ts @@ -378,7 +378,7 @@ export function create( // 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() { diff --git a/web/src/message_list_view.js b/web/src/message_list_view.js index c3f5a37c93..43a5d2b632 100644 --- a/web/src/message_list_view.js +++ b/web/src/message_list_view.js @@ -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) { diff --git a/web/src/rendered_markdown.ts b/web/src/rendered_markdown.ts index 10166b809b..cc695747bc 100644 --- a/web/src/rendered_markdown.ts +++ b/web/src/rendered_markdown.ts @@ -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(`

${$t_html({defaultMessage: "Spoiler"})}

`); + $(this).append($("

").text($t({defaultMessage: "Spoiler"}))); } // Add the expand/collapse button to spoiler blocks const toggle_button_html = ''; - $(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, diff --git a/web/src/settings_profile_fields.js b/web/src/settings_profile_fields.js index 90f3847a12..21334e43d0 100644 --- a/web/src/settings_profile_fields.js +++ b/web/src/settings_profile_fields.js @@ -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. diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts index 75e329ebb8..7aef763965 100644 --- a/web/src/stream_list.ts +++ b/web/src/stream_list.ts @@ -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 { diff --git a/web/src/timerender.ts b/web/src/timerender.ts index cf69deefd0..765e9dea90 100644 --- a/web/src/timerender.ts +++ b/web/src/timerender.ts @@ -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); } diff --git a/web/src/vdom.ts b/web/src/vdom.ts index 10058506b3..1d0e0daf1b 100644 --- a/web/src/vdom.ts +++ b/web/src/vdom.ts @@ -1,3 +1,4 @@ +import $ from "jquery"; import _ from "lodash"; import * as blueslip from "./blueslip"; @@ -202,7 +203,7 @@ export function update( 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); diff --git a/web/tests/activity.test.js b/web/tests/activity.test.js index f8d3a87cba..2d1d0c5c75 100644 --- a/web/tests/activity.test.js +++ b/web/tests/activity.test.js @@ -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 ""; }); $("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, () => ""); 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, () => ""); 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 ""; }); - 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, ""); }); 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, () => ""); clear_buddy_list(buddy_list); page_params.presences = {}; } diff --git a/web/tests/buddy_list.test.js b/web/tests/buddy_list.test.js index e3abe6589a..c5dcfa9ade 100644 --- a/web/tests/buddy_list.test.js +++ b/web/tests/buddy_list.test.js @@ -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", () => ""); 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, () => ""); 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, ""); 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, () => ""); 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 ""; } - return "empty-list"; + return ""; }); 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 === "") { 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 === "") { 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, () => ""); 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, () => ""); 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, () => ""); let items_to_html_call_count = 0; override(buddy_list, "items_to_html", () => { items_to_html_call_count += 1; - return "html-stub"; + return ""; }); 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, () => ""); stub_buddy_list_elements(); init_simulated_scrolling(); stub_buddy_list_elements(); diff --git a/web/tests/common.test.js b/web/tests/common.test.js index 53984d5bfa..32b8cb5d44 100644 --- a/web/tests/common.test.js +++ b/web/tests/common.test.js @@ -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 = "Fn + "; override(navigator, "platform", "MacIntel"); + $("").contents = () => $(""); 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, ""); }; } 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, ""); assert.equal($elem.selector, ""); assert.equal($elem.text(), $stub.attr("data-mac-following-key")); }; diff --git a/web/tests/list_widget.test.js b/web/tests/list_widget.test.js index 96156107a5..90b78fff88 100644 --- a/web/tests/list_widget.test.js +++ b/web/tests/list_widget.test.js @@ -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); }, diff --git a/web/tests/message_list_view.test.js b/web/tests/message_list_view.test.js index a155973598..6024a597e1 100644 --- a/web/tests/message_list_view.test.js +++ b/web/tests/message_list_view.test.js @@ -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, () => ""); 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, () => ""); // 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, () => ""); // 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 diff --git a/web/tests/rendered_markdown.test.js b/web/tests/rendered_markdown.test.js index 6eb8b559ee..1dd77b6ecd 100644 --- a/web/tests/rendered_markdown.test.js +++ b/web/tests/rendered_markdown.test.js @@ -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", () => { ''; $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 = ''; $header.empty(); rm.update_elements($content); - assert.equal(toggle_button_html + "

translated HTML: Spoiler

", $header.html()); + assert.equal($appended.selector, "

"); + assert.equal($appended.text(), $t({defaultMessage: "Spoiler"})); + assert.equal($prepended.selector, toggle_button_html); }); function assert_clipboard_setup() { diff --git a/web/tests/settings_profile_fields.test.js b/web/tests/settings_profile_fields.test.js index 3ceed28eac..4e00148eda 100644 --- a/web/tests/settings_profile_fields.test.js +++ b/web/tests/settings_profile_fields.test.js @@ -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 ""; }); const fields_data = [ diff --git a/web/tests/stream_list.test.js b/web/tests/stream_list.test.js index 907c8c2aa4..fb9c5ee703 100644 --- a/web/tests/stream_list.test.js +++ b/web/tests/stream_list.test.js @@ -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, () => ""); let filter_topics_appended = false; $stream_li1.children = () => ({ - append(html) { - assert.equal(html, "filter-topics-stub"); + append($element) { + assert.equal($element.selector, ""); filter_topics_appended = true; }, }); diff --git a/web/tests/timerender.test.js b/web/tests/timerender.test.js index 1ab797f165..94807e2b04 100644 --- a/web/tests/timerender.test.js +++ b/web/tests/timerender.test.js @@ -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 = $(""); @@ -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"); diff --git a/web/tests/vdom.test.js b/web/tests/vdom.test.js index 5d6e4c9f31..628986367f 100644 --- a/web/tests/vdom.test.js +++ b/web/tests/vdom.test.js @@ -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, "

  • modified1
  • "); + assert.equal($patched.selector, "
  • modified1
  • "); }); run_test("eq_array easy cases", () => {