Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
node tests: Eliminate "silent" option for zjquery.
Steve Howell2e3406f0b86d
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.jsindex bfcad46f032..95d28342cac 100644--- a/frontend_tests/node_tests/hash_util.js+++ b/frontend_tests/node_tests/hash_util.js@@ -12,12 +12,8 @@ const people = zrequire("people");const Filter = zrequire("Filter", "js/filter");const narrow_state = zrequire("narrow_state");-set_global(- "$",- make_zjquery({- silent: true,- }),-);+set_global("$", make_zjquery());+const ui_report = set_global("ui_report", {displayed_error: false,error: () => {diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.jsindex eb3ee89f28a..83ffdd68827 100644--- a/frontend_tests/node_tests/notifications.js+++ b/frontend_tests/node_tests/notifications.js@@ -9,12 +9,7 @@ const {run_test} = require("../zjsunit/test");const {make_zjquery} = require("../zjsunit/zjquery");// Dependencies-set_global(- "$",- make_zjquery({- silent: true,- }),-);+set_global("$", make_zjquery());set_global("document", {hasFocus() {return true;@@ -34,7 +29,7 @@ set_global("navigator", _navigator);const muting = zrequire("muting");const stream_data = zrequire("stream_data");-zrequire("ui");+const ui = zrequire("ui");const spoilers = zrequire("spoilers");spoilers.hide_spoilers_in_notification = () => {};@@ -262,7 +257,9 @@ run_test("message_is_notifiable", () => {assert.equal(notifications.message_is_notifiable(message), true);});-run_test("basic_notifications", () => {+run_test("basic_notifications", (override) => {+ override(ui, "replace_emoji_with_text", () => {});+let n; // Object for storing all notification data for assertions.let last_closed_message_id = null;let last_shown_message_id = null;diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex bcdc9b78567..2d1e2a8c910 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -10,12 +10,7 @@ const {make_zjquery} = require("../zjsunit/zjquery");zrequire("message_util");const noop = () => {};-set_global(- "$",- make_zjquery({- silent: true,- }),-);+set_global("$", make_zjquery());set_global("hashchange", {exit_overlay: noop,});@@ -290,6 +285,20 @@ function verify_topic_data(all_topics, stream, topic, last_msg_id, participated)let rt = zrequire("recent_topics");+function stub_out_filter_buttons() {+ // TODO: We probably want more direct tests that make sure+ // the widgets get updated correctly, but the stubs here+ // should accurately simulate toggling the filters.+ //+ // See show_selected_filters() and set_filter() in the+ // implementation.+ for (const filter of ["all", "unread", "muted", "participated"]) {+ const stub = $.create(`filter-${filter}-stub`);+ const selector = `[data-filter="${filter}"]`;+ $("#recent_topics_filter_buttons").set_find_results(selector, stub);+ }+}+run_test("test_recent_topics_launch", () => {// Note: unread count and urls are fake,// since they are generated in external libraries@@ -311,6 +320,8 @@ run_test("test_recent_topics_launch", () => {return "<recent_topics table stub>";});+ stub_out_filter_buttons();+rt = reset_module("recent_topics");rt.process_messages(messages);@@ -349,12 +360,15 @@ run_test("test_filter_all", () => {row_data = generate_topic_data([[1, "topic-1", 0, false, true]]);i = row_data.length;rt = reset_module("recent_topics");++ stub_out_filter_buttons();rt.set_filter("all");rt.process_messages([messages[0]]);row_data = row_data.concat(generate_topic_data([[1, "topic-7", 1, true, true]]));i = row_data.length;// topic is muted (=== hidden)+ stub_out_filter_buttons();rt.process_messages([messages[9]]);// Test search@@ -389,6 +403,7 @@ run_test("test_filter_unread", () => {rt = reset_module("recent_topics");stub_templates(() => "<recent_topics table stub>");+ stub_out_filter_buttons();rt.process_messages(messages);assert.equal(rt.inplace_rerender("1:topic-1"), true);@@ -452,6 +467,7 @@ run_test("test_filter_participated", () => {rt = reset_module("recent_topics");stub_templates(() => "<recent_topics table stub>");+ stub_out_filter_buttons();rt.process_messages(messages);assert.equal(rt.inplace_rerender("1:topic-4"), true);@@ -504,12 +520,14 @@ stub_templates(() => "<recent_topics table stub>");run_test("basic assertions", () => {rt = reset_module("recent_topics");+ stub_out_filter_buttons();rt.set_filter("all");rt.process_messages(messages);let all_topics = rt.get();// update a messagegenerate_topic_data([[1, "topic-7", 1, false, true]]);+ stub_out_filter_buttons();rt.process_messages([messages[9]]);// Check for expected lengths.// total 8 topics, 1 muted@@ -581,6 +599,7 @@ run_test("basic assertions", () => {run_test("test_reify_local_echo_message", () => {rt = reset_module("recent_topics");+ stub_out_filter_buttons();rt.set_filter("all");rt.process_messages(messages);diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.jsindex 6b1c2fd349f..0af6b4fc664 100644--- a/frontend_tests/zjsunit/zjquery.js+++ b/frontend_tests/zjsunit/zjquery.js@@ -227,9 +227,6 @@ exports.make_new_elem = function (selector, opts) {// if ($.find().length) { //success }return [];}- if (opts.silent) {- return self;- }throw new Error("Cannot find " + child_selector + " in " + selector);},get_on_handler(name, child_selector) {@@ -407,19 +404,14 @@ exports.make_new_elem = function (selector, opts) {return self;};-exports.make_zjquery = function (opts) {- opts = opts || {};-+exports.make_zjquery = function () {const elems = new Map();// Our fn structure helps us simulate extending jQuery.const fn = {};function new_elem(selector, create_opts) {- const elem = exports.make_new_elem(selector, {- silent: opts.silent,- ...create_opts,- });+ const elem = exports.make_new_elem(selector, {...create_opts});Object.assign(elem, fn);// Create a proxy handler to detect missing stubs.