mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
js: Prefix jQuery object variable names with $.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -8,8 +8,8 @@ const blueslip = require("../zjsunit/zblueslip");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
const {page_params, user_settings} = require("../zjsunit/zpage_params");
|
||||
|
||||
const window_stub = $.create("window-stub");
|
||||
set_global("to_$", () => window_stub);
|
||||
const $window_stub = $.create("window-stub");
|
||||
set_global("to_$", () => $window_stub);
|
||||
$(window).idle = () => {};
|
||||
|
||||
const _document = {
|
||||
@@ -242,34 +242,34 @@ function simulate_right_column_buddy_list() {
|
||||
};
|
||||
}
|
||||
|
||||
function buddy_list_add(user_id, stub) {
|
||||
if (stub.attr) {
|
||||
stub.attr("data-user-id", user_id);
|
||||
function buddy_list_add(user_id, $stub) {
|
||||
if ($stub.attr) {
|
||||
$stub.attr("data-user-id", user_id);
|
||||
}
|
||||
stub.length = 1;
|
||||
$stub.length = 1;
|
||||
const sel = `li.user_sidebar_entry[data-user-id='${CSS.escape(user_id)}']`;
|
||||
$("#user_presences").set_find_results(sel, stub);
|
||||
$("#user_presences").set_find_results(sel, $stub);
|
||||
}
|
||||
|
||||
test("PM_update_dom_counts", () => {
|
||||
const count = $.create("alice-unread-count");
|
||||
const $count = $.create("alice-unread-count");
|
||||
const pm_key = alice.user_id.toString();
|
||||
const li = $.create("alice stub");
|
||||
buddy_list_add(pm_key, li);
|
||||
li.set_find_results(".unread_count", count);
|
||||
count.set_parents_result("li", li);
|
||||
const $li = $.create("alice stub");
|
||||
buddy_list_add(pm_key, $li);
|
||||
$li.set_find_results(".unread_count", $count);
|
||||
$count.set_parents_result("li", $li);
|
||||
|
||||
const counts = new Map();
|
||||
counts.set(pm_key, 5);
|
||||
li.addClass("user_sidebar_entry");
|
||||
$li.addClass("user_sidebar_entry");
|
||||
|
||||
activity.update_dom_with_unread_counts({pm_count: counts});
|
||||
assert.equal(count.text(), "5");
|
||||
assert.equal($count.text(), "5");
|
||||
|
||||
counts.set(pm_key, 0);
|
||||
|
||||
activity.update_dom_with_unread_counts({pm_count: counts});
|
||||
assert.equal(count.text(), "");
|
||||
assert.equal($count.text(), "");
|
||||
});
|
||||
|
||||
test("handlers", ({override, override_rewire, mock_template}) => {
|
||||
@@ -289,9 +289,9 @@ test("handlers", ({override, override_rewire, mock_template}) => {
|
||||
|
||||
// This is kind of weak coverage; we are mostly making sure that
|
||||
// keys and clicks got mapped to functions that don't crash.
|
||||
let me_li;
|
||||
let alice_li;
|
||||
let fred_li;
|
||||
let $me_li;
|
||||
let $alice_li;
|
||||
let $fred_li;
|
||||
|
||||
let narrowed;
|
||||
|
||||
@@ -307,13 +307,13 @@ test("handlers", ({override, override_rewire, mock_template}) => {
|
||||
});
|
||||
activity.set_cursor_and_filter();
|
||||
|
||||
me_li = $.create("me stub");
|
||||
alice_li = $.create("alice stub");
|
||||
fred_li = $.create("fred stub");
|
||||
$me_li = $.create("me stub");
|
||||
$alice_li = $.create("alice stub");
|
||||
$fred_li = $.create("fred stub");
|
||||
|
||||
buddy_list_add(me.user_id, me_li);
|
||||
buddy_list_add(alice.user_id, alice_li);
|
||||
buddy_list_add(fred.user_id, fred_li);
|
||||
buddy_list_add(me.user_id, $me_li);
|
||||
buddy_list_add(alice.user_id, $alice_li);
|
||||
buddy_list_add(fred.user_id, $fred_li);
|
||||
}
|
||||
|
||||
(function test_filter_keys() {
|
||||
@@ -364,7 +364,7 @@ test("handlers", ({override, override_rewire, mock_template}) => {
|
||||
// We wire up the click handler in click_handlers.js,
|
||||
// so this just tests the called function.
|
||||
narrowed = false;
|
||||
activity.narrow_for_user({li: alice_li});
|
||||
activity.narrow_for_user({$li: $alice_li});
|
||||
assert.ok(narrowed);
|
||||
})();
|
||||
|
||||
@@ -420,7 +420,7 @@ test("first/prev/next", ({override, mock_template}) => {
|
||||
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
||||
assert.equal(buddy_list.next_key(alice.user_id), undefined);
|
||||
|
||||
override(buddy_list.container, "append", () => {});
|
||||
override(buddy_list.$container, "append", () => {});
|
||||
|
||||
activity.redraw_user(alice.user_id);
|
||||
activity.redraw_user(fred.user_id);
|
||||
@@ -457,7 +457,7 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
|
||||
override(padded_widget, "update_padding", () => {});
|
||||
|
||||
let appended_html;
|
||||
override(buddy_list.container, "append", (html) => {
|
||||
override(buddy_list.$container, "append", (html) => {
|
||||
appended_html = html;
|
||||
});
|
||||
|
||||
@@ -470,7 +470,7 @@ test("insert_alice_then_fred", ({override, mock_template}) => {
|
||||
mock_template("user_presence_row.hbs", true, (data, html) => html);
|
||||
|
||||
let appended_html;
|
||||
override(buddy_list.container, "append", (html) => {
|
||||
override(buddy_list.$container, "append", (html) => {
|
||||
appended_html = html;
|
||||
});
|
||||
override(padded_widget, "update_padding", () => {});
|
||||
@@ -488,7 +488,7 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
|
||||
mock_template("user_presence_row.hbs", true, (data, html) => html);
|
||||
|
||||
let appended_html;
|
||||
override(buddy_list.container, "append", (html) => {
|
||||
override(buddy_list.$container, "append", (html) => {
|
||||
appended_html = html;
|
||||
});
|
||||
override(padded_widget, "update_padding", () => {});
|
||||
@@ -497,16 +497,16 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
|
||||
assert.ok(appended_html.indexOf('data-user-id="2"') > 0);
|
||||
assert.ok(appended_html.indexOf("user_circle_green") > 0);
|
||||
|
||||
const fred_stub = $.create("fred-first");
|
||||
buddy_list_add(fred.user_id, fred_stub);
|
||||
const $fred_stub = $.create("fred-first");
|
||||
buddy_list_add(fred.user_id, $fred_stub);
|
||||
|
||||
let inserted_html;
|
||||
fred_stub.before = (html) => {
|
||||
$fred_stub.before = (html) => {
|
||||
inserted_html = html;
|
||||
};
|
||||
|
||||
let fred_removed;
|
||||
fred_stub.remove = () => {
|
||||
$fred_stub.remove = () => {
|
||||
fred_removed = true;
|
||||
};
|
||||
|
||||
@@ -522,10 +522,10 @@ test("insert_fred_then_alice_then_rename", ({override, mock_template}) => {
|
||||
};
|
||||
people.add_active_user(fred_with_new_name);
|
||||
|
||||
const alice_stub = $.create("alice-first");
|
||||
buddy_list_add(alice.user_id, alice_stub);
|
||||
const $alice_stub = $.create("alice-first");
|
||||
buddy_list_add(alice.user_id, $alice_stub);
|
||||
|
||||
alice_stub.before = (html) => {
|
||||
$alice_stub.before = (html) => {
|
||||
inserted_html = html;
|
||||
};
|
||||
|
||||
@@ -541,8 +541,8 @@ test("insert_unfiltered_user_with_filter", () => {
|
||||
// This test only tests that we do not explode when
|
||||
// try to insert Fred into a list where he does not
|
||||
// match the search filter.
|
||||
const user_filter = $(".user-list-filter");
|
||||
user_filter.val("do-not-match-filter");
|
||||
const $user_filter = $(".user-list-filter");
|
||||
$user_filter.val("do-not-match-filter");
|
||||
activity.redraw_user(fred.user_id);
|
||||
});
|
||||
|
||||
@@ -579,8 +579,8 @@ test("update_presence_info", ({override, override_rewire}) => {
|
||||
|
||||
override_rewire(buddy_data, "matches_filter", () => true);
|
||||
|
||||
const alice_li = $.create("alice stub");
|
||||
buddy_list_add(alice.user_id, alice_li);
|
||||
const $alice_li = $.create("alice stub");
|
||||
buddy_list_add(alice.user_id, $alice_li);
|
||||
|
||||
let inserted;
|
||||
override(buddy_list, "insert_or_move", () => {
|
||||
@@ -613,8 +613,8 @@ test("initialize", ({override, mock_template}) => {
|
||||
|
||||
function clear() {
|
||||
$.clear_all_elements();
|
||||
buddy_list.container = $("#user_presences");
|
||||
buddy_list.container.append = () => {};
|
||||
buddy_list.$container = $("#user_presences");
|
||||
buddy_list.$container.append = () => {};
|
||||
clear_buddy_list();
|
||||
page_params.presences = {};
|
||||
}
|
||||
|
||||
@@ -50,31 +50,31 @@ run_test("add_alert_word", ({override_rewire}) => {
|
||||
|
||||
alert_words_ui.set_up_alert_words();
|
||||
|
||||
const create_form = $("#create_alert_word_form");
|
||||
const add_func = create_form.get_on_handler("click", "#create_alert_word_button");
|
||||
const $create_form = $("#create_alert_word_form");
|
||||
const add_func = $create_form.get_on_handler("click", "#create_alert_word_button");
|
||||
|
||||
const new_alert_word = $("#create_alert_word_name");
|
||||
const alert_word_status = $("#alert_word_status");
|
||||
const alert_word_status_text = $(".alert_word_status_text");
|
||||
alert_word_status.set_find_results(".alert_word_status_text", alert_word_status_text);
|
||||
const $new_alert_word = $("#create_alert_word_name");
|
||||
const $alert_word_status = $("#alert_word_status");
|
||||
const $alert_word_status_text = $(".alert_word_status_text");
|
||||
$alert_word_status.set_find_results(".alert_word_status_text", $alert_word_status_text);
|
||||
|
||||
// add '' as alert word
|
||||
add_func();
|
||||
assert.equal(new_alert_word.val(), "");
|
||||
assert.ok(alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal(alert_word_status_text.text(), "translated: Alert word can't be empty!");
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.equal($new_alert_word.val(), "");
|
||||
assert.ok($alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal($alert_word_status_text.text(), "translated: Alert word can't be empty!");
|
||||
assert.ok($alert_word_status.visible());
|
||||
|
||||
// add 'foo' as alert word (existing word)
|
||||
new_alert_word.val("foo");
|
||||
$new_alert_word.val("foo");
|
||||
|
||||
add_func();
|
||||
assert.ok(alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal(alert_word_status_text.text(), "translated: Alert word already exists!");
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.ok($alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal($alert_word_status_text.text(), "translated: Alert word already exists!");
|
||||
assert.ok($alert_word_status.visible());
|
||||
|
||||
// add 'zot' as alert word (new word)
|
||||
new_alert_word.val("zot");
|
||||
$new_alert_word.val("zot");
|
||||
|
||||
let success_func;
|
||||
let fail_func;
|
||||
@@ -89,26 +89,29 @@ run_test("add_alert_word", ({override_rewire}) => {
|
||||
|
||||
// test failure
|
||||
fail_func();
|
||||
assert.ok(alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal(alert_word_status_text.text(), "translated: Error adding alert word!");
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.ok($alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal($alert_word_status_text.text(), "translated: Error adding alert word!");
|
||||
assert.ok($alert_word_status.visible());
|
||||
|
||||
// test success
|
||||
success_func();
|
||||
assert.ok(alert_word_status.hasClass("alert-success"));
|
||||
assert.equal(alert_word_status_text.text(), 'translated: Alert word "zot" added successfully!');
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.ok($alert_word_status.hasClass("alert-success"));
|
||||
assert.equal(
|
||||
$alert_word_status_text.text(),
|
||||
'translated: Alert word "zot" added successfully!',
|
||||
);
|
||||
assert.ok($alert_word_status.visible());
|
||||
});
|
||||
|
||||
run_test("add_alert_word_keypress", ({override_rewire}) => {
|
||||
override_rewire(alert_words_ui, "rerender_alert_words_ui", () => {});
|
||||
alert_words_ui.set_up_alert_words();
|
||||
|
||||
const create_form = $("#create_alert_word_form");
|
||||
const keypress_func = create_form.get_on_handler("keypress", "#create_alert_word_name");
|
||||
const $create_form = $("#create_alert_word_form");
|
||||
const keypress_func = $create_form.get_on_handler("keypress", "#create_alert_word_name");
|
||||
|
||||
const new_alert_word = $("#create_alert_word_name");
|
||||
new_alert_word.val("zot");
|
||||
const $new_alert_word = $("#create_alert_word_name");
|
||||
$new_alert_word.val("zot");
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {},
|
||||
@@ -130,16 +133,16 @@ run_test("remove_alert_word", ({override_rewire}) => {
|
||||
override_rewire(alert_words_ui, "rerender_alert_words_ui", () => {});
|
||||
alert_words_ui.set_up_alert_words();
|
||||
|
||||
const word_list = $("#alert-words-table");
|
||||
const remove_func = word_list.get_on_handler("click", ".remove-alert-word");
|
||||
const $word_list = $("#alert-words-table");
|
||||
const remove_func = $word_list.get_on_handler("click", ".remove-alert-word");
|
||||
|
||||
const remove_alert_word = $(".remove-alert-word");
|
||||
const list_item = $("tr.alert-word-item");
|
||||
const val_item = $("span.value");
|
||||
val_item.text($t({defaultMessage: "zot"}));
|
||||
const $remove_alert_word = $(".remove-alert-word");
|
||||
const $list_item = $("tr.alert-word-item");
|
||||
const $val_item = $("span.value");
|
||||
$val_item.text($t({defaultMessage: "zot"}));
|
||||
|
||||
remove_alert_word.set_parents_result("tr", list_item);
|
||||
list_item.set_find_results(".value", val_item);
|
||||
$remove_alert_word.set_parents_result("tr", $list_item);
|
||||
$list_item.set_find_results(".value", $val_item);
|
||||
|
||||
const event = {
|
||||
currentTarget: ".remove-alert-word",
|
||||
@@ -156,42 +159,42 @@ run_test("remove_alert_word", ({override_rewire}) => {
|
||||
|
||||
remove_func(event);
|
||||
|
||||
const alert_word_status = $("#alert_word_status");
|
||||
const alert_word_status_text = $(".alert_word_status_text");
|
||||
alert_word_status.set_find_results(".alert_word_status_text", alert_word_status_text);
|
||||
const $alert_word_status = $("#alert_word_status");
|
||||
const $alert_word_status_text = $(".alert_word_status_text");
|
||||
$alert_word_status.set_find_results(".alert_word_status_text", $alert_word_status_text);
|
||||
|
||||
// test failure
|
||||
fail_func();
|
||||
assert.ok(alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal(alert_word_status_text.text(), "translated: Error removing alert word!");
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.ok($alert_word_status.hasClass("alert-danger"));
|
||||
assert.equal($alert_word_status_text.text(), "translated: Error removing alert word!");
|
||||
assert.ok($alert_word_status.visible());
|
||||
|
||||
// test success
|
||||
success_func();
|
||||
assert.ok(alert_word_status.hasClass("alert-success"));
|
||||
assert.equal(alert_word_status_text.text(), "translated: Alert word removed successfully!");
|
||||
assert.ok(alert_word_status.visible());
|
||||
assert.ok($alert_word_status.hasClass("alert-success"));
|
||||
assert.equal($alert_word_status_text.text(), "translated: Alert word removed successfully!");
|
||||
assert.ok($alert_word_status.visible());
|
||||
});
|
||||
|
||||
run_test("close_status_message", ({override_rewire}) => {
|
||||
override_rewire(alert_words_ui, "rerender_alert_words_ui", () => {});
|
||||
alert_words_ui.set_up_alert_words();
|
||||
|
||||
const alert_word_settings = $("#alert-word-settings");
|
||||
const close = alert_word_settings.get_on_handler("click", ".close-alert-word-status");
|
||||
const $alert_word_settings = $("#alert-word-settings");
|
||||
const close = $alert_word_settings.get_on_handler("click", ".close-alert-word-status");
|
||||
|
||||
const alert = $(".alert");
|
||||
const close_btn = $(".close-alert-word-status");
|
||||
close_btn.set_parents_result(".alert", alert);
|
||||
const $alert = $(".alert");
|
||||
const $close_btn = $(".close-alert-word-status");
|
||||
$close_btn.set_parents_result(".alert", $alert);
|
||||
|
||||
alert.show();
|
||||
$alert.show();
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {},
|
||||
currentTarget: ".close-alert-word-status",
|
||||
};
|
||||
|
||||
assert.ok(alert.visible());
|
||||
assert.ok($alert.visible());
|
||||
close(event);
|
||||
assert.ok(!alert.visible());
|
||||
assert.ok(!$alert.visible());
|
||||
});
|
||||
|
||||
@@ -39,18 +39,18 @@ people.add_active_user(alice);
|
||||
run_test("get_items", () => {
|
||||
const buddy_list = new BuddyList();
|
||||
|
||||
// We don't make alice_li an actual jQuery stub,
|
||||
// We don't make $alice_li an actual jQuery stub,
|
||||
// because our test only cares that it comes
|
||||
// back from get_items.
|
||||
const alice_li = "alice stub";
|
||||
const $alice_li = "alice stub";
|
||||
const sel = "li.user_sidebar_entry";
|
||||
const container = $.create("get_items container", {
|
||||
children: [{to_$: () => alice_li}],
|
||||
const $container = $.create("get_items container", {
|
||||
children: [{to_$: () => $alice_li}],
|
||||
});
|
||||
buddy_list.container.set_find_results(sel, container);
|
||||
buddy_list.$container.set_find_results(sel, $container);
|
||||
|
||||
const items = buddy_list.get_items();
|
||||
assert.deepEqual(items, [alice_li]);
|
||||
assert.deepEqual(items, [$alice_li]);
|
||||
});
|
||||
|
||||
run_test("basics", ({override}) => {
|
||||
@@ -83,19 +83,19 @@ run_test("basics", ({override}) => {
|
||||
});
|
||||
assert.ok(appended);
|
||||
|
||||
const alice_li = {length: 1};
|
||||
const $alice_li = {length: 1};
|
||||
|
||||
override(buddy_list, "get_li_from_key", (opts) => {
|
||||
const key = opts.key;
|
||||
|
||||
assert.equal(key, alice.user_id);
|
||||
return alice_li;
|
||||
return $alice_li;
|
||||
});
|
||||
|
||||
const li = buddy_list.find_li({
|
||||
const $li = buddy_list.find_li({
|
||||
key: alice.user_id,
|
||||
});
|
||||
assert.equal(li, alice_li);
|
||||
assert.equal($li, $alice_li);
|
||||
});
|
||||
|
||||
run_test("big_list", ({override}) => {
|
||||
@@ -163,11 +163,11 @@ run_test("find_li w/force_render", ({override}) => {
|
||||
// key is not already rendered in DOM, then the
|
||||
// widget will call show_key to force-render it.
|
||||
const key = "999";
|
||||
const stub_li = {length: 0};
|
||||
const $stub_li = {length: 0};
|
||||
|
||||
override(buddy_list, "get_li_from_key", (opts) => {
|
||||
assert.equal(opts.key, key);
|
||||
return stub_li;
|
||||
return $stub_li;
|
||||
});
|
||||
|
||||
buddy_list.keys = ["foo", "bar", key, "baz"];
|
||||
@@ -179,18 +179,18 @@ run_test("find_li w/force_render", ({override}) => {
|
||||
shown = true;
|
||||
});
|
||||
|
||||
const empty_li = buddy_list.find_li({
|
||||
const $empty_li = buddy_list.find_li({
|
||||
key,
|
||||
});
|
||||
assert.equal(empty_li, stub_li);
|
||||
assert.equal($empty_li, $stub_li);
|
||||
assert.ok(!shown);
|
||||
|
||||
const li = buddy_list.find_li({
|
||||
const $li = buddy_list.find_li({
|
||||
key,
|
||||
force_render: true,
|
||||
});
|
||||
|
||||
assert.equal(li, stub_li);
|
||||
assert.equal($li, $stub_li);
|
||||
assert.ok(shown);
|
||||
});
|
||||
|
||||
@@ -198,12 +198,12 @@ run_test("find_li w/bad key", ({override}) => {
|
||||
const buddy_list = new BuddyList();
|
||||
override(buddy_list, "get_li_from_key", () => ({length: 0}));
|
||||
|
||||
const undefined_li = buddy_list.find_li({
|
||||
const $undefined_li = buddy_list.find_li({
|
||||
key: "not-there",
|
||||
force_render: true,
|
||||
});
|
||||
|
||||
assert.deepEqual(undefined_li, []);
|
||||
assert.deepEqual($undefined_li, []);
|
||||
});
|
||||
|
||||
run_test("scrolling", ({override}) => {
|
||||
|
||||
@@ -39,41 +39,41 @@ run_test("phrase_match", () => {
|
||||
run_test("copy_data_attribute_value", ({override}) => {
|
||||
const admin_emails_val = "iago@zulip.com";
|
||||
|
||||
const input = $.create("input");
|
||||
const $input = $.create("input");
|
||||
|
||||
let removed;
|
||||
input.remove = () => {
|
||||
$input.remove = () => {
|
||||
removed = true;
|
||||
};
|
||||
|
||||
override(document, "createElement", () => input);
|
||||
override(document, "createElement", () => $input);
|
||||
override(document, "execCommand", noop);
|
||||
|
||||
$("body").append = noop;
|
||||
$(input).val = (arg) => {
|
||||
$($input).val = (arg) => {
|
||||
assert.equal(arg, admin_emails_val);
|
||||
return {
|
||||
trigger: noop,
|
||||
};
|
||||
};
|
||||
|
||||
const elem = {};
|
||||
const $elem = {};
|
||||
let faded_in = false;
|
||||
let faded_out = false;
|
||||
|
||||
elem.data = (key) => {
|
||||
$elem.data = (key) => {
|
||||
assert.equal(key, "admin-emails");
|
||||
return admin_emails_val;
|
||||
};
|
||||
elem.fadeOut = (val) => {
|
||||
$elem.fadeOut = (val) => {
|
||||
assert.equal(val, 250);
|
||||
faded_out = true;
|
||||
};
|
||||
elem.fadeIn = (val) => {
|
||||
$elem.fadeIn = (val) => {
|
||||
assert.equal(val, 1000);
|
||||
faded_in = true;
|
||||
};
|
||||
common.copy_data_attribute_value(elem, "admin-emails");
|
||||
common.copy_data_attribute_value($elem, "admin-emails");
|
||||
assert.ok(removed);
|
||||
assert.ok(faded_in);
|
||||
assert.ok(faded_out);
|
||||
@@ -111,17 +111,17 @@ run_test("adjust_mac_shortcuts mac", ({override_rewire}) => {
|
||||
|
||||
for (const [old_key, mac_key] of keys_to_test_mac) {
|
||||
const test_item = {};
|
||||
const stub = $.create("hotkey_" + key_no);
|
||||
stub.text(old_key);
|
||||
assert.equal(stub.hasClass("mac-cmd-key"), false);
|
||||
test_item.stub = stub;
|
||||
const $stub = $.create("hotkey_" + key_no);
|
||||
$stub.text(old_key);
|
||||
assert.equal($stub.hasClass("mac-cmd-key"), false);
|
||||
test_item.$stub = $stub;
|
||||
test_item.mac_key = mac_key;
|
||||
test_item.is_cmd_key = old_key.includes("Ctrl");
|
||||
test_items.push(test_item);
|
||||
key_no += 1;
|
||||
}
|
||||
|
||||
const children = test_items.map((test_item) => ({to_$: () => test_item.stub}));
|
||||
const children = test_items.map((test_item) => ({to_$: () => test_item.$stub}));
|
||||
|
||||
$.create(".markdown_content", {children});
|
||||
|
||||
@@ -129,8 +129,8 @@ run_test("adjust_mac_shortcuts mac", ({override_rewire}) => {
|
||||
common.adjust_mac_shortcuts(".markdown_content", require_cmd);
|
||||
|
||||
for (const test_item of test_items) {
|
||||
assert.equal(test_item.stub.hasClass("mac-cmd-key"), test_item.is_cmd_key);
|
||||
assert.equal(test_item.stub.text(), test_item.mac_key);
|
||||
assert.equal(test_item.$stub.hasClass("mac-cmd-key"), test_item.is_cmd_key);
|
||||
assert.equal(test_item.$stub.text(), test_item.mac_key);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -10,35 +10,35 @@ const blueslip = require("../zjsunit/zblueslip");
|
||||
let env;
|
||||
|
||||
function make_tab(i) {
|
||||
const self = {};
|
||||
const $self = {};
|
||||
|
||||
assert.equal(env.tabs.length, i);
|
||||
|
||||
self.stub = true;
|
||||
self.class = [];
|
||||
$self.stub = true;
|
||||
$self.class = [];
|
||||
|
||||
self.addClass = (c) => {
|
||||
self.class += " " + c;
|
||||
const tokens = self.class.trim().split(/ +/);
|
||||
self.class = Array.from(new Set(tokens)).join(" ");
|
||||
$self.addClass = (c) => {
|
||||
$self.class += " " + c;
|
||||
const tokens = $self.class.trim().split(/ +/);
|
||||
$self.class = Array.from(new Set(tokens)).join(" ");
|
||||
};
|
||||
|
||||
self.removeClass = (c) => {
|
||||
const tokens = self.class.trim().split(/ +/);
|
||||
self.class = tokens.filter((token) => token !== c).join(" ");
|
||||
$self.removeClass = (c) => {
|
||||
const tokens = $self.class.trim().split(/ +/);
|
||||
$self.class = tokens.filter((token) => token !== c).join(" ");
|
||||
};
|
||||
|
||||
self.hasClass = (c) => {
|
||||
const tokens = self.class.trim().split(/ +/);
|
||||
$self.hasClass = (c) => {
|
||||
const tokens = $self.class.trim().split(/ +/);
|
||||
return tokens.includes(c);
|
||||
};
|
||||
|
||||
self.data = (name) => {
|
||||
$self.data = (name) => {
|
||||
assert.equal(name, "tab-id");
|
||||
return i;
|
||||
};
|
||||
|
||||
self.text = (text) => {
|
||||
$self.text = (text) => {
|
||||
assert.equal(
|
||||
text,
|
||||
[
|
||||
@@ -49,23 +49,23 @@ function make_tab(i) {
|
||||
);
|
||||
};
|
||||
|
||||
self.trigger = (type) => {
|
||||
$self.trigger = (type) => {
|
||||
if (type === "focus") {
|
||||
env.focused_tab = i;
|
||||
}
|
||||
};
|
||||
|
||||
env.tabs.push(self);
|
||||
env.tabs.push($self);
|
||||
|
||||
return self;
|
||||
return $self;
|
||||
}
|
||||
|
||||
const ind_tab = (function () {
|
||||
const self = {};
|
||||
const $self = {};
|
||||
|
||||
self.stub = true;
|
||||
$self.stub = true;
|
||||
|
||||
self.on = (name, f) => {
|
||||
$self.on = (name, f) => {
|
||||
if (name === "click") {
|
||||
env.click_f = f;
|
||||
} else if (name === "keydown") {
|
||||
@@ -73,36 +73,36 @@ const ind_tab = (function () {
|
||||
}
|
||||
};
|
||||
|
||||
self.removeClass = (c) => {
|
||||
for (const tab of env.tabs) {
|
||||
tab.removeClass(c);
|
||||
$self.removeClass = (c) => {
|
||||
for (const $tab of env.tabs) {
|
||||
$tab.removeClass(c);
|
||||
}
|
||||
};
|
||||
|
||||
self.eq = (idx) => env.tabs[idx];
|
||||
$self.eq = (idx) => env.tabs[idx];
|
||||
|
||||
return self;
|
||||
return $self;
|
||||
})();
|
||||
|
||||
function make_switcher() {
|
||||
const self = {};
|
||||
const $self = {};
|
||||
|
||||
self.stub = true;
|
||||
$self.stub = true;
|
||||
|
||||
self.children = [];
|
||||
$self.children = [];
|
||||
|
||||
self.classList = new Set();
|
||||
$self.classList = new Set();
|
||||
|
||||
self.append = (child) => {
|
||||
self.children.push(child);
|
||||
$self.append = (child) => {
|
||||
$self.children.push(child);
|
||||
};
|
||||
|
||||
self.addClass = (c) => {
|
||||
self.classList.add(c);
|
||||
self.addedClass = c;
|
||||
$self.addClass = (c) => {
|
||||
$self.classList.add(c);
|
||||
$self.addedClass = c;
|
||||
};
|
||||
|
||||
self.find = (sel) => {
|
||||
$self.find = (sel) => {
|
||||
switch (sel) {
|
||||
case ".ind-tab":
|
||||
return ind_tab;
|
||||
@@ -111,7 +111,7 @@ function make_switcher() {
|
||||
}
|
||||
};
|
||||
|
||||
return self;
|
||||
return $self;
|
||||
}
|
||||
|
||||
mock_jquery((sel, attributes) => {
|
||||
|
||||
@@ -552,27 +552,28 @@ test_ui("on_events", ({override, override_rewire}) => {
|
||||
override(rendered_markdown, "update_elements", () => {});
|
||||
|
||||
function setup_parents_and_mock_remove(container_sel, target_sel, parent) {
|
||||
const container = $.create("fake " + container_sel);
|
||||
const $container = $.create("fake " + container_sel);
|
||||
let container_removed = false;
|
||||
|
||||
container.remove = () => {
|
||||
$container.remove = () => {
|
||||
container_removed = true;
|
||||
};
|
||||
|
||||
const target = $.create("fake click target (" + target_sel + ")");
|
||||
const $target = $.create("fake click target (" + target_sel + ")");
|
||||
|
||||
target.set_parents_result(parent, container);
|
||||
$target.set_parents_result(parent, $container);
|
||||
|
||||
const event = {
|
||||
preventDefault: noop,
|
||||
stopPropagation: noop,
|
||||
target,
|
||||
// FIXME: event.target should not be a jQuery object
|
||||
target: $target,
|
||||
};
|
||||
|
||||
const helper = {
|
||||
event,
|
||||
container,
|
||||
target,
|
||||
$container,
|
||||
$target,
|
||||
container_was_removed: () => container_removed,
|
||||
};
|
||||
|
||||
@@ -633,7 +634,7 @@ test_ui("on_events", ({override, override_rewire}) => {
|
||||
".compose_invite_user",
|
||||
);
|
||||
|
||||
helper.container.data = (field) => {
|
||||
helper.$container.data = (field) => {
|
||||
if (field === "user-id") {
|
||||
return "34";
|
||||
}
|
||||
@@ -642,7 +643,7 @@ test_ui("on_events", ({override, override_rewire}) => {
|
||||
}
|
||||
throw new Error(`Unknown field ${field}`);
|
||||
};
|
||||
helper.target.prop("disabled", false);
|
||||
helper.$target.prop("disabled", false);
|
||||
|
||||
// !sub will result in true here and we check the success code path.
|
||||
stream_data.add_sub(subscription);
|
||||
|
||||
@@ -43,9 +43,9 @@ run_test("pills", ({override}) => {
|
||||
|
||||
people.get_realm_users = () => [iago, othello, hamlet];
|
||||
|
||||
const recipient_stub = $("#private_message_recipient");
|
||||
const $recipient_stub = $("#private_message_recipient");
|
||||
const pill_container_stub = "pill-container";
|
||||
recipient_stub.set_parent(pill_container_stub);
|
||||
$recipient_stub.set_parent(pill_container_stub);
|
||||
let create_item_handler;
|
||||
|
||||
const all_pills = new Map();
|
||||
@@ -132,7 +132,7 @@ run_test("pills", ({override}) => {
|
||||
}
|
||||
|
||||
function input_pill_stub(opts) {
|
||||
assert.equal(opts.container, pill_container_stub);
|
||||
assert.equal(opts.$container, pill_container_stub);
|
||||
create_item_handler = opts.create_item_from_text;
|
||||
assert.ok(create_item_handler);
|
||||
return pills;
|
||||
|
||||
@@ -46,48 +46,48 @@ people.add_active_user(bob);
|
||||
|
||||
function make_textbox(s) {
|
||||
// Simulate a jQuery textbox for testing purposes.
|
||||
const widget = {};
|
||||
const $widget = {};
|
||||
|
||||
widget.s = s;
|
||||
widget.focused = false;
|
||||
$widget.s = s;
|
||||
$widget.focused = false;
|
||||
|
||||
widget.caret = function (arg) {
|
||||
$widget.caret = function (arg) {
|
||||
if (typeof arg === "number") {
|
||||
widget.pos = arg;
|
||||
$widget.pos = arg;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (arg) {
|
||||
widget.insert_pos = widget.pos;
|
||||
widget.insert_text = arg;
|
||||
const before = widget.s.slice(0, widget.pos);
|
||||
const after = widget.s.slice(widget.pos);
|
||||
widget.s = before + arg + after;
|
||||
widget.pos += arg.length;
|
||||
$widget.insert_pos = $widget.pos;
|
||||
$widget.insert_text = arg;
|
||||
const before = $widget.s.slice(0, $widget.pos);
|
||||
const after = $widget.s.slice($widget.pos);
|
||||
$widget.s = before + arg + after;
|
||||
$widget.pos += arg.length;
|
||||
return this;
|
||||
}
|
||||
|
||||
return widget.pos;
|
||||
return $widget.pos;
|
||||
};
|
||||
|
||||
widget.val = function (new_val) {
|
||||
$widget.val = function (new_val) {
|
||||
if (new_val) {
|
||||
widget.s = new_val;
|
||||
$widget.s = new_val;
|
||||
return this;
|
||||
}
|
||||
return widget.s;
|
||||
return $widget.s;
|
||||
};
|
||||
|
||||
widget.trigger = function (type) {
|
||||
$widget.trigger = function (type) {
|
||||
if (type === "focus") {
|
||||
widget.focused = true;
|
||||
$widget.focused = true;
|
||||
} else if (type === "blur") {
|
||||
widget.focused = false;
|
||||
$widget.focused = false;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
return widget;
|
||||
return $widget;
|
||||
}
|
||||
|
||||
run_test("autosize_textarea", ({override}) => {
|
||||
@@ -121,59 +121,59 @@ run_test("insert_syntax_and_focus", () => {
|
||||
});
|
||||
|
||||
run_test("smart_insert", () => {
|
||||
let textbox = make_textbox("abc");
|
||||
textbox.caret(4);
|
||||
let $textbox = make_textbox("abc");
|
||||
$textbox.caret(4);
|
||||
|
||||
compose_ui.smart_insert(textbox, ":smile:");
|
||||
assert.equal(textbox.insert_pos, 4);
|
||||
assert.equal(textbox.insert_text, " :smile: ");
|
||||
assert.equal(textbox.val(), "abc :smile: ");
|
||||
assert.ok(textbox.focused);
|
||||
compose_ui.smart_insert($textbox, ":smile:");
|
||||
assert.equal($textbox.insert_pos, 4);
|
||||
assert.equal($textbox.insert_text, " :smile: ");
|
||||
assert.equal($textbox.val(), "abc :smile: ");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, ":airplane:");
|
||||
assert.equal(textbox.insert_text, ":airplane: ");
|
||||
assert.equal(textbox.val(), "abc :smile: :airplane: ");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, ":airplane:");
|
||||
assert.equal($textbox.insert_text, ":airplane: ");
|
||||
assert.equal($textbox.val(), "abc :smile: :airplane: ");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
textbox.caret(0);
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, ":octopus:");
|
||||
assert.equal(textbox.insert_text, ":octopus: ");
|
||||
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: ");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox.caret(0);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, ":octopus:");
|
||||
assert.equal($textbox.insert_text, ":octopus: ");
|
||||
assert.equal($textbox.val(), ":octopus: abc :smile: :airplane: ");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
textbox.caret(textbox.val().length);
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, ":heart:");
|
||||
assert.equal(textbox.insert_text, ":heart: ");
|
||||
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: :heart: ");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox.caret($textbox.val().length);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, ":heart:");
|
||||
assert.equal($textbox.insert_text, ":heart: ");
|
||||
assert.equal($textbox.val(), ":octopus: abc :smile: :airplane: :heart: ");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
// Test handling of spaces for ```quote
|
||||
textbox = make_textbox("");
|
||||
textbox.caret(0);
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, "```quote\nquoted message\n```\n");
|
||||
assert.equal(textbox.insert_text, "```quote\nquoted message\n```\n");
|
||||
assert.equal(textbox.val(), "```quote\nquoted message\n```\n");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox = make_textbox("");
|
||||
$textbox.caret(0);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, "```quote\nquoted message\n```\n");
|
||||
assert.equal($textbox.insert_text, "```quote\nquoted message\n```\n");
|
||||
assert.equal($textbox.val(), "```quote\nquoted message\n```\n");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
textbox = make_textbox("");
|
||||
textbox.caret(0);
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, "translated: [Quoting…]\n");
|
||||
assert.equal(textbox.insert_text, "translated: [Quoting…]\n");
|
||||
assert.equal(textbox.val(), "translated: [Quoting…]\n");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox = make_textbox("");
|
||||
$textbox.caret(0);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, "translated: [Quoting…]\n");
|
||||
assert.equal($textbox.insert_text, "translated: [Quoting…]\n");
|
||||
assert.equal($textbox.val(), "translated: [Quoting…]\n");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
textbox = make_textbox("abc");
|
||||
textbox.caret(3);
|
||||
textbox.trigger("blur");
|
||||
compose_ui.smart_insert(textbox, " test with space");
|
||||
assert.equal(textbox.insert_text, " test with space ");
|
||||
assert.equal(textbox.val(), "abc test with space ");
|
||||
assert.ok(textbox.focused);
|
||||
$textbox = make_textbox("abc");
|
||||
$textbox.caret(3);
|
||||
$textbox.trigger("blur");
|
||||
compose_ui.smart_insert($textbox, " test with space");
|
||||
assert.equal($textbox.insert_text, " test with space ");
|
||||
assert.equal($textbox.val(), "abc test with space ");
|
||||
assert.ok($textbox.focused);
|
||||
|
||||
// Note that we don't have any special logic for strings that are
|
||||
// already surrounded by spaces, since we are usually inserting things
|
||||
@@ -481,14 +481,14 @@ run_test("format_text", () => {
|
||||
wrap_syntax = "";
|
||||
}
|
||||
|
||||
const textarea = $("#compose-textarea");
|
||||
textarea.get = () => ({
|
||||
const $textarea = $("#compose-textarea");
|
||||
$textarea.get = () => ({
|
||||
setSelectionRange: () => {},
|
||||
});
|
||||
|
||||
function init_textarea(val, range) {
|
||||
textarea.val = () => val;
|
||||
textarea.range = () => range;
|
||||
$textarea.val = () => val;
|
||||
$textarea.range = () => range;
|
||||
}
|
||||
|
||||
const italic_syntax = "*";
|
||||
@@ -502,7 +502,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 3,
|
||||
});
|
||||
compose_ui.format_text(textarea, "bold");
|
||||
compose_ui.format_text($textarea, "bold");
|
||||
assert.equal(set_text, "");
|
||||
assert.equal(wrap_selection_called, true);
|
||||
assert.equal(wrap_syntax, bold_syntax);
|
||||
@@ -515,7 +515,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 7,
|
||||
});
|
||||
compose_ui.format_text(textarea, "bold");
|
||||
compose_ui.format_text($textarea, "bold");
|
||||
assert.equal(set_text, "abc");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -527,7 +527,7 @@ run_test("format_text", () => {
|
||||
text: "**abc**",
|
||||
length: 7,
|
||||
});
|
||||
compose_ui.format_text(textarea, "bold");
|
||||
compose_ui.format_text($textarea, "bold");
|
||||
assert.equal(set_text, "abc");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -539,7 +539,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 3,
|
||||
});
|
||||
compose_ui.format_text(textarea, "italic");
|
||||
compose_ui.format_text($textarea, "italic");
|
||||
assert.equal(set_text, "");
|
||||
assert.equal(wrap_selection_called, true);
|
||||
assert.equal(wrap_syntax, italic_syntax);
|
||||
@@ -552,7 +552,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 3,
|
||||
});
|
||||
compose_ui.format_text(textarea, "italic");
|
||||
compose_ui.format_text($textarea, "italic");
|
||||
assert.equal(set_text, "abc");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -564,7 +564,7 @@ run_test("format_text", () => {
|
||||
text: "*abc*",
|
||||
length: 5,
|
||||
});
|
||||
compose_ui.format_text(textarea, "italic");
|
||||
compose_ui.format_text($textarea, "italic");
|
||||
assert.equal(set_text, "abc");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -576,7 +576,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 3,
|
||||
});
|
||||
compose_ui.format_text(textarea, "bold");
|
||||
compose_ui.format_text($textarea, "bold");
|
||||
assert.equal(set_text, "*abc*");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -588,7 +588,7 @@ run_test("format_text", () => {
|
||||
text: "***abc***",
|
||||
length: 9,
|
||||
});
|
||||
compose_ui.format_text(textarea, "bold");
|
||||
compose_ui.format_text($textarea, "bold");
|
||||
assert.equal(set_text, "*abc*");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -600,7 +600,7 @@ run_test("format_text", () => {
|
||||
text: "abc",
|
||||
length: 3,
|
||||
});
|
||||
compose_ui.format_text(textarea, "italic");
|
||||
compose_ui.format_text($textarea, "italic");
|
||||
assert.equal(set_text, "**abc**");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
|
||||
@@ -612,14 +612,14 @@ run_test("format_text", () => {
|
||||
text: "***abc***",
|
||||
length: 9,
|
||||
});
|
||||
compose_ui.format_text(textarea, "italic");
|
||||
compose_ui.format_text($textarea, "italic");
|
||||
assert.equal(set_text, "**abc**");
|
||||
assert.equal(wrap_selection_called, false);
|
||||
});
|
||||
|
||||
run_test("markdown_shortcuts", ({override_rewire}) => {
|
||||
let format_text_type;
|
||||
override_rewire(compose_ui, "format_text", (textarea, type) => {
|
||||
override_rewire(compose_ui, "format_text", ($textarea, type) => {
|
||||
format_text_type = type;
|
||||
});
|
||||
|
||||
@@ -711,21 +711,21 @@ run_test("markdown_shortcuts", ({override_rewire}) => {
|
||||
});
|
||||
|
||||
run_test("right-to-left", () => {
|
||||
const textarea = $("#compose-textarea");
|
||||
const $textarea = $("#compose-textarea");
|
||||
|
||||
const event = {
|
||||
key: "A",
|
||||
};
|
||||
|
||||
assert.equal(textarea.hasClass("rtl"), false);
|
||||
assert.equal($textarea.hasClass("rtl"), false);
|
||||
|
||||
textarea.val("```quote\nمرحبا");
|
||||
$textarea.val("```quote\nمرحبا");
|
||||
compose_ui.handle_keyup(event, $("#compose-textarea"));
|
||||
|
||||
assert.equal(textarea.hasClass("rtl"), true);
|
||||
assert.equal($textarea.hasClass("rtl"), true);
|
||||
|
||||
textarea.val("```quote foo");
|
||||
compose_ui.handle_keyup(event, textarea);
|
||||
$textarea.val("```quote foo");
|
||||
compose_ui.handle_keyup(event, $textarea);
|
||||
|
||||
assert.equal(textarea.hasClass("rtl"), false);
|
||||
assert.equal($textarea.hasClass("rtl"), false);
|
||||
});
|
||||
|
||||
@@ -131,10 +131,10 @@ test_ui("validate", ({override, mock_template}) => {
|
||||
$("#compose-send-button").trigger("focus");
|
||||
$("#compose-send-button .loader").hide();
|
||||
|
||||
const pm_pill_container = $.create("fake-pm-pill-container");
|
||||
const $pm_pill_container = $.create("fake-pm-pill-container");
|
||||
$("#private_message_recipient")[0] = {};
|
||||
$("#private_message_recipient").set_parent(pm_pill_container);
|
||||
pm_pill_container.set_find_results(".input", $("#private_message_recipient"));
|
||||
$("#private_message_recipient").set_parent($pm_pill_container);
|
||||
$pm_pill_container.set_find_results(".input", $("#private_message_recipient"));
|
||||
$("#private_message_recipient").before = () => {};
|
||||
|
||||
compose_pm_pill.initialize();
|
||||
@@ -474,38 +474,38 @@ test_ui("test_validate_stream_message_post_policy_full_members_only", () => {
|
||||
test_ui("test_check_overflow_text", () => {
|
||||
page_params.max_message_length = 10000;
|
||||
|
||||
const textarea = $("#compose-textarea");
|
||||
const indicator = $("#compose_limit_indicator");
|
||||
const send_button = $("#compose-send-button");
|
||||
const $textarea = $("#compose-textarea");
|
||||
const $indicator = $("#compose_limit_indicator");
|
||||
const $send_button = $("#compose-send-button");
|
||||
|
||||
// Indicator should show red colored text
|
||||
textarea.val("a".repeat(10000 + 1));
|
||||
$textarea.val("a".repeat(10000 + 1));
|
||||
compose_validate.check_overflow_text();
|
||||
assert.ok(indicator.hasClass("over_limit"));
|
||||
assert.equal(indicator.text(), "10001/10000");
|
||||
assert.ok(textarea.hasClass("over_limit"));
|
||||
assert.ok($indicator.hasClass("over_limit"));
|
||||
assert.equal($indicator.text(), "10001/10000");
|
||||
assert.ok($textarea.hasClass("over_limit"));
|
||||
assert.equal(
|
||||
$("#compose-error-msg").html(),
|
||||
"translated HTML: Message length shouldn't be greater than 10000 characters.",
|
||||
);
|
||||
assert.ok(send_button.prop("disabled"));
|
||||
assert.ok($send_button.prop("disabled"));
|
||||
|
||||
$("#compose-send-status").stop = () => ({fadeOut: () => {}});
|
||||
|
||||
// Indicator should show orange colored text
|
||||
textarea.val("a".repeat(9000 + 1));
|
||||
$textarea.val("a".repeat(9000 + 1));
|
||||
compose_validate.check_overflow_text();
|
||||
assert.ok(!indicator.hasClass("over_limit"));
|
||||
assert.equal(indicator.text(), "9001/10000");
|
||||
assert.ok(!textarea.hasClass("over_limit"));
|
||||
assert.ok(!send_button.prop("disabled"));
|
||||
assert.ok(!$indicator.hasClass("over_limit"));
|
||||
assert.equal($indicator.text(), "9001/10000");
|
||||
assert.ok(!$textarea.hasClass("over_limit"));
|
||||
assert.ok(!$send_button.prop("disabled"));
|
||||
|
||||
// Indicator must be empty
|
||||
textarea.val("a".repeat(9000));
|
||||
$textarea.val("a".repeat(9000));
|
||||
compose_validate.check_overflow_text();
|
||||
assert.ok(!indicator.hasClass("over_limit"));
|
||||
assert.equal(indicator.text(), "");
|
||||
assert.ok(!textarea.hasClass("over_limit"));
|
||||
assert.ok(!$indicator.hasClass("over_limit"));
|
||||
assert.equal($indicator.text(), "");
|
||||
assert.ok(!$textarea.hasClass("over_limit"));
|
||||
});
|
||||
|
||||
test_ui("test_message_overflow", () => {
|
||||
@@ -736,10 +736,10 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, override_rewire, moc
|
||||
}
|
||||
|
||||
// Simulate that the row was added to the DOM.
|
||||
const warning_row = $("<warning row>");
|
||||
const $warning_row = $("<warning row>");
|
||||
|
||||
let looked_for_existing;
|
||||
warning_row.data = (field) => {
|
||||
$warning_row.data = (field) => {
|
||||
if (field === "user-id") {
|
||||
looked_for_existing = true;
|
||||
return "34";
|
||||
@@ -750,9 +750,9 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, override_rewire, moc
|
||||
throw new Error(`Unknown field ${field}`);
|
||||
};
|
||||
|
||||
const previous_users = $("#compose_invite_users .compose_invite_user");
|
||||
previous_users.length = 1;
|
||||
previous_users[0] = warning_row;
|
||||
const $previous_users = $("#compose_invite_users .compose_invite_user");
|
||||
$previous_users.length = 1;
|
||||
$previous_users[0] = $warning_row;
|
||||
$("#compose_invite_users").hide();
|
||||
|
||||
// Now try to mention the same person again. The template should
|
||||
@@ -788,12 +788,12 @@ test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {
|
||||
stream_data.add_sub(sub);
|
||||
|
||||
// The error message area where it is shown
|
||||
const error_area = $("#compose_resolved_topic");
|
||||
const $error_area = $("#compose_resolved_topic");
|
||||
compose_validate.clear_topic_resolved_warning();
|
||||
// Hack to make this empty for zjquery; this is conceptually done
|
||||
// in the previous line.
|
||||
error_area.html("");
|
||||
assert.ok(!error_area.visible());
|
||||
$error_area.html("");
|
||||
assert.ok(!$error_area.visible());
|
||||
|
||||
compose_state.set_message_type("stream");
|
||||
compose_state.stream_name("Do not exist");
|
||||
@@ -802,25 +802,25 @@ test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {
|
||||
|
||||
// Do not show a warning if stream name does not exist
|
||||
compose_validate.warn_if_topic_resolved(true);
|
||||
assert.ok(!error_area.visible());
|
||||
assert.ok(!$error_area.visible());
|
||||
|
||||
compose_state.stream_name("random");
|
||||
|
||||
// Show the warning now as stream also exists
|
||||
compose_validate.warn_if_topic_resolved(true);
|
||||
assert.ok(error_area.visible());
|
||||
assert.ok($error_area.visible());
|
||||
|
||||
// Call it again with false; this should be a noop.
|
||||
compose_validate.warn_if_topic_resolved(false);
|
||||
assert.ok(error_area.visible());
|
||||
assert.ok($error_area.visible());
|
||||
|
||||
compose_state.topic("hello");
|
||||
|
||||
// The warning will be cleared now
|
||||
compose_validate.warn_if_topic_resolved(true);
|
||||
assert.ok(!error_area.visible());
|
||||
assert.ok(!$error_area.visible());
|
||||
|
||||
// Calling with false won't do anything.
|
||||
compose_validate.warn_if_topic_resolved(false);
|
||||
assert.ok(!error_area.visible());
|
||||
assert.ok(!$error_area.visible());
|
||||
});
|
||||
|
||||
@@ -29,12 +29,12 @@ const server_events_dispatch = zrequire("server_events_dispatch");
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const compose = zrequire("compose");
|
||||
function stub_out_video_calls() {
|
||||
const elem = $("#below-compose-content .video_link");
|
||||
elem.toggle = (show) => {
|
||||
const $elem = $("#below-compose-content .video_link");
|
||||
$elem.toggle = (show) => {
|
||||
if (show) {
|
||||
elem.show();
|
||||
$elem.show();
|
||||
} else {
|
||||
elem.hide();
|
||||
$elem.hide();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -78,14 +78,14 @@ test("videos", ({override, override_rewire}) => {
|
||||
(function test_no_provider_video_link_compose_clicked() {
|
||||
let called = false;
|
||||
|
||||
const textarea = $.create("target-stub");
|
||||
textarea.set_parents_result(".message_edit_form", []);
|
||||
const $textarea = $.create("target-stub");
|
||||
$textarea.set_parents_result(".message_edit_form", []);
|
||||
|
||||
const ev = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
target: {
|
||||
to_$: () => textarea,
|
||||
to_$: () => $textarea,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -104,14 +104,14 @@ test("videos", ({override, override_rewire}) => {
|
||||
let syntax_to_insert;
|
||||
let called = false;
|
||||
|
||||
const textarea = $.create("jitsi-target-stub");
|
||||
textarea.set_parents_result(".message_edit_form", []);
|
||||
const $textarea = $.create("jitsi-target-stub");
|
||||
$textarea.set_parents_result(".message_edit_form", []);
|
||||
|
||||
const ev = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
target: {
|
||||
to_$: () => textarea,
|
||||
to_$: () => $textarea,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -142,14 +142,14 @@ test("videos", ({override, override_rewire}) => {
|
||||
let syntax_to_insert;
|
||||
let called = false;
|
||||
|
||||
const textarea = $.create("zoom-target-stub");
|
||||
textarea.set_parents_result(".message_edit_form", []);
|
||||
const $textarea = $.create("zoom-target-stub");
|
||||
$textarea.set_parents_result(".message_edit_form", []);
|
||||
|
||||
const ev = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
target: {
|
||||
to_$: () => textarea,
|
||||
to_$: () => $textarea,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -188,14 +188,14 @@ test("videos", ({override, override_rewire}) => {
|
||||
let syntax_to_insert;
|
||||
let called = false;
|
||||
|
||||
const textarea = $.create("bbb-target-stub");
|
||||
textarea.set_parents_result(".message_edit_form", []);
|
||||
const $textarea = $.create("bbb-target-stub");
|
||||
$textarea.set_parents_result(".message_edit_form", []);
|
||||
|
||||
const ev = {
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
target: {
|
||||
to_$: () => textarea,
|
||||
to_$: () => $textarea,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@ test("draft_model add", ({override}) => {
|
||||
const ls = localstorage();
|
||||
assert.equal(ls.get("draft"), undefined);
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
override(Date, "now", () => 1);
|
||||
const expected = {...draft_1};
|
||||
@@ -136,8 +136,8 @@ test("draft_model edit", () => {
|
||||
assert.equal(ls.get("draft"), undefined);
|
||||
let id;
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
with_overrides(({override}) => {
|
||||
override(Date, "now", () => 1);
|
||||
@@ -161,8 +161,8 @@ test("draft_model delete", ({override}) => {
|
||||
const ls = localstorage();
|
||||
assert.equal(ls.get("draft"), undefined);
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
override(Date, "now", () => 1);
|
||||
const expected = {...draft_1};
|
||||
@@ -212,8 +212,8 @@ test("initialize", ({override_rewire}) => {
|
||||
assert.ok(called);
|
||||
};
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
drafts.initialize();
|
||||
});
|
||||
@@ -239,8 +239,8 @@ test("remove_old_drafts", () => {
|
||||
ls.set("drafts", data);
|
||||
assert.deepEqual(draft_model.get(), data);
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
drafts.remove_old_drafts();
|
||||
assert.deepEqual(draft_model.get(), {id3: draft_3});
|
||||
@@ -256,9 +256,9 @@ test("update_draft", ({override}) => {
|
||||
override(compose_state, "get_message_type", () => "private");
|
||||
override(compose_state, "private_message_recipient", () => "aaron@zulip.com");
|
||||
|
||||
const container = $(".top_left_drafts");
|
||||
const child = $(".unread_count");
|
||||
container.set_find_results(".unread_count", child);
|
||||
const $container = $(".top_left_drafts");
|
||||
const $child = $(".unread_count");
|
||||
$container.set_find_results(".unread_count", $child);
|
||||
|
||||
tippy_args = {
|
||||
content: "translated: Saved as draft",
|
||||
@@ -313,8 +313,8 @@ test("delete_all_drafts", () => {
|
||||
ls.set("drafts", data);
|
||||
assert.deepEqual(draft_model.get(), data);
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
drafts.delete_all_drafts();
|
||||
assert.deepEqual(draft_model.get(), {});
|
||||
@@ -451,8 +451,8 @@ test("format_drafts", ({override_rewire, mock_template}) => {
|
||||
|
||||
expected[0].stream_name = "stream-rename";
|
||||
|
||||
const unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", unread_count);
|
||||
const $unread_count = $('<span class="unread_count"></span>');
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
drafts.launch();
|
||||
timerender.__Rewire__("render_now", stub_render_now);
|
||||
|
||||
@@ -25,12 +25,12 @@ const {DropdownListWidget, MultiSelectDropdownListWidget} = zrequire("dropdown_l
|
||||
|
||||
// For DropdownListWidget
|
||||
const setup_dropdown_zjquery_data = (name) => {
|
||||
const input_group = $(".input_group");
|
||||
const reset_button = $(".dropdown_list_reset_button");
|
||||
input_group.set_find_results(".dropdown_list_reset_button", reset_button);
|
||||
$(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`).closest = () => input_group;
|
||||
const $input_group = $(".input_group");
|
||||
const $reset_button = $(".dropdown_list_reset_button");
|
||||
$input_group.set_find_results(".dropdown_list_reset_button", $reset_button);
|
||||
$(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`).closest = () => $input_group;
|
||||
const $widget = $(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`);
|
||||
return {reset_button, $widget};
|
||||
return {$reset_button, $widget};
|
||||
};
|
||||
|
||||
run_test("basic_functions", () => {
|
||||
@@ -46,31 +46,31 @@ run_test("basic_functions", () => {
|
||||
render_text: (text) => `rendered: ${text}`,
|
||||
};
|
||||
|
||||
const {reset_button, $widget} = setup_dropdown_zjquery_data(opts.widget_name);
|
||||
const {$reset_button, $widget} = setup_dropdown_zjquery_data(opts.widget_name);
|
||||
|
||||
const widget = new DropdownListWidget(opts);
|
||||
|
||||
assert.equal(widget.value(), "one");
|
||||
assert.equal(updated_value, undefined); // We haven't 'updated' the widget yet.
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
|
||||
widget.update("two");
|
||||
assert.equal($widget.text(), "rendered: two");
|
||||
assert.equal(widget.value(), "two");
|
||||
assert.equal(updated_value, "two");
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
|
||||
widget.update(null);
|
||||
assert.equal($widget.text(), "translated: not set");
|
||||
assert.equal(widget.value(), "");
|
||||
assert.equal(updated_value, null);
|
||||
assert.ok(!reset_button.visible());
|
||||
assert.ok(!$reset_button.visible());
|
||||
|
||||
widget.update("four");
|
||||
assert.equal($widget.text(), "translated: not set");
|
||||
assert.equal(widget.value(), "four");
|
||||
assert.equal(updated_value, "four");
|
||||
assert.ok(!reset_button.visible());
|
||||
assert.ok(!$reset_button.visible());
|
||||
});
|
||||
|
||||
run_test("no_default_value", () => {
|
||||
@@ -110,7 +110,7 @@ run_test("basic MDLW functions", () => {
|
||||
default_text: $t({defaultMessage: "not set"}),
|
||||
};
|
||||
|
||||
const {reset_button, $widget} = setup_multiselect_dropdown_zjquery_data(opts.widget_name);
|
||||
const {$reset_button, $widget} = setup_multiselect_dropdown_zjquery_data(opts.widget_name);
|
||||
const widget = new MultiSelectDropdownListWidget(opts);
|
||||
|
||||
function set_dropdown_variables(widget, value) {
|
||||
@@ -121,7 +121,7 @@ run_test("basic MDLW functions", () => {
|
||||
assert.deepEqual(widget.value(), ["one"]);
|
||||
assert.equal(updated_value, undefined);
|
||||
assert.equal($widget.text(), "one");
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
|
||||
set_dropdown_variables(widget, ["one", "two"]);
|
||||
widget.update(widget.data_selected);
|
||||
@@ -129,7 +129,7 @@ run_test("basic MDLW functions", () => {
|
||||
assert.equal($widget.text(), "one,two");
|
||||
assert.deepEqual(widget.value(), ["one", "two"]);
|
||||
assert.deepEqual(updated_value, ["one", "two"]);
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
|
||||
set_dropdown_variables(widget, ["one", "two", "three"]);
|
||||
widget.update(widget.data_selected);
|
||||
@@ -137,7 +137,7 @@ run_test("basic MDLW functions", () => {
|
||||
assert.equal($widget.text(), "translated: 3 selected");
|
||||
assert.deepEqual(widget.value(), ["one", "two", "three"]);
|
||||
assert.deepEqual(updated_value, ["one", "two", "three"]);
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
|
||||
set_dropdown_variables(widget, null);
|
||||
widget.update(widget.data_selected);
|
||||
@@ -145,7 +145,7 @@ run_test("basic MDLW functions", () => {
|
||||
assert.equal($widget.text(), "translated: not set");
|
||||
assert.equal(widget.value(), null);
|
||||
assert.equal(updated_value, null);
|
||||
assert.ok(!reset_button.visible());
|
||||
assert.ok(!$reset_button.visible());
|
||||
|
||||
set_dropdown_variables(widget, ["one"]);
|
||||
widget.update(widget.data_selected);
|
||||
@@ -153,7 +153,7 @@ run_test("basic MDLW functions", () => {
|
||||
assert.equal($widget.text(), "one");
|
||||
assert.deepEqual(widget.value(), ["one"]);
|
||||
assert.deepEqual(updated_value, ["one"]);
|
||||
assert.ok(reset_button.visible());
|
||||
assert.ok($reset_button.visible());
|
||||
});
|
||||
|
||||
run_test("MDLW no_default_value", () => {
|
||||
|
||||
@@ -67,7 +67,7 @@ people.add_active_user(kitty);
|
||||
*/
|
||||
run_test("typing_events.render_notifications_for_narrow", ({override_rewire, mock_template}) => {
|
||||
// All typists are rendered in `#typing_notifications`.
|
||||
const typing_notifications = $("#typing_notifications");
|
||||
const $typing_notifications = $("#typing_notifications");
|
||||
|
||||
const two_typing_users_ids = [anna.user_id, vronsky.user_id];
|
||||
const two_typing_users = [anna, vronsky];
|
||||
@@ -107,7 +107,7 @@ run_test("typing_events.render_notifications_for_narrow", ({override_rewire, moc
|
||||
typing_events.render_notifications_for_narrow();
|
||||
// Make sure #typing_notifications's html content is set to the rendered template
|
||||
// which we mocked and gave a custom return value.
|
||||
assert.equal(typing_notifications.html(), two_typing_users_rendered_html);
|
||||
assert.equal($typing_notifications.html(), two_typing_users_rendered_html);
|
||||
|
||||
// Now we'll see how setting the second argument to `true`
|
||||
// can be helpful in testing conditionals inside the template.
|
||||
@@ -118,9 +118,9 @@ run_test("typing_events.render_notifications_for_narrow", ({override_rewire, moc
|
||||
// Since we only have two(<MAX_USERS_TO_DISPLAY_NAME) typists, both of them
|
||||
// should be rendered but not 'Several people are typing…'
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
|
||||
|
||||
// Change to having four typists and verify the rendered html has
|
||||
// 'Several people are typing…' but not the list of users.
|
||||
@@ -128,9 +128,9 @@ run_test("typing_events.render_notifications_for_narrow", ({override_rewire, moc
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => four_typing_users_ids);
|
||||
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok(!typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${kitty.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok(!$typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${kitty.full_name} is typing…`));
|
||||
});
|
||||
|
||||
@@ -8,8 +8,8 @@ const blueslip = require("../zjsunit/zblueslip");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
const {user_settings} = require("../zjsunit/zpage_params");
|
||||
|
||||
let window_stub;
|
||||
set_global("to_$", () => window_stub);
|
||||
let $window_stub;
|
||||
set_global("to_$", () => $window_stub);
|
||||
|
||||
mock_esm("../../static/js/search", {
|
||||
update_button_visibility: () => {},
|
||||
@@ -165,7 +165,7 @@ function test_helper({override, override_rewire, change_tab}) {
|
||||
}
|
||||
|
||||
run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window_stub = $.create("window-stub");
|
||||
$window_stub = $.create("window-stub");
|
||||
user_settings.default_view = "recent_topics";
|
||||
|
||||
override_rewire(recent_topics_util, "is_visible", () => false);
|
||||
@@ -189,7 +189,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#all_messages";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[message_viewport, "stop_auto_scrolling"],
|
||||
@@ -199,7 +199,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
]);
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[message_viewport, "stop_auto_scrolling"],
|
||||
@@ -211,7 +211,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#narrow/stream/Denmark";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[message_viewport, "stop_auto_scrolling"],
|
||||
@@ -225,7 +225,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#narrow";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[message_viewport, "stop_auto_scrolling"],
|
||||
@@ -240,7 +240,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#narrow/foo.foo";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[message_viewport, "stop_auto_scrolling"],
|
||||
@@ -251,7 +251,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#streams/whatever";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[stream_settings_ui, "launch"],
|
||||
@@ -261,7 +261,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#reload:send_after_reload=0...";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([]);
|
||||
// If it's reload hash it shouldn't show the default view.
|
||||
assert.equal(recent_topics_ui_shown, false);
|
||||
@@ -269,25 +269,25 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#keyboard-shortcuts/whatever";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([[overlays, "close_for_hash_change"], "info: keyboard-shortcuts"]);
|
||||
|
||||
window.location.hash = "#message-formatting/whatever";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([[overlays, "close_for_hash_change"], "info: message-formatting"]);
|
||||
|
||||
window.location.hash = "#search-operators/whatever";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([[overlays, "close_for_hash_change"], "info: search-operators"]);
|
||||
|
||||
window.location.hash = "#drafts";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[drafts, "launch"],
|
||||
@@ -296,7 +296,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#settings/alert-words";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[settings, "launch"],
|
||||
@@ -305,7 +305,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
window.location.hash = "#organization/user-list-admin";
|
||||
|
||||
helper.clear_events();
|
||||
window_stub.trigger("hashchange");
|
||||
$window_stub.trigger("hashchange");
|
||||
helper.assert_events([
|
||||
[overlays, "close_for_hash_change"],
|
||||
[admin, "launch"],
|
||||
|
||||
@@ -69,12 +69,12 @@ run_test("basics", ({override_rewire, mock_template}) => {
|
||||
blueslip.expect("error", "Pill needs container.");
|
||||
input_pill.create(config);
|
||||
|
||||
const pill_input = $.create("pill_input");
|
||||
const container = $.create("container");
|
||||
container.set_find_results(".input", pill_input);
|
||||
const $pill_input = $.create("pill_input");
|
||||
const $container = $.create("container");
|
||||
$container.set_find_results(".input", $pill_input);
|
||||
|
||||
blueslip.expect("error", "Pill needs create_item_from_text");
|
||||
config.container = container;
|
||||
config.$container = $container;
|
||||
input_pill.create(config);
|
||||
|
||||
blueslip.expect("error", "Pill needs get_text_from_item");
|
||||
@@ -101,9 +101,9 @@ run_test("basics", ({override_rewire, mock_template}) => {
|
||||
let inserted_before;
|
||||
const expected_html = pill_html("JavaScript", "some_id1", example_img_link, status_emoji_info);
|
||||
|
||||
pill_input.before = (elem) => {
|
||||
$pill_input.before = ($elem) => {
|
||||
inserted_before = true;
|
||||
assert.equal(elem.html(), expected_html);
|
||||
assert.equal($elem.html(), expected_html);
|
||||
};
|
||||
|
||||
widget.appendValidatedData(item);
|
||||
@@ -134,27 +134,27 @@ function set_up() {
|
||||
},
|
||||
};
|
||||
|
||||
const pill_input = $.create("pill_input");
|
||||
const $pill_input = $.create("pill_input");
|
||||
|
||||
pill_input[0] = {};
|
||||
pill_input.before = () => {};
|
||||
$pill_input[0] = {};
|
||||
$pill_input.before = () => {};
|
||||
|
||||
const create_item_from_text = (text) => items[text];
|
||||
|
||||
const container = $.create("container");
|
||||
container.set_find_results(".input", pill_input);
|
||||
const $container = $.create("container");
|
||||
$container.set_find_results(".input", $pill_input);
|
||||
|
||||
const config = {
|
||||
container,
|
||||
$container,
|
||||
create_item_from_text,
|
||||
get_text_from_item: (item) => item.display_value,
|
||||
};
|
||||
|
||||
return {
|
||||
config,
|
||||
pill_input,
|
||||
$pill_input,
|
||||
items,
|
||||
container,
|
||||
$container,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -167,16 +167,16 @@ run_test("copy from pill", ({override_rewire, mock_template}) => {
|
||||
override_random_id({override_rewire});
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
widget.appendValue("blue,red");
|
||||
|
||||
const copy_handler = container.get_on_handler("copy", ".pill");
|
||||
const copy_handler = $container.get_on_handler("copy", ".pill");
|
||||
|
||||
let copied_text;
|
||||
|
||||
const pill_stub = {
|
||||
const $pill_stub = {
|
||||
data: (field) => {
|
||||
assert.equal(field, "id");
|
||||
return "some_id2";
|
||||
@@ -195,7 +195,7 @@ run_test("copy from pill", ({override_rewire, mock_template}) => {
|
||||
preventDefault: noop,
|
||||
};
|
||||
|
||||
container.set_find_results(":focus", pill_stub);
|
||||
$container.set_find_results(":focus", $pill_stub);
|
||||
|
||||
copy_handler(e);
|
||||
|
||||
@@ -210,12 +210,12 @@ run_test("paste to input", ({mock_template}) => {
|
||||
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
const items = info.items;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
|
||||
const paste_handler = container.get_on_handler("paste", ".input");
|
||||
const paste_handler = $container.get_on_handler("paste", ".input");
|
||||
|
||||
const paste_text = "blue,yellow";
|
||||
|
||||
@@ -233,7 +233,7 @@ run_test("paste to input", ({mock_template}) => {
|
||||
|
||||
document.execCommand = (cmd, _, text) => {
|
||||
assert.equal(cmd, "insertText");
|
||||
container.find(".input").text(text);
|
||||
$container.find(".input").text(text);
|
||||
};
|
||||
|
||||
paste_handler(e);
|
||||
@@ -257,12 +257,12 @@ run_test("arrows on pills", ({mock_template}) => {
|
||||
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
widget.appendValue("blue,red");
|
||||
|
||||
const key_handler = container.get_on_handler("keydown", ".pill");
|
||||
const key_handler = $container.get_on_handler("keydown", ".pill");
|
||||
|
||||
function test_key(c) {
|
||||
key_handler({
|
||||
@@ -273,7 +273,7 @@ run_test("arrows on pills", ({mock_template}) => {
|
||||
let prev_focused = false;
|
||||
let next_focused = false;
|
||||
|
||||
const pill_stub = {
|
||||
const $pill_stub = {
|
||||
prev: () => ({
|
||||
trigger: (type) => {
|
||||
if (type === "focus") {
|
||||
@@ -290,7 +290,7 @@ run_test("arrows on pills", ({mock_template}) => {
|
||||
}),
|
||||
};
|
||||
|
||||
container.set_find_results(".pill:focus", pill_stub);
|
||||
$container.set_find_results(".pill:focus", $pill_stub);
|
||||
|
||||
// We use the same stub to test both arrows, since we don't
|
||||
// actually cause any real state changes here. We stub out
|
||||
@@ -310,16 +310,16 @@ run_test("left arrow on input", ({mock_template}) => {
|
||||
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
widget.appendValue("blue,red");
|
||||
|
||||
const key_handler = container.get_on_handler("keydown", ".input");
|
||||
const key_handler = $container.get_on_handler("keydown", ".input");
|
||||
|
||||
let last_pill_focused = false;
|
||||
|
||||
container.set_find_results(".pill", {
|
||||
$container.set_find_results(".pill", {
|
||||
last: () => ({
|
||||
trigger: (type) => {
|
||||
if (type === "focus") {
|
||||
@@ -345,17 +345,17 @@ run_test("comma", ({mock_template}) => {
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const items = info.items;
|
||||
const pill_input = info.pill_input;
|
||||
const container = info.container;
|
||||
const $pill_input = info.$pill_input;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
widget.appendValue("blue,red");
|
||||
|
||||
assert.deepEqual(widget.items(), [items.blue, items.red]);
|
||||
|
||||
const key_handler = container.get_on_handler("keydown", ".input");
|
||||
const key_handler = $container.get_on_handler("keydown", ".input");
|
||||
|
||||
pill_input.text(" yel");
|
||||
$pill_input.text(" yel");
|
||||
|
||||
key_handler({
|
||||
key: ",",
|
||||
@@ -364,7 +364,7 @@ run_test("comma", ({mock_template}) => {
|
||||
|
||||
assert.deepEqual(widget.items(), [items.blue, items.red]);
|
||||
|
||||
pill_input.text(" yellow");
|
||||
$pill_input.text(" yellow");
|
||||
|
||||
key_handler({
|
||||
key: ",",
|
||||
@@ -383,14 +383,14 @@ run_test("Enter key with text", ({mock_template}) => {
|
||||
const info = set_up();
|
||||
const config = info.config;
|
||||
const items = info.items;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
widget.appendValue("blue,red");
|
||||
|
||||
assert.deepEqual(widget.items(), [items.blue, items.red]);
|
||||
|
||||
const key_handler = container.get_on_handler("keydown", ".input");
|
||||
const key_handler = $container.get_on_handler("keydown", ".input");
|
||||
|
||||
key_handler({
|
||||
key: "Enter",
|
||||
@@ -415,13 +415,13 @@ run_test("insert_remove", ({override_rewire, mock_template}) => {
|
||||
const info = set_up();
|
||||
|
||||
const config = info.config;
|
||||
const pill_input = info.pill_input;
|
||||
const $pill_input = info.$pill_input;
|
||||
const items = info.items;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const inserted_html = [];
|
||||
pill_input.before = (elem) => {
|
||||
inserted_html.push(elem.html());
|
||||
$pill_input.before = ($elem) => {
|
||||
inserted_html.push($elem.html());
|
||||
};
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
@@ -450,11 +450,11 @@ run_test("insert_remove", ({override_rewire, mock_template}) => {
|
||||
|
||||
assert.deepEqual(widget.items(), [items.blue, items.red, items.yellow]);
|
||||
|
||||
assert.equal(pill_input.text(), "chartreuse, mauve");
|
||||
assert.equal($pill_input.text(), "chartreuse, mauve");
|
||||
|
||||
assert.equal(widget.is_pending(), true);
|
||||
widget.clear_text();
|
||||
assert.equal(pill_input.text(), "");
|
||||
assert.equal($pill_input.text(), "");
|
||||
assert.equal(widget.is_pending(), false);
|
||||
|
||||
let color_removed;
|
||||
@@ -469,7 +469,7 @@ run_test("insert_remove", ({override_rewire, mock_template}) => {
|
||||
pill.$element.remove = set_colored_removed_func(pill.item.display_value);
|
||||
}
|
||||
|
||||
let key_handler = container.get_on_handler("keydown", ".input");
|
||||
let key_handler = $container.get_on_handler("keydown", ".input");
|
||||
|
||||
key_handler({
|
||||
key: "Backspace",
|
||||
@@ -486,7 +486,7 @@ run_test("insert_remove", ({override_rewire, mock_template}) => {
|
||||
|
||||
let next_pill_focused = false;
|
||||
|
||||
const next_pill_stub = {
|
||||
const $next_pill_stub = {
|
||||
trigger: (type) => {
|
||||
if (type === "focus") {
|
||||
next_pill_focused = true;
|
||||
@@ -494,17 +494,17 @@ run_test("insert_remove", ({override_rewire, mock_template}) => {
|
||||
},
|
||||
};
|
||||
|
||||
const focus_pill_stub = {
|
||||
next: () => next_pill_stub,
|
||||
const $focus_pill_stub = {
|
||||
next: () => $next_pill_stub,
|
||||
data: (field) => {
|
||||
assert.equal(field, "id");
|
||||
return "some_id1";
|
||||
},
|
||||
};
|
||||
|
||||
container.set_find_results(".pill:focus", focus_pill_stub);
|
||||
$container.set_find_results(".pill:focus", $focus_pill_stub);
|
||||
|
||||
key_handler = container.get_on_handler("keydown", ".pill");
|
||||
key_handler = $container.get_on_handler("keydown", ".pill");
|
||||
key_handler({
|
||||
key: "Backspace",
|
||||
preventDefault: noop,
|
||||
@@ -526,7 +526,7 @@ run_test("exit button on pill", ({override_rewire, mock_template}) => {
|
||||
|
||||
const config = info.config;
|
||||
const items = info.items;
|
||||
const container = info.container;
|
||||
const $container = info.$container;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
|
||||
@@ -539,7 +539,7 @@ run_test("exit button on pill", ({override_rewire, mock_template}) => {
|
||||
|
||||
let next_pill_focused = false;
|
||||
|
||||
const next_pill_stub = {
|
||||
const $next_pill_stub = {
|
||||
trigger: (type) => {
|
||||
if (type === "focus") {
|
||||
next_pill_focused = true;
|
||||
@@ -547,8 +547,8 @@ run_test("exit button on pill", ({override_rewire, mock_template}) => {
|
||||
},
|
||||
};
|
||||
|
||||
const curr_pill_stub = {
|
||||
next: () => next_pill_stub,
|
||||
const $curr_pill_stub = {
|
||||
next: () => $next_pill_stub,
|
||||
data: (field) => {
|
||||
assert.equal(field, "id");
|
||||
return "some_id1";
|
||||
@@ -559,7 +559,7 @@ run_test("exit button on pill", ({override_rewire, mock_template}) => {
|
||||
to_$: () => ({
|
||||
closest: (sel) => {
|
||||
assert.equal(sel, ".pill");
|
||||
return curr_pill_stub;
|
||||
return $curr_pill_stub;
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -567,7 +567,7 @@ run_test("exit button on pill", ({override_rewire, mock_template}) => {
|
||||
const e = {
|
||||
stopPropagation: noop,
|
||||
};
|
||||
const exit_click_handler = container.get_on_handler("click", ".exit");
|
||||
const exit_click_handler = $container.get_on_handler("click", ".exit");
|
||||
|
||||
exit_click_handler.call(exit_button_stub, e);
|
||||
|
||||
@@ -580,13 +580,13 @@ run_test("misc things", () => {
|
||||
const info = set_up();
|
||||
|
||||
const config = info.config;
|
||||
const container = info.container;
|
||||
const pill_input = info.pill_input;
|
||||
const $container = info.$container;
|
||||
const $pill_input = info.$pill_input;
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
|
||||
// animation
|
||||
const animation_end_handler = container.get_on_handler("animationend", ".input");
|
||||
const animation_end_handler = $container.get_on_handler("animationend", ".input");
|
||||
|
||||
let shake_class_removed = false;
|
||||
|
||||
@@ -614,17 +614,17 @@ run_test("misc things", () => {
|
||||
});
|
||||
|
||||
// click on container
|
||||
const container_click_handler = container.get_on_handler("click");
|
||||
const container_click_handler = $container.get_on_handler("click");
|
||||
|
||||
const stub = $.create("the-pill-container");
|
||||
stub.set_find_results(".input", pill_input);
|
||||
stub.is = (sel) => {
|
||||
const $stub = $.create("the-pill-container");
|
||||
$stub.set_find_results(".input", $pill_input);
|
||||
$stub.is = (sel) => {
|
||||
assert.equal(sel, ".pill-container");
|
||||
return true;
|
||||
};
|
||||
|
||||
const this_ = {
|
||||
to_$: () => stub,
|
||||
to_$: () => $stub,
|
||||
};
|
||||
|
||||
container_click_handler.call(this_, {target: this_});
|
||||
@@ -637,18 +637,18 @@ run_test("appendValue/clear", ({mock_template}) => {
|
||||
return html;
|
||||
});
|
||||
|
||||
const pill_input = $.create("pill_input");
|
||||
const container = $.create("container");
|
||||
container.set_find_results(".input", pill_input);
|
||||
const $pill_input = $.create("pill_input");
|
||||
const $container = $.create("container");
|
||||
$container.set_find_results(".input", $pill_input);
|
||||
|
||||
const config = {
|
||||
container,
|
||||
$container,
|
||||
create_item_from_text: (s) => ({type: "color", display_value: s}),
|
||||
get_text_from_item: (s) => s.display_value,
|
||||
};
|
||||
|
||||
pill_input.before = () => {};
|
||||
pill_input[0] = {};
|
||||
$pill_input.before = () => {};
|
||||
$pill_input[0] = {};
|
||||
|
||||
const widget = input_pill.create(config);
|
||||
|
||||
@@ -672,5 +672,5 @@ run_test("appendValue/clear", ({mock_template}) => {
|
||||
|
||||
// Note that we remove colors in the reverse order that we inserted.
|
||||
assert.deepEqual(removed_colors, ["blue", "yellow", "red"]);
|
||||
assert.equal(pill_input[0].textContent, "");
|
||||
assert.equal($pill_input[0].textContent, "");
|
||||
});
|
||||
|
||||
@@ -7,9 +7,9 @@ const $ = require("../zjsunit/zjquery");
|
||||
const keydown_util = zrequire("keydown_util");
|
||||
|
||||
run_test("test_early_returns", () => {
|
||||
const stub = $.create("stub");
|
||||
const $stub = $.create("stub");
|
||||
const opts = {
|
||||
elem: stub,
|
||||
$elem: $stub,
|
||||
handlers: {
|
||||
ArrowLeft: () => {
|
||||
throw new Error("do not dispatch this with alt key");
|
||||
@@ -24,14 +24,14 @@ run_test("test_early_returns", () => {
|
||||
key: "a", // not in keys
|
||||
};
|
||||
|
||||
stub.trigger(e1);
|
||||
$stub.trigger(e1);
|
||||
|
||||
const e2 = {
|
||||
type: "keydown",
|
||||
key: "Enter", // no handler
|
||||
};
|
||||
|
||||
stub.trigger(e2);
|
||||
$stub.trigger(e2);
|
||||
|
||||
const e3 = {
|
||||
type: "keydown",
|
||||
@@ -39,5 +39,5 @@ run_test("test_early_returns", () => {
|
||||
altKey: true, // let browser handle
|
||||
};
|
||||
|
||||
stub.trigger(e3);
|
||||
$stub.trigger(e3);
|
||||
});
|
||||
|
||||
@@ -30,21 +30,21 @@ function test(label, f) {
|
||||
}
|
||||
|
||||
test("pan_and_zoom", ({override_rewire}) => {
|
||||
const img = $.create("img-stub");
|
||||
const link = $.create("link-stub");
|
||||
const msg = $.create("msg-stub");
|
||||
const $img = $.create("img-stub");
|
||||
const $link = $.create("link-stub");
|
||||
const $msg = $.create("msg-stub");
|
||||
|
||||
$(img).closest = () => [];
|
||||
$($img).closest = () => [];
|
||||
|
||||
img.set_parent(link);
|
||||
link.closest = () => msg;
|
||||
$img.set_parent($link);
|
||||
$link.closest = () => $msg;
|
||||
|
||||
override_rewire(rows, "id", (row) => {
|
||||
assert.equal(row, msg);
|
||||
override_rewire(rows, "id", ($row) => {
|
||||
assert.equal($row, $msg);
|
||||
return 1234;
|
||||
});
|
||||
|
||||
img.attr("src", "example");
|
||||
$img.attr("src", "example");
|
||||
|
||||
let fetched_zid;
|
||||
|
||||
@@ -55,25 +55,25 @@ test("pan_and_zoom", ({override_rewire}) => {
|
||||
|
||||
override_rewire(lightbox, "render_lightbox_list_images", () => {});
|
||||
const open_image = lightbox.build_open_image_function();
|
||||
open_image(img);
|
||||
open_image($img);
|
||||
|
||||
assert.equal(fetched_zid, 1234);
|
||||
});
|
||||
|
||||
test("youtube", ({override_rewire}) => {
|
||||
const href = "https://youtube.com/some-random-clip";
|
||||
const img = $.create("img-stub");
|
||||
const link = $.create("link-stub");
|
||||
const msg = $.create("msg-stub");
|
||||
const $img = $.create("img-stub");
|
||||
const $link = $.create("link-stub");
|
||||
const $msg = $.create("msg-stub");
|
||||
|
||||
override_rewire(rows, "id", (row) => {
|
||||
assert.equal(row, msg);
|
||||
override_rewire(rows, "id", ($row) => {
|
||||
assert.equal($row, $msg);
|
||||
return 4321;
|
||||
});
|
||||
|
||||
$(img).attr("src", href);
|
||||
$($img).attr("src", href);
|
||||
|
||||
$(img).closest = (sel) => {
|
||||
$($img).closest = (sel) => {
|
||||
if (sel === ".youtube-video") {
|
||||
// We just need a nonempty array to
|
||||
// set is_youtube_video to true.
|
||||
@@ -82,13 +82,13 @@ test("youtube", ({override_rewire}) => {
|
||||
return [];
|
||||
};
|
||||
|
||||
img.set_parent(link);
|
||||
link.closest = () => msg;
|
||||
link.attr("href", href);
|
||||
$img.set_parent($link);
|
||||
$link.closest = () => $msg;
|
||||
$link.attr("href", href);
|
||||
|
||||
override_rewire(lightbox, "render_lightbox_list_images", () => {});
|
||||
|
||||
const open_image = lightbox.build_open_image_function();
|
||||
open_image(img);
|
||||
open_image($img);
|
||||
assert.equal($(".image-actions .open").attr("href"), href);
|
||||
});
|
||||
|
||||
@@ -70,12 +70,12 @@ run_test("single item list", ({override}) => {
|
||||
});
|
||||
const cursor = new ListCursor(conf);
|
||||
|
||||
const li_stub = {
|
||||
const $li_stub = {
|
||||
length: 1,
|
||||
addClass: () => {},
|
||||
};
|
||||
|
||||
override(conf.list, "find_li", () => li_stub);
|
||||
override(conf.list, "find_li", () => $li_stub);
|
||||
override(cursor, "adjust_scroll", () => {});
|
||||
|
||||
cursor.go_to(valid_key);
|
||||
|
||||
@@ -41,81 +41,81 @@ const ListWidget = zrequire("list_widget");
|
||||
// in the real code.
|
||||
|
||||
function make_container() {
|
||||
const container = {};
|
||||
const $container = {};
|
||||
|
||||
container.length = () => 1;
|
||||
container.is = () => false;
|
||||
container.css = (prop) => {
|
||||
$container.length = () => 1;
|
||||
$container.is = () => false;
|
||||
$container.css = (prop) => {
|
||||
assert.equal(prop, "max-height");
|
||||
return "none";
|
||||
};
|
||||
|
||||
// Make our append function just set a field we can
|
||||
// check in our tests.
|
||||
container.append = (data) => {
|
||||
container.appended_data = data;
|
||||
$container.append = ($data) => {
|
||||
$container.$appended_data = $data;
|
||||
};
|
||||
|
||||
return container;
|
||||
return $container;
|
||||
}
|
||||
|
||||
function make_scroll_container() {
|
||||
const scroll_container = {};
|
||||
const $scroll_container = {};
|
||||
|
||||
scroll_container.cleared = false;
|
||||
$scroll_container.cleared = false;
|
||||
|
||||
// Capture the scroll callback so we can call it in
|
||||
// our tests.
|
||||
scroll_container.on = (ev, f) => {
|
||||
$scroll_container.on = (ev, f) => {
|
||||
assert.equal(ev, "scroll.list_widget_container");
|
||||
scroll_container.call_scroll = () => {
|
||||
f.call(scroll_container);
|
||||
$scroll_container.call_scroll = () => {
|
||||
f.call($scroll_container);
|
||||
};
|
||||
};
|
||||
|
||||
scroll_container.off = (ev) => {
|
||||
$scroll_container.off = (ev) => {
|
||||
assert.equal(ev, "scroll.list_widget_container");
|
||||
scroll_container.cleared = true;
|
||||
$scroll_container.cleared = true;
|
||||
};
|
||||
|
||||
return scroll_container;
|
||||
return $scroll_container;
|
||||
}
|
||||
|
||||
function make_sort_container() {
|
||||
const sort_container = {};
|
||||
const $sort_container = {};
|
||||
|
||||
sort_container.cleared = false;
|
||||
$sort_container.cleared = false;
|
||||
|
||||
sort_container.on = (ev, sel, f) => {
|
||||
$sort_container.on = (ev, sel, f) => {
|
||||
assert.equal(ev, "click.list_widget_sort");
|
||||
assert.equal(sel, "[data-sort]");
|
||||
sort_container.f = f;
|
||||
$sort_container.f = f;
|
||||
};
|
||||
|
||||
sort_container.off = (ev) => {
|
||||
$sort_container.off = (ev) => {
|
||||
assert.equal(ev, "click.list_widget_sort");
|
||||
sort_container.cleared = true;
|
||||
$sort_container.cleared = true;
|
||||
};
|
||||
|
||||
return sort_container;
|
||||
return $sort_container;
|
||||
}
|
||||
|
||||
function make_filter_element() {
|
||||
const element = {};
|
||||
const $element = {};
|
||||
|
||||
element.cleared = false;
|
||||
$element.cleared = false;
|
||||
|
||||
element.on = (ev, f) => {
|
||||
$element.on = (ev, f) => {
|
||||
assert.equal(ev, "input.list_widget_filter");
|
||||
element.f = f;
|
||||
$element.f = f;
|
||||
};
|
||||
|
||||
element.off = (ev) => {
|
||||
$element.off = (ev) => {
|
||||
assert.equal(ev, "input.list_widget_filter");
|
||||
element.cleared = true;
|
||||
$element.cleared = true;
|
||||
};
|
||||
|
||||
return element;
|
||||
return $element;
|
||||
}
|
||||
|
||||
function make_search_input() {
|
||||
@@ -143,15 +143,15 @@ function div(item) {
|
||||
}
|
||||
|
||||
run_test("scrolling", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
|
||||
const items = [];
|
||||
|
||||
let get_scroll_element_called = false;
|
||||
ui.get_scroll_element = (element) => {
|
||||
ui.get_scroll_element = ($element) => {
|
||||
get_scroll_element_called = true;
|
||||
return element;
|
||||
return $element;
|
||||
};
|
||||
|
||||
for (let i = 0; i < 200; i += 1) {
|
||||
@@ -160,38 +160,38 @@ run_test("scrolling", () => {
|
||||
|
||||
const opts = {
|
||||
modifier: (item) => item,
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
};
|
||||
|
||||
container.html = (html) => {
|
||||
$container.html = (html) => {
|
||||
assert.equal(html, "");
|
||||
};
|
||||
ListWidget.create(container, items, opts);
|
||||
ListWidget.create($container, items, opts);
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), items.slice(0, 80).join(""));
|
||||
assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join(""));
|
||||
assert.equal(get_scroll_element_called, true);
|
||||
|
||||
// Set up our fake geometry so it forces a scroll action.
|
||||
scroll_container.scrollTop = 180;
|
||||
scroll_container.clientHeight = 100;
|
||||
scroll_container.scrollHeight = 260;
|
||||
$scroll_container.scrollTop = 180;
|
||||
$scroll_container.clientHeight = 100;
|
||||
$scroll_container.scrollHeight = 260;
|
||||
|
||||
// Scrolling gets the next two elements from the list into
|
||||
// our widget.
|
||||
scroll_container.call_scroll();
|
||||
assert.deepEqual(container.appended_data.html(), items.slice(80, 100).join(""));
|
||||
$scroll_container.call_scroll();
|
||||
assert.deepEqual($container.$appended_data.html(), items.slice(80, 100).join(""));
|
||||
});
|
||||
|
||||
run_test("not_scrolling", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
|
||||
const items = [];
|
||||
|
||||
let get_scroll_element_called = false;
|
||||
ui.get_scroll_element = (element) => {
|
||||
ui.get_scroll_element = ($element) => {
|
||||
get_scroll_element_called = true;
|
||||
return element;
|
||||
return $element;
|
||||
};
|
||||
|
||||
let post_scroll__pre_render_callback_called = false;
|
||||
@@ -211,54 +211,54 @@ run_test("not_scrolling", () => {
|
||||
|
||||
const opts = {
|
||||
modifier: (item) => item,
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
is_scroll_position_for_render: () => false,
|
||||
post_scroll__pre_render_callback,
|
||||
get_min_load_count,
|
||||
};
|
||||
|
||||
container.html = (html) => {
|
||||
$container.html = (html) => {
|
||||
assert.equal(html, "");
|
||||
};
|
||||
ListWidget.create(container, items, opts);
|
||||
ListWidget.create($container, items, opts);
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), items.slice(0, 80).join(""));
|
||||
assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join(""));
|
||||
assert.equal(get_scroll_element_called, true);
|
||||
|
||||
// Set up our fake geometry.
|
||||
scroll_container.scrollTop = 180;
|
||||
scroll_container.clientHeight = 100;
|
||||
scroll_container.scrollHeight = 260;
|
||||
$scroll_container.scrollTop = 180;
|
||||
$scroll_container.clientHeight = 100;
|
||||
$scroll_container.scrollHeight = 260;
|
||||
|
||||
// Since `should_render` is always false, no elements will be
|
||||
// added regardless of scrolling.
|
||||
scroll_container.call_scroll();
|
||||
// appended_data remains the same.
|
||||
assert.deepEqual(container.appended_data.html(), items.slice(0, 80).join(""));
|
||||
$scroll_container.call_scroll();
|
||||
// $appended_data remains the same.
|
||||
assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join(""));
|
||||
assert.equal(post_scroll__pre_render_callback_called, true);
|
||||
assert.equal(get_min_load_count_called, true);
|
||||
});
|
||||
|
||||
run_test("filtering", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
|
||||
const search_input = make_search_input();
|
||||
const $search_input = make_search_input();
|
||||
|
||||
const list = ["apple", "banana", "carrot", "dog", "egg", "fence", "grape"];
|
||||
const opts = {
|
||||
filter: {
|
||||
element: search_input,
|
||||
$element: $search_input,
|
||||
predicate: (item, value) => item.includes(value),
|
||||
},
|
||||
modifier: (item) => div(item),
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
};
|
||||
|
||||
container.html = (html) => {
|
||||
$container.html = (html) => {
|
||||
assert.equal(html, "");
|
||||
};
|
||||
const widget = ListWidget.create(container, list, opts);
|
||||
const widget = ListWidget.create($container, list, opts);
|
||||
|
||||
let expected_html =
|
||||
"<div>apple</div>" +
|
||||
@@ -269,45 +269,45 @@ run_test("filtering", () => {
|
||||
"<div>fence</div>" +
|
||||
"<div>grape</div>";
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
|
||||
// Filtering will pick out dog/egg/grape when we put "g"
|
||||
// into our search input. (This uses the default filter, which
|
||||
// is a glorified indexOf call.)
|
||||
search_input.val = () => "g";
|
||||
search_input.simulate_input_event();
|
||||
$search_input.val = () => "g";
|
||||
$search_input.simulate_input_event();
|
||||
assert.deepEqual(widget.get_current_list(), ["dog", "egg", "grape"]);
|
||||
expected_html = "<div>dog</div><div>egg</div><div>grape</div>";
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
|
||||
// We can insert new data into the widget.
|
||||
const new_data = ["greta", "faye", "gary", "frank", "giraffe", "fox"];
|
||||
|
||||
widget.replace_list_data(new_data);
|
||||
expected_html = "<div>greta</div><div>gary</div><div>giraffe</div>";
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
});
|
||||
|
||||
run_test("no filtering", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
container.html = () => {};
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
$container.html = () => {};
|
||||
|
||||
let callback_called = false;
|
||||
// Opts does not require a filter key.
|
||||
const opts = {
|
||||
modifier: (item) => div(item),
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
callback_after_render: () => {
|
||||
callback_called = true;
|
||||
},
|
||||
};
|
||||
const widget = ListWidget.create(container, ["apple", "banana"], opts);
|
||||
const widget = ListWidget.create($container, ["apple", "banana"], opts);
|
||||
widget.render();
|
||||
assert.deepEqual(callback_called, true);
|
||||
|
||||
const expected_html = "<div>apple</div><div>banana</div>";
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
});
|
||||
|
||||
function sort_button(opts) {
|
||||
@@ -336,7 +336,7 @@ function sort_button(opts) {
|
||||
|
||||
const classList = new Set();
|
||||
|
||||
const button = {
|
||||
const $button = {
|
||||
data,
|
||||
closest: lookup(".progressive-table-wrapper", {
|
||||
data: lookup("list-widget", opts.list_name),
|
||||
@@ -351,47 +351,47 @@ function sort_button(opts) {
|
||||
siblings: lookup(".active", {
|
||||
removeClass: (cls) => {
|
||||
assert.equal(cls, "active");
|
||||
button.siblings_deactivated = true;
|
||||
$button.siblings_deactivated = true;
|
||||
},
|
||||
}),
|
||||
siblings_deactivated: false,
|
||||
to_jquery: () => button,
|
||||
to_jquery: () => $button,
|
||||
};
|
||||
|
||||
return button;
|
||||
return $button;
|
||||
}
|
||||
|
||||
run_test("wire up filter element", () => {
|
||||
const lst = ["alice", "JESSE", "moses", "scott", "Sean", "Xavier"];
|
||||
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const filter_element = make_filter_element();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
const $filter_element = make_filter_element();
|
||||
|
||||
// We don't care about what gets drawn initially.
|
||||
container.html = () => {};
|
||||
$container.html = () => {};
|
||||
|
||||
const opts = {
|
||||
filter: {
|
||||
filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)),
|
||||
element: filter_element,
|
||||
$element: $filter_element,
|
||||
},
|
||||
modifier: (s) => "(" + s + ")",
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
};
|
||||
|
||||
ListWidget.create(container, lst, opts);
|
||||
filter_element.f.apply({value: "se"});
|
||||
assert.equal(container.appended_data.html(), "(JESSE)(moses)(Sean)");
|
||||
ListWidget.create($container, lst, opts);
|
||||
$filter_element.f.apply({value: "se"});
|
||||
assert.equal($container.$appended_data.html(), "(JESSE)(moses)(Sean)");
|
||||
});
|
||||
|
||||
run_test("sorting", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const sort_container = make_sort_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
const $sort_container = make_sort_container();
|
||||
|
||||
let cleared;
|
||||
container.html = (html) => {
|
||||
$container.html = (html) => {
|
||||
assert.equal(html, "");
|
||||
cleared = true;
|
||||
};
|
||||
@@ -406,22 +406,22 @@ run_test("sorting", () => {
|
||||
|
||||
const opts = {
|
||||
name: "sorting-list",
|
||||
parent_container: sort_container,
|
||||
$parent_container: $sort_container,
|
||||
modifier: (item) => div(item.name) + div(item.salary),
|
||||
filter: {
|
||||
predicate: () => true,
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
};
|
||||
|
||||
function html_for(people) {
|
||||
return people.map((item) => opts.modifier(item)).join("");
|
||||
}
|
||||
|
||||
ListWidget.create(container, list, opts);
|
||||
ListWidget.create($container, list, opts);
|
||||
|
||||
let button_opts;
|
||||
let button;
|
||||
let $button;
|
||||
let expected_html;
|
||||
|
||||
button_opts = {
|
||||
@@ -431,31 +431,31 @@ run_test("sorting", () => {
|
||||
active: false,
|
||||
};
|
||||
|
||||
button = sort_button(button_opts);
|
||||
$button = sort_button(button_opts);
|
||||
|
||||
sort_container.f.apply(button);
|
||||
$sort_container.f.apply($button);
|
||||
|
||||
assert.ok(cleared);
|
||||
assert.ok(button.siblings_deactivated);
|
||||
assert.ok($button.siblings_deactivated);
|
||||
|
||||
expected_html = html_for([alice, bob, cal, dave, ellen]);
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
|
||||
// Hit same button again to reverse the data.
|
||||
cleared = false;
|
||||
sort_container.f.apply(button);
|
||||
$sort_container.f.apply($button);
|
||||
assert.ok(cleared);
|
||||
expected_html = html_for([ellen, dave, cal, bob, alice]);
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.ok(button.hasClass("descend"));
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
assert.ok($button.hasClass("descend"));
|
||||
|
||||
// And then hit a third time to go back to the forward sort.
|
||||
cleared = false;
|
||||
sort_container.f.apply(button);
|
||||
$sort_container.f.apply($button);
|
||||
assert.ok(cleared);
|
||||
expected_html = html_for([alice, bob, cal, dave, ellen]);
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.ok(!button.hasClass("descend"));
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
assert.ok(!$button.hasClass("descend"));
|
||||
|
||||
// Now try a numeric sort.
|
||||
button_opts = {
|
||||
@@ -465,32 +465,32 @@ run_test("sorting", () => {
|
||||
active: false,
|
||||
};
|
||||
|
||||
button = sort_button(button_opts);
|
||||
$button = sort_button(button_opts);
|
||||
|
||||
cleared = false;
|
||||
button.siblings_deactivated = false;
|
||||
$button.siblings_deactivated = false;
|
||||
|
||||
sort_container.f.apply(button);
|
||||
$sort_container.f.apply($button);
|
||||
|
||||
assert.ok(cleared);
|
||||
assert.ok(button.siblings_deactivated);
|
||||
assert.ok($button.siblings_deactivated);
|
||||
|
||||
expected_html = html_for([dave, cal, bob, alice, ellen]);
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
|
||||
// Hit same button again to reverse the numeric sort.
|
||||
cleared = false;
|
||||
sort_container.f.apply(button);
|
||||
$sort_container.f.apply($button);
|
||||
assert.ok(cleared);
|
||||
expected_html = html_for([ellen, alice, bob, cal, dave]);
|
||||
assert.deepEqual(container.appended_data.html(), expected_html);
|
||||
assert.ok(button.hasClass("descend"));
|
||||
assert.deepEqual($container.$appended_data.html(), expected_html);
|
||||
assert.ok($button.hasClass("descend"));
|
||||
});
|
||||
|
||||
run_test("custom sort", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
container.html = () => {};
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
$container.html = () => {};
|
||||
|
||||
const n42 = {x: 6, y: 7};
|
||||
const n43 = {x: 1, y: 43};
|
||||
@@ -506,7 +506,7 @@ run_test("custom sort", () => {
|
||||
return a.x * a.y - b.x * b.y;
|
||||
}
|
||||
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
name: "custom-sort-list",
|
||||
modifier: (n) => "(" + n.x + ", " + n.y + ")",
|
||||
sort_fields: {
|
||||
@@ -514,15 +514,15 @@ run_test("custom sort", () => {
|
||||
x_value: sort_by_x,
|
||||
},
|
||||
init_sort: [sort_by_product],
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), "(6, 7)(1, 43)(4, 11)");
|
||||
assert.deepEqual($container.$appended_data.html(), "(6, 7)(1, 43)(4, 11)");
|
||||
|
||||
const widget = ListWidget.get("custom-sort-list");
|
||||
|
||||
widget.sort("x_value");
|
||||
assert.deepEqual(container.appended_data.html(), "(1, 43)(4, 11)(6, 7)");
|
||||
assert.deepEqual($container.$appended_data.html(), "(1, 43)(4, 11)(6, 7)");
|
||||
|
||||
// We can sort without registering the function, too.
|
||||
function sort_by_y(a, b) {
|
||||
@@ -530,97 +530,97 @@ run_test("custom sort", () => {
|
||||
}
|
||||
|
||||
widget.sort(sort_by_y);
|
||||
assert.deepEqual(container.appended_data.html(), "(6, 7)(4, 11)(1, 43)");
|
||||
assert.deepEqual($container.$appended_data.html(), "(6, 7)(4, 11)(1, 43)");
|
||||
});
|
||||
|
||||
run_test("clear_event_handlers", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const sort_container = make_sort_container();
|
||||
const filter_element = make_filter_element();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
const $sort_container = make_sort_container();
|
||||
const $filter_element = make_filter_element();
|
||||
|
||||
// We don't care about actual data for this test.
|
||||
const list = [];
|
||||
container.html = () => {};
|
||||
$container.html = () => {};
|
||||
|
||||
const opts = {
|
||||
name: "list-we-create-twice",
|
||||
parent_container: sort_container,
|
||||
$parent_container: $sort_container,
|
||||
modifier: () => {},
|
||||
filter: {
|
||||
element: filter_element,
|
||||
$element: $filter_element,
|
||||
predicate: () => true,
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
};
|
||||
|
||||
// Create it the first time.
|
||||
ListWidget.create(container, list, opts);
|
||||
assert.equal(sort_container.cleared, false);
|
||||
assert.equal(scroll_container.cleared, false);
|
||||
assert.equal(filter_element.cleared, false);
|
||||
ListWidget.create($container, list, opts);
|
||||
assert.equal($sort_container.cleared, false);
|
||||
assert.equal($scroll_container.cleared, false);
|
||||
assert.equal($filter_element.cleared, false);
|
||||
|
||||
// The second time we'll clear the old events.
|
||||
ListWidget.create(container, list, opts);
|
||||
assert.equal(sort_container.cleared, true);
|
||||
assert.equal(scroll_container.cleared, true);
|
||||
assert.equal(filter_element.cleared, true);
|
||||
ListWidget.create($container, list, opts);
|
||||
assert.equal($sort_container.cleared, true);
|
||||
assert.equal($scroll_container.cleared, true);
|
||||
assert.equal($filter_element.cleared, true);
|
||||
});
|
||||
|
||||
run_test("errors", () => {
|
||||
// We don't care about actual data for this test.
|
||||
const list = ["stub"];
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
|
||||
blueslip.expect("error", "Need opts to create widget.");
|
||||
ListWidget.create(container, list);
|
||||
ListWidget.create($container, list);
|
||||
blueslip.reset();
|
||||
|
||||
blueslip.expect("error", "simplebar_container is missing.");
|
||||
ListWidget.create(container, list, {
|
||||
blueslip.expect("error", "$simplebar_container is missing.");
|
||||
ListWidget.create($container, list, {
|
||||
modifier: "hello world",
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
blueslip.expect("error", "get_item should be a function");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
get_item: "not a function",
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
blueslip.expect("error", "Filter predicate is not a function.");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
filter: {
|
||||
predicate: "wrong type",
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
blueslip.expect("error", "Filterer and predicate are mutually exclusive.");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
filter: {
|
||||
filterer: () => true,
|
||||
predicate: () => true,
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
blueslip.expect("error", "Filter filterer is not a function (or missing).");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
filter: {},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
container.html = () => {};
|
||||
$container.html = () => {};
|
||||
blueslip.expect("error", "List item is not a string: 999");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
modifier: () => 999,
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
});
|
||||
@@ -648,14 +648,14 @@ run_test("sort helpers", () => {
|
||||
});
|
||||
|
||||
run_test("replace_list_data w/filter update", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
container.html = () => {};
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
$container.html = () => {};
|
||||
|
||||
const list = [1, 2, 3, 4];
|
||||
let num_updates = 0;
|
||||
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (n) => "(" + n.toString() + ")",
|
||||
filter: {
|
||||
@@ -664,19 +664,19 @@ run_test("replace_list_data w/filter update", () => {
|
||||
num_updates += 1;
|
||||
},
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
|
||||
assert.equal(num_updates, 0);
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), "(2)(4)");
|
||||
assert.deepEqual($container.$appended_data.html(), "(2)(4)");
|
||||
|
||||
const widget = ListWidget.get("replace-list");
|
||||
widget.replace_list_data([5, 6, 7, 8]);
|
||||
|
||||
assert.equal(num_updates, 1);
|
||||
|
||||
assert.deepEqual(container.appended_data.html(), "(6)(8)");
|
||||
assert.deepEqual($container.$appended_data.html(), "(6)(8)");
|
||||
});
|
||||
|
||||
run_test("opts.get_item", () => {
|
||||
@@ -722,12 +722,12 @@ run_test("opts.get_item", () => {
|
||||
});
|
||||
|
||||
run_test("render item", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
const INITIAL_RENDER_COUNT = 80; // Keep this in sync with the actual code.
|
||||
container.html = () => {};
|
||||
$container.html = () => {};
|
||||
let called = false;
|
||||
scroll_container.find = (query) => {
|
||||
$scroll_container.find = (query) => {
|
||||
const expected_queries = [
|
||||
`tr[data-item='${INITIAL_RENDER_COUNT}']`,
|
||||
`tr[data-item='${INITIAL_RENDER_COUNT - 1}']`,
|
||||
@@ -746,7 +746,7 @@ run_test("render item", () => {
|
||||
replaceWith: (html) => {
|
||||
assert.equal(new_html, html);
|
||||
called = true;
|
||||
container.appended_data.replace(regex, new_html);
|
||||
$container.$appended_data.replace(regex, new_html);
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -756,29 +756,29 @@ run_test("render item", () => {
|
||||
let text = "initial";
|
||||
const get_item = (item) => ({text: `${text}: ${item}`, value: item});
|
||||
|
||||
const widget = ListWidget.create(container, list, {
|
||||
const widget = ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
||||
get_item,
|
||||
html_selector: (item) => `tr[data-item='${item}']`,
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
const item = INITIAL_RENDER_COUNT - 1;
|
||||
|
||||
assert.ok(container.appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
||||
assert.ok(container.appended_data.html().includes("<tr data-item=3>initial: 3</tr>"));
|
||||
assert.ok($container.$appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
||||
assert.ok($container.$appended_data.html().includes("<tr data-item=3>initial: 3</tr>"));
|
||||
text = "updated";
|
||||
called = false;
|
||||
widget.render_item(INITIAL_RENDER_COUNT - 1);
|
||||
assert.ok(called);
|
||||
assert.ok(container.appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
||||
assert.ok($container.$appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
||||
assert.ok(
|
||||
container.appended_data.html().includes(`<tr data-item=${item}>updated: ${item}</tr>`),
|
||||
$container.$appended_data.html().includes(`<tr data-item=${item}>updated: ${item}</tr>`),
|
||||
);
|
||||
|
||||
// Item 80 should not be in the rendered list. (0 indexed)
|
||||
assert.ok(
|
||||
!container.appended_data
|
||||
!$container.$appended_data
|
||||
.html()
|
||||
.includes(
|
||||
`<tr data-item=${INITIAL_RENDER_COUNT}>initial: ${INITIAL_RENDER_COUNT}</tr>`,
|
||||
@@ -793,24 +793,24 @@ run_test("render item", () => {
|
||||
// Tests below this are for the corner cases, where we abort the rerender.
|
||||
|
||||
blueslip.expect("error", "html_selector should be a function.");
|
||||
ListWidget.create(container, list, {
|
||||
ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
||||
get_item,
|
||||
html_selector: "hello world",
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
blueslip.reset();
|
||||
|
||||
let get_item_called;
|
||||
const widget_2 = ListWidget.create(container, list, {
|
||||
const widget_2 = ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
||||
get_item: (item) => {
|
||||
get_item_called = true;
|
||||
return item;
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
get_item_called = false;
|
||||
widget_2.render_item(item);
|
||||
@@ -818,12 +818,12 @@ run_test("render item", () => {
|
||||
assert.ok(!get_item_called);
|
||||
|
||||
let rendering_item = false;
|
||||
const widget_3 = ListWidget.create(container, list, {
|
||||
const widget_3 = ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (item) => (rendering_item ? undefined : `${item}\n`),
|
||||
get_item,
|
||||
html_selector: (item) => `tr[data-item='${item}']`,
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
// Once we have initially rendered the widget, change the
|
||||
// behavior of the modifier function.
|
||||
@@ -834,16 +834,16 @@ run_test("render item", () => {
|
||||
});
|
||||
|
||||
run_test("Multiselect dropdown retain_selected_items", () => {
|
||||
const container = make_container();
|
||||
const scroll_container = make_scroll_container();
|
||||
const filter_element = make_filter_element();
|
||||
const $container = make_container();
|
||||
const $scroll_container = make_scroll_container();
|
||||
const $filter_element = make_filter_element();
|
||||
let data_rendered = [];
|
||||
|
||||
const list = ["one", "two", "three", "four"].map((x) => ({name: x, value: x}));
|
||||
const data = ["one"]; // Data initially selected.
|
||||
|
||||
container.html = () => {};
|
||||
container.find = (elem) => DropdownItem(elem);
|
||||
$container.html = () => {};
|
||||
$container.find = (elem) => DropdownItem(elem);
|
||||
|
||||
// We essentially create fake jQuery functions
|
||||
// whose return value are stored in objects so that
|
||||
@@ -880,8 +880,8 @@ run_test("Multiselect dropdown retain_selected_items", () => {
|
||||
return ListItem(element, temp);
|
||||
}
|
||||
|
||||
function prepend(data) {
|
||||
temp.prepended_data = data.html();
|
||||
function prepend($data) {
|
||||
temp.prepended_data = $data.html();
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -890,17 +890,17 @@ run_test("Multiselect dropdown retain_selected_items", () => {
|
||||
};
|
||||
}
|
||||
|
||||
const widget = ListWidget.create(container, list, {
|
||||
const widget = ListWidget.create($container, list, {
|
||||
name: "replace-list",
|
||||
modifier: (item) => `<li data-value="${item.value}">${item.name}</li>\n`,
|
||||
multiselect: {
|
||||
selected_items: data,
|
||||
},
|
||||
filter: {
|
||||
element: filter_element,
|
||||
$element: $filter_element,
|
||||
predicate: () => true,
|
||||
},
|
||||
simplebar_container: scroll_container,
|
||||
$simplebar_container: $scroll_container,
|
||||
});
|
||||
|
||||
const expected_value = [
|
||||
|
||||
@@ -117,9 +117,9 @@ run_test("update_messages", () => {
|
||||
page_params.realm_allow_edit_history = false;
|
||||
message_list.narrowed = "stub-to-ignore";
|
||||
|
||||
const message_edit_history_modal = $.create("#message-edit-history");
|
||||
const modal = $.create("micromodal").addClass("modal--open");
|
||||
message_edit_history_modal.set_parents_result(".micromodal", modal);
|
||||
const $message_edit_history_modal = $.create("#message-edit-history");
|
||||
const $modal = $.create("micromodal").addClass("modal--open");
|
||||
$message_edit_history_modal.set_parents_result(".micromodal", $modal);
|
||||
|
||||
// TEST THIS:
|
||||
message_events.update_messages(events);
|
||||
|
||||
@@ -27,47 +27,47 @@ run_test("basics w/progress bar", () => {
|
||||
let password;
|
||||
let warning;
|
||||
|
||||
const bar = (function () {
|
||||
const self = {};
|
||||
const $bar = (function () {
|
||||
const $self = {};
|
||||
|
||||
self.width = (width) => {
|
||||
self.w = width;
|
||||
return self;
|
||||
$self.width = (width) => {
|
||||
$self.w = width;
|
||||
return $self;
|
||||
};
|
||||
|
||||
self.removeClass = (arg) => {
|
||||
$self.removeClass = (arg) => {
|
||||
assert.equal(arg, "bar-success bar-danger");
|
||||
return self;
|
||||
return $self;
|
||||
};
|
||||
|
||||
self.addClass = (arg) => {
|
||||
self.added_class = arg;
|
||||
return self;
|
||||
$self.addClass = (arg) => {
|
||||
$self.added_class = arg;
|
||||
return $self;
|
||||
};
|
||||
|
||||
return self;
|
||||
return $self;
|
||||
})();
|
||||
|
||||
password = "z!X4@S_&";
|
||||
accepted = password_quality(password, bar, password_field(10, 80000));
|
||||
accepted = password_quality(password, $bar, password_field(10, 80000));
|
||||
assert.ok(!accepted);
|
||||
assert.equal(bar.w, "39.7%");
|
||||
assert.equal(bar.added_class, "bar-danger");
|
||||
assert.equal($bar.w, "39.7%");
|
||||
assert.equal($bar.added_class, "bar-danger");
|
||||
warning = password_warning(password, password_field(10));
|
||||
assert.equal(warning, "translated: Password should be at least 10 characters long");
|
||||
|
||||
password = "foo";
|
||||
accepted = password_quality(password, bar, password_field(2, 200));
|
||||
accepted = password_quality(password, $bar, password_field(2, 200));
|
||||
assert.ok(accepted);
|
||||
assert.equal(bar.w, "10.390277164940581%");
|
||||
assert.equal(bar.added_class, "bar-success");
|
||||
assert.equal($bar.w, "10.390277164940581%");
|
||||
assert.equal($bar.added_class, "bar-success");
|
||||
warning = password_warning(password, password_field(2));
|
||||
assert.equal(warning, "translated: Password is too weak");
|
||||
|
||||
password = "aaaaaaaa";
|
||||
accepted = password_quality(password, bar, password_field(6, 1e100));
|
||||
accepted = password_quality(password, $bar, password_field(6, 1e100));
|
||||
assert.ok(!accepted);
|
||||
assert.equal(bar.added_class, "bar-danger");
|
||||
assert.equal($bar.added_class, "bar-danger");
|
||||
warning = password_warning(password, password_field(6));
|
||||
assert.equal(warning, 'Repeats like "aaa" are easy to guess');
|
||||
});
|
||||
|
||||
@@ -19,19 +19,19 @@ const user_groups = zrequire("user_groups");
|
||||
// set global test variables.
|
||||
let sort_recipients_called = false;
|
||||
let sort_streams_called = false;
|
||||
const fake_rendered_person = $.create("fake-rendered-person");
|
||||
const fake_rendered_stream = $.create("fake-rendered-stream");
|
||||
const fake_rendered_group = $.create("fake-rendered-group");
|
||||
const $fake_rendered_person = $.create("fake-rendered-person");
|
||||
const $fake_rendered_stream = $.create("fake-rendered-stream");
|
||||
const $fake_rendered_group = $.create("fake-rendered-group");
|
||||
|
||||
mock_esm("../../static/js/typeahead_helper", {
|
||||
render_person() {
|
||||
return fake_rendered_person;
|
||||
return $fake_rendered_person;
|
||||
},
|
||||
render_user_group() {
|
||||
return fake_rendered_group;
|
||||
return $fake_rendered_group;
|
||||
},
|
||||
render_stream() {
|
||||
return fake_rendered_stream;
|
||||
return $fake_rendered_stream;
|
||||
},
|
||||
sort_streams() {
|
||||
sort_streams_called = true;
|
||||
@@ -113,20 +113,20 @@ run_test("set_up", ({mock_template}) => {
|
||||
return html;
|
||||
});
|
||||
let input_pill_typeahead_called = false;
|
||||
const fake_input = $.create(".input");
|
||||
fake_input.before = noop;
|
||||
const $fake_input = $.create(".input");
|
||||
$fake_input.before = noop;
|
||||
|
||||
const container = $.create(".pill-container");
|
||||
container.find = () => fake_input;
|
||||
const $container = $.create(".pill-container");
|
||||
$container.find = () => $fake_input;
|
||||
|
||||
const pill_widget = input_pill.create({
|
||||
container,
|
||||
const $pill_widget = input_pill.create({
|
||||
$container,
|
||||
create_item_from_text: noop,
|
||||
get_text_from_item: noop,
|
||||
});
|
||||
|
||||
let opts = {};
|
||||
fake_input.typeahead = (config) => {
|
||||
$fake_input.typeahead = (config) => {
|
||||
assert.equal(config.items, 5);
|
||||
assert.ok(config.fixed);
|
||||
assert.ok(config.dropup);
|
||||
@@ -154,7 +154,7 @@ run_test("set_up", ({mock_template}) => {
|
||||
// Test stream highlighter for widgets that allow stream pills.
|
||||
assert.equal(
|
||||
config.highlighter.call(fake_stream_this, denmark),
|
||||
fake_rendered_stream,
|
||||
$fake_rendered_stream,
|
||||
);
|
||||
}
|
||||
if (opts.user_group && opts.user) {
|
||||
@@ -162,17 +162,17 @@ run_test("set_up", ({mock_template}) => {
|
||||
// then we should check that each of them rendered correctly.
|
||||
assert.equal(
|
||||
config.highlighter.call(fake_group_this, testers),
|
||||
fake_rendered_group,
|
||||
$fake_rendered_group,
|
||||
);
|
||||
assert.equal(config.highlighter.call(fake_person_this, me), fake_rendered_person);
|
||||
assert.equal(config.highlighter.call(fake_person_this, me), $fake_rendered_person);
|
||||
}
|
||||
if (opts.user && !opts.user_group) {
|
||||
assert.equal(config.highlighter.call(fake_person_this, me), fake_rendered_person);
|
||||
assert.equal(config.highlighter.call(fake_person_this, me), $fake_rendered_person);
|
||||
}
|
||||
if (!opts.user && opts.user_group) {
|
||||
assert.equal(
|
||||
config.highlighter.call(fake_group_this, testers),
|
||||
fake_rendered_group,
|
||||
$fake_rendered_group,
|
||||
);
|
||||
}
|
||||
})();
|
||||
@@ -288,7 +288,7 @@ run_test("set_up", ({mock_template}) => {
|
||||
// updater in pill_typeahead.
|
||||
|
||||
function number_of_pills() {
|
||||
const pills = pill_widget.items();
|
||||
const pills = $pill_widget.items();
|
||||
return pills.length;
|
||||
}
|
||||
assert.equal(number_of_pills(), 0);
|
||||
@@ -307,7 +307,7 @@ run_test("set_up", ({mock_template}) => {
|
||||
};
|
||||
|
||||
function test_pill_typeahead(opts) {
|
||||
pill_typeahead.set_up(fake_input, pill_widget, opts);
|
||||
pill_typeahead.set_up($fake_input, $pill_widget, opts);
|
||||
assert.ok(input_pill_typeahead_called);
|
||||
}
|
||||
|
||||
@@ -339,6 +339,6 @@ run_test("set_up", ({mock_template}) => {
|
||||
opts = {};
|
||||
input_pill_typeahead_called = false;
|
||||
blueslip.expect("error", "Unspecified possible item types");
|
||||
pill_typeahead.set_up(fake_input, pill_widget, {});
|
||||
pill_typeahead.set_up($fake_input, $pill_widget, {});
|
||||
assert.ok(!input_pill_typeahead_called);
|
||||
});
|
||||
|
||||
@@ -16,23 +16,23 @@ run_test("update_dom_with_unread_counts", () => {
|
||||
narrow_state.set_current_filter("stub");
|
||||
assert.equal(narrow_state.active(), true);
|
||||
|
||||
const total_count = $.create("total-count-stub");
|
||||
const private_li = $(".top_left_private_messages .private_messages_header");
|
||||
private_li.set_find_results(".unread_count", total_count);
|
||||
const $total_count = $.create("total-count-stub");
|
||||
const $private_li = $(".top_left_private_messages .private_messages_header");
|
||||
$private_li.set_find_results(".unread_count", $total_count);
|
||||
|
||||
counts = {
|
||||
private_message_count: 10,
|
||||
};
|
||||
|
||||
pm_list.update_dom_with_unread_counts(counts);
|
||||
assert.equal(total_count.text(), "10");
|
||||
assert.ok(total_count.visible());
|
||||
assert.equal($total_count.text(), "10");
|
||||
assert.ok($total_count.visible());
|
||||
|
||||
counts = {
|
||||
private_message_count: 0,
|
||||
};
|
||||
|
||||
pm_list.update_dom_with_unread_counts(counts);
|
||||
assert.equal(total_count.text(), "");
|
||||
assert.ok(!total_count.visible());
|
||||
assert.equal($total_count.text(), "");
|
||||
assert.ok(!$total_count.visible());
|
||||
});
|
||||
|
||||
@@ -210,7 +210,7 @@ run_test("activate another person poll", ({mock_template}) => {
|
||||
mock_template("widgets/poll_widget.hbs", false, () => "widgets/poll_widget");
|
||||
mock_template("widgets/poll_widget_results.hbs", false, () => "widgets/poll_widget_results");
|
||||
|
||||
const widget_elem = $("<div>").addClass("widget-content");
|
||||
const $widget_elem = $("<div>").addClass("widget-content");
|
||||
|
||||
let out_data; // Used to check the event data sent to the server
|
||||
const callback = (data) => {
|
||||
@@ -218,7 +218,7 @@ run_test("activate another person poll", ({mock_template}) => {
|
||||
};
|
||||
|
||||
const opts = {
|
||||
elem: widget_elem,
|
||||
$elem: $widget_elem,
|
||||
callback,
|
||||
message: {
|
||||
sender_id: alice.user_id,
|
||||
@@ -229,53 +229,53 @@ run_test("activate another person poll", ({mock_template}) => {
|
||||
};
|
||||
|
||||
const set_widget_find_result = (selector) => {
|
||||
const elem = $.create(selector);
|
||||
widget_elem.set_find_results(selector, elem);
|
||||
return elem;
|
||||
const $elem = $.create(selector);
|
||||
$widget_elem.set_find_results(selector, $elem);
|
||||
return $elem;
|
||||
};
|
||||
|
||||
const poll_option = set_widget_find_result("button.poll-option");
|
||||
const poll_option_input = set_widget_find_result("input.poll-option");
|
||||
const widget_option_container = set_widget_find_result("ul.poll-widget");
|
||||
const $poll_option = set_widget_find_result("button.poll-option");
|
||||
const $poll_option_input = set_widget_find_result("input.poll-option");
|
||||
const $widget_option_container = set_widget_find_result("ul.poll-widget");
|
||||
|
||||
const poll_question_submit = set_widget_find_result("button.poll-question-check");
|
||||
const poll_edit_question = set_widget_find_result(".poll-edit-question");
|
||||
const poll_question_header = set_widget_find_result(".poll-question-header");
|
||||
const poll_question_container = set_widget_find_result(".poll-question-bar");
|
||||
const poll_option_container = set_widget_find_result(".poll-option-bar");
|
||||
const $poll_question_submit = set_widget_find_result("button.poll-question-check");
|
||||
const $poll_edit_question = set_widget_find_result(".poll-edit-question");
|
||||
const $poll_question_header = set_widget_find_result(".poll-question-header");
|
||||
const $poll_question_container = set_widget_find_result(".poll-question-bar");
|
||||
const $poll_option_container = set_widget_find_result(".poll-option-bar");
|
||||
|
||||
const poll_vote_button = set_widget_find_result("button.poll-vote");
|
||||
const poll_please_wait = set_widget_find_result(".poll-please-wait");
|
||||
const poll_author_help = set_widget_find_result(".poll-author-help");
|
||||
const $poll_vote_button = set_widget_find_result("button.poll-vote");
|
||||
const $poll_please_wait = set_widget_find_result(".poll-please-wait");
|
||||
const $poll_author_help = set_widget_find_result(".poll-author-help");
|
||||
|
||||
set_widget_find_result("button.poll-question-remove");
|
||||
set_widget_find_result("input.poll-question");
|
||||
|
||||
poll_widget.activate(opts);
|
||||
|
||||
assert.ok(poll_option_container.visible());
|
||||
assert.ok(poll_question_header.visible());
|
||||
assert.ok($poll_option_container.visible());
|
||||
assert.ok($poll_question_header.visible());
|
||||
|
||||
assert.ok(!poll_question_container.visible());
|
||||
assert.ok(!poll_question_submit.visible());
|
||||
assert.ok(!poll_edit_question.visible());
|
||||
assert.ok(!poll_please_wait.visible());
|
||||
assert.ok(!poll_author_help.visible());
|
||||
assert.ok(!$poll_question_container.visible());
|
||||
assert.ok(!$poll_question_submit.visible());
|
||||
assert.ok(!$poll_edit_question.visible());
|
||||
assert.ok(!$poll_please_wait.visible());
|
||||
assert.ok(!$poll_author_help.visible());
|
||||
|
||||
assert.equal(widget_elem.html(), "widgets/poll_widget");
|
||||
assert.equal(widget_option_container.html(), "widgets/poll_widget_results");
|
||||
assert.equal(poll_question_header.text(), "What do you want?");
|
||||
assert.equal($widget_elem.html(), "widgets/poll_widget");
|
||||
assert.equal($widget_option_container.html(), "widgets/poll_widget_results");
|
||||
assert.equal($poll_question_header.text(), "What do you want?");
|
||||
|
||||
{
|
||||
/* Testing data sent to server on adding option */
|
||||
poll_option_input.val("cool choice");
|
||||
$poll_option_input.val("cool choice");
|
||||
out_data = undefined;
|
||||
poll_option.trigger("click");
|
||||
$poll_option.trigger("click");
|
||||
assert.deepEqual(out_data, {type: "new_option", idx: 1, option: "cool choice"});
|
||||
|
||||
poll_option_input.val("");
|
||||
$poll_option_input.val("");
|
||||
out_data = undefined;
|
||||
poll_option.trigger("click");
|
||||
$poll_option.trigger("click");
|
||||
assert.deepEqual(out_data, undefined);
|
||||
}
|
||||
|
||||
@@ -298,13 +298,13 @@ run_test("activate another person poll", ({mock_template}) => {
|
||||
},
|
||||
];
|
||||
|
||||
widget_elem.handle_events(vote_events);
|
||||
$widget_elem.handle_events(vote_events);
|
||||
|
||||
{
|
||||
/* Testing data sent to server on voting */
|
||||
poll_vote_button.attr("data-key", "100,1");
|
||||
$poll_vote_button.attr("data-key", "100,1");
|
||||
out_data = undefined;
|
||||
poll_vote_button.trigger("click");
|
||||
$poll_vote_button.trigger("click");
|
||||
assert.deepEqual(out_data, {type: "vote", key: "100,1", vote: 1});
|
||||
}
|
||||
|
||||
@@ -318,20 +318,20 @@ run_test("activate another person poll", ({mock_template}) => {
|
||||
},
|
||||
];
|
||||
|
||||
widget_elem.handle_events(add_question_event);
|
||||
$widget_elem.handle_events(add_question_event);
|
||||
});
|
||||
|
||||
run_test("activate own poll", ({mock_template}) => {
|
||||
mock_template("widgets/poll_widget.hbs", false, () => "widgets/poll_widget");
|
||||
mock_template("widgets/poll_widget_results.hbs", false, () => "widgets/poll_widget_results");
|
||||
|
||||
const widget_elem = $("<div>").addClass("widget-content");
|
||||
const $widget_elem = $("<div>").addClass("widget-content");
|
||||
let out_data;
|
||||
const callback = (data) => {
|
||||
out_data = data;
|
||||
};
|
||||
const opts = {
|
||||
elem: widget_elem,
|
||||
$elem: $widget_elem,
|
||||
callback,
|
||||
message: {
|
||||
sender_id: me.user_id,
|
||||
@@ -342,59 +342,59 @@ run_test("activate own poll", ({mock_template}) => {
|
||||
};
|
||||
|
||||
const set_widget_find_result = (selector) => {
|
||||
const elem = $.create(selector);
|
||||
widget_elem.set_find_results(selector, elem);
|
||||
return elem;
|
||||
const $elem = $.create(selector);
|
||||
$widget_elem.set_find_results(selector, $elem);
|
||||
return $elem;
|
||||
};
|
||||
|
||||
set_widget_find_result("button.poll-option");
|
||||
const poll_option_input = set_widget_find_result("input.poll-option");
|
||||
const widget_option_container = set_widget_find_result("ul.poll-widget");
|
||||
const $poll_option_input = set_widget_find_result("input.poll-option");
|
||||
const $widget_option_container = set_widget_find_result("ul.poll-widget");
|
||||
|
||||
const poll_question_submit = set_widget_find_result("button.poll-question-check");
|
||||
const poll_edit_question = set_widget_find_result(".poll-edit-question");
|
||||
const poll_question_input = set_widget_find_result("input.poll-question");
|
||||
const poll_question_header = set_widget_find_result(".poll-question-header");
|
||||
const poll_question_container = set_widget_find_result(".poll-question-bar");
|
||||
const poll_option_container = set_widget_find_result(".poll-option-bar");
|
||||
const $poll_question_submit = set_widget_find_result("button.poll-question-check");
|
||||
const $poll_edit_question = set_widget_find_result(".poll-edit-question");
|
||||
const $poll_question_input = set_widget_find_result("input.poll-question");
|
||||
const $poll_question_header = set_widget_find_result(".poll-question-header");
|
||||
const $poll_question_container = set_widget_find_result(".poll-question-bar");
|
||||
const $poll_option_container = set_widget_find_result(".poll-option-bar");
|
||||
|
||||
set_widget_find_result("button.poll-vote");
|
||||
const poll_please_wait = set_widget_find_result(".poll-please-wait");
|
||||
const poll_author_help = set_widget_find_result(".poll-author-help");
|
||||
const $poll_please_wait = set_widget_find_result(".poll-please-wait");
|
||||
const $poll_author_help = set_widget_find_result(".poll-author-help");
|
||||
|
||||
set_widget_find_result("button.poll-question-remove");
|
||||
|
||||
function assert_visibility() {
|
||||
assert.ok(poll_option_container.visible());
|
||||
assert.ok(poll_question_header.visible());
|
||||
assert.ok(!poll_question_container.visible());
|
||||
assert.ok(poll_edit_question.visible());
|
||||
assert.ok(!poll_please_wait.visible());
|
||||
assert.ok(!poll_author_help.visible());
|
||||
assert.ok($poll_option_container.visible());
|
||||
assert.ok($poll_question_header.visible());
|
||||
assert.ok(!$poll_question_container.visible());
|
||||
assert.ok($poll_edit_question.visible());
|
||||
assert.ok(!$poll_please_wait.visible());
|
||||
assert.ok(!$poll_author_help.visible());
|
||||
}
|
||||
|
||||
poll_widget.activate(opts);
|
||||
|
||||
assert_visibility();
|
||||
assert.ok(!poll_question_submit.visible());
|
||||
assert.ok(!$poll_question_submit.visible());
|
||||
|
||||
assert.equal(widget_elem.html(), "widgets/poll_widget");
|
||||
assert.equal(widget_option_container.html(), "widgets/poll_widget_results");
|
||||
assert.equal(poll_question_header.text(), "Where to go?");
|
||||
assert.equal($widget_elem.html(), "widgets/poll_widget");
|
||||
assert.equal($widget_option_container.html(), "widgets/poll_widget_results");
|
||||
assert.equal($poll_question_header.text(), "Where to go?");
|
||||
|
||||
{
|
||||
/* Testing data sent to server on editing question */
|
||||
poll_question_input.val("Is it new?");
|
||||
$poll_question_input.val("Is it new?");
|
||||
out_data = undefined;
|
||||
poll_question_submit.trigger("click");
|
||||
$poll_question_submit.trigger("click");
|
||||
assert.deepEqual(out_data, {type: "question", question: "Is it new?"});
|
||||
|
||||
assert_visibility();
|
||||
assert.ok(poll_question_submit.visible());
|
||||
assert.ok($poll_question_submit.visible());
|
||||
|
||||
poll_option_input.val("");
|
||||
$poll_option_input.val("");
|
||||
out_data = undefined;
|
||||
poll_question_submit.trigger("click");
|
||||
$poll_question_submit.trigger("click");
|
||||
assert.deepEqual(out_data, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -146,9 +146,9 @@ test_ui("sender_hover", ({override, mock_template}) => {
|
||||
assert.equal(msg_id, message.id);
|
||||
};
|
||||
|
||||
const target = $.create("click target");
|
||||
const $target = $.create("click target");
|
||||
|
||||
target.closest = (sel) => {
|
||||
$target.closest = (sel) => {
|
||||
assert.equal(sel, ".message_row");
|
||||
return {};
|
||||
};
|
||||
@@ -205,7 +205,7 @@ test_ui("sender_hover", ({override, mock_template}) => {
|
||||
|
||||
$.create(".user_popover_email", {children: []});
|
||||
const image_stubber = make_image_stubber();
|
||||
handler.call(target, e);
|
||||
handler.call($target, e);
|
||||
|
||||
const avatar_img = image_stubber.get(0);
|
||||
assert.equal(avatar_img.src.toString(), "/avatar/42/medium");
|
||||
@@ -216,7 +216,7 @@ test_ui("sender_hover", ({override, mock_template}) => {
|
||||
test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
|
||||
override($.fn, "popover", noop);
|
||||
|
||||
const target = $.create("click target");
|
||||
const $target = $.create("click target");
|
||||
|
||||
const handler = $("#main_div").get_on_handler("click", ".actions_hover");
|
||||
|
||||
@@ -241,7 +241,7 @@ test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
|
||||
|
||||
override_rewire(message_edit, "get_editability", () => 4);
|
||||
|
||||
target.closest = (sel) => {
|
||||
$target.closest = (sel) => {
|
||||
assert.equal(sel, ".message_row");
|
||||
return {
|
||||
toggleClass: noop,
|
||||
@@ -257,5 +257,5 @@ test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
|
||||
return "actions-content";
|
||||
});
|
||||
|
||||
handler.call(target, e);
|
||||
handler.call($target, e);
|
||||
});
|
||||
|
||||
@@ -361,46 +361,46 @@ test("sending", ({override, override_rewire}) => {
|
||||
});
|
||||
|
||||
test("set_reaction_count", () => {
|
||||
const count_element = $.create("count-stub");
|
||||
const reaction_element = $.create("reaction-stub");
|
||||
const $count_element = $.create("count-stub");
|
||||
const $reaction_element = $.create("reaction-stub");
|
||||
|
||||
reaction_element.set_find_results(".message_reaction_count", count_element);
|
||||
$reaction_element.set_find_results(".message_reaction_count", $count_element);
|
||||
|
||||
reactions.set_reaction_count(reaction_element, 5);
|
||||
reactions.set_reaction_count($reaction_element, 5);
|
||||
|
||||
assert.equal(count_element.text(), "5");
|
||||
assert.equal($count_element.text(), "5");
|
||||
});
|
||||
|
||||
test("find_reaction", ({override_rewire}) => {
|
||||
const message_id = 99;
|
||||
const local_id = "unicode_emoji,1f44b";
|
||||
const reaction_section = $.create("section-stub");
|
||||
const $reaction_section = $.create("section-stub");
|
||||
|
||||
const reaction_stub = "reaction-stub";
|
||||
reaction_section.set_find_results(
|
||||
$reaction_section.set_find_results(
|
||||
`[data-reaction-id='${CSS.escape(local_id)}']`,
|
||||
reaction_stub,
|
||||
);
|
||||
|
||||
override_rewire(reactions, "get_reaction_section", (arg) => {
|
||||
assert.equal(arg, message_id);
|
||||
return reaction_section;
|
||||
return $reaction_section;
|
||||
});
|
||||
|
||||
assert.equal(reactions.find_reaction(message_id, local_id), reaction_stub);
|
||||
});
|
||||
|
||||
test("get_reaction_section", () => {
|
||||
const message_table = $.create(".message_table");
|
||||
const message_row = $.create("some-message-row");
|
||||
const message_reactions = $.create("our-reactions-section");
|
||||
const $message_table = $.create(".message_table");
|
||||
const $message_row = $.create("some-message-row");
|
||||
const $message_reactions = $.create("our-reactions-section");
|
||||
|
||||
message_table.set_find_results(`[zid='${CSS.escape(555)}']`, message_row);
|
||||
message_row.set_find_results(".message_reactions", message_reactions);
|
||||
$message_table.set_find_results(`[zid='${CSS.escape(555)}']`, $message_row);
|
||||
$message_row.set_find_results(".message_reactions", $message_reactions);
|
||||
|
||||
const section = reactions.get_reaction_section(555);
|
||||
|
||||
assert.equal(section, message_reactions);
|
||||
assert.equal(section, $message_reactions);
|
||||
});
|
||||
|
||||
test("emoji_reaction_title", ({override}) => {
|
||||
@@ -599,14 +599,14 @@ test("view.insert_new_reaction (me w/unicode emoji)", ({override_rewire, mock_te
|
||||
user_id: alice.user_id,
|
||||
};
|
||||
|
||||
const message_reactions = $.create("our-reactions");
|
||||
const $message_reactions = $.create("our-reactions");
|
||||
|
||||
override_rewire(reactions, "get_reaction_section", (message_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
return message_reactions;
|
||||
return $message_reactions;
|
||||
});
|
||||
|
||||
message_reactions.find = (selector) => {
|
||||
$message_reactions.find = (selector) => {
|
||||
assert.equal(selector, ".reaction_button");
|
||||
return "reaction-button-stub";
|
||||
};
|
||||
@@ -646,14 +646,14 @@ test("view.insert_new_reaction (them w/zulip emoji)", ({override_rewire, mock_te
|
||||
user_id: bob.user_id,
|
||||
};
|
||||
|
||||
const message_reactions = $.create("our-reactions");
|
||||
const $message_reactions = $.create("our-reactions");
|
||||
|
||||
override_rewire(reactions, "get_reaction_section", (message_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
return message_reactions;
|
||||
return $message_reactions;
|
||||
});
|
||||
|
||||
message_reactions.find = (selector) => {
|
||||
$message_reactions.find = (selector) => {
|
||||
assert.equal(selector, ".reaction_button");
|
||||
return "reaction-button-stub";
|
||||
};
|
||||
@@ -696,24 +696,24 @@ test("view.update_existing_reaction (me)", ({override_rewire}) => {
|
||||
user_list: [alice.user_id, bob.user_id],
|
||||
};
|
||||
|
||||
const our_reaction = $.create("our-reaction-stub");
|
||||
const $our_reaction = $.create("our-reaction-stub");
|
||||
|
||||
override_rewire(reactions, "find_reaction", (message_id, local_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
assert.equal(local_id, "unicode_emoji,1f3b1");
|
||||
return our_reaction;
|
||||
return $our_reaction;
|
||||
});
|
||||
|
||||
override_rewire(reactions, "set_reaction_count", (reaction, count) => {
|
||||
assert.equal(reaction, our_reaction);
|
||||
assert.equal(reaction, $our_reaction);
|
||||
assert.equal(count, 2);
|
||||
});
|
||||
|
||||
reactions.view.update_existing_reaction(opts);
|
||||
|
||||
assert.ok(our_reaction.hasClass("reacted"));
|
||||
assert.ok($our_reaction.hasClass("reacted"));
|
||||
assert.equal(
|
||||
our_reaction.attr("aria-label"),
|
||||
$our_reaction.attr("aria-label"),
|
||||
"translated: You (click to remove) and Bob van Roberts reacted with :8ball:",
|
||||
);
|
||||
});
|
||||
@@ -728,24 +728,24 @@ test("view.update_existing_reaction (them)", ({override_rewire}) => {
|
||||
user_list: [alice.user_id, bob.user_id, cali.user_id, alexus.user_id],
|
||||
};
|
||||
|
||||
const our_reaction = $.create("our-reaction-stub");
|
||||
const $our_reaction = $.create("our-reaction-stub");
|
||||
|
||||
override_rewire(reactions, "find_reaction", (message_id, local_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
assert.equal(local_id, "unicode_emoji,1f3b1");
|
||||
return our_reaction;
|
||||
return $our_reaction;
|
||||
});
|
||||
|
||||
override_rewire(reactions, "set_reaction_count", (reaction, count) => {
|
||||
assert.equal(reaction, our_reaction);
|
||||
assert.equal(reaction, $our_reaction);
|
||||
assert.equal(count, 4);
|
||||
});
|
||||
|
||||
reactions.view.update_existing_reaction(opts);
|
||||
|
||||
assert.ok(!our_reaction.hasClass("reacted"));
|
||||
assert.ok(!$our_reaction.hasClass("reacted"));
|
||||
assert.equal(
|
||||
our_reaction.attr("aria-label"),
|
||||
$our_reaction.attr("aria-label"),
|
||||
"translated: You (click to remove), Bob van Roberts, Cali and Alexus reacted with :8ball:",
|
||||
);
|
||||
});
|
||||
@@ -760,25 +760,25 @@ test("view.remove_reaction (me)", ({override_rewire}) => {
|
||||
user_list: [bob.user_id, cali.user_id],
|
||||
};
|
||||
|
||||
const our_reaction = $.create("our-reaction-stub");
|
||||
our_reaction.addClass("reacted");
|
||||
const $our_reaction = $.create("our-reaction-stub");
|
||||
$our_reaction.addClass("reacted");
|
||||
|
||||
override_rewire(reactions, "find_reaction", (message_id, local_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
assert.equal(local_id, "unicode_emoji,1f3b1");
|
||||
return our_reaction;
|
||||
return $our_reaction;
|
||||
});
|
||||
|
||||
override_rewire(reactions, "set_reaction_count", (reaction, count) => {
|
||||
assert.equal(reaction, our_reaction);
|
||||
assert.equal(reaction, $our_reaction);
|
||||
assert.equal(count, 2);
|
||||
});
|
||||
|
||||
reactions.view.remove_reaction(opts);
|
||||
|
||||
assert.ok(!our_reaction.hasClass("reacted"));
|
||||
assert.ok(!$our_reaction.hasClass("reacted"));
|
||||
assert.equal(
|
||||
our_reaction.attr("aria-label"),
|
||||
$our_reaction.attr("aria-label"),
|
||||
"translated: Bob van Roberts and Cali reacted with :8ball:",
|
||||
);
|
||||
});
|
||||
@@ -793,26 +793,26 @@ test("view.remove_reaction (them)", ({override_rewire}) => {
|
||||
user_list: [alice.user_id],
|
||||
};
|
||||
|
||||
const our_reaction = $.create("our-reaction-stub");
|
||||
our_reaction.addClass("reacted");
|
||||
const $our_reaction = $.create("our-reaction-stub");
|
||||
$our_reaction.addClass("reacted");
|
||||
|
||||
override_rewire(reactions, "find_reaction", (message_id, local_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
assert.equal(local_id, "unicode_emoji,1f3b1");
|
||||
return our_reaction;
|
||||
return $our_reaction;
|
||||
});
|
||||
|
||||
override_rewire(reactions, "set_reaction_count", (reaction, count) => {
|
||||
assert.equal(reaction, our_reaction);
|
||||
assert.equal(reaction, $our_reaction);
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
|
||||
our_reaction.addClass("reacted");
|
||||
$our_reaction.addClass("reacted");
|
||||
reactions.view.remove_reaction(opts);
|
||||
|
||||
assert.ok(our_reaction.hasClass("reacted"));
|
||||
assert.ok($our_reaction.hasClass("reacted"));
|
||||
assert.equal(
|
||||
our_reaction.attr("aria-label"),
|
||||
$our_reaction.attr("aria-label"),
|
||||
"translated: You (click to remove) reacted with :8ball:",
|
||||
);
|
||||
});
|
||||
@@ -827,16 +827,16 @@ test("view.remove_reaction (last person)", ({override_rewire}) => {
|
||||
user_list: [],
|
||||
};
|
||||
|
||||
const our_reaction = $.create("our-reaction-stub");
|
||||
const $our_reaction = $.create("our-reaction-stub");
|
||||
|
||||
override_rewire(reactions, "find_reaction", (message_id, local_id) => {
|
||||
assert.equal(message_id, opts.message_id);
|
||||
assert.equal(local_id, "unicode_emoji,1f3b1");
|
||||
return our_reaction;
|
||||
return $our_reaction;
|
||||
});
|
||||
|
||||
let removed;
|
||||
our_reaction.remove = () => {
|
||||
$our_reaction.remove = () => {
|
||||
removed = true;
|
||||
};
|
||||
reactions.view.remove_reaction(opts);
|
||||
|
||||
@@ -323,9 +323,9 @@ function stub_out_filter_buttons() {
|
||||
// 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 $stub = $.create(`filter-${filter}-stub`);
|
||||
const selector = `[data-filter="${filter}"]`;
|
||||
$("#recent_topics_filter_buttons").set_find_results(selector, stub);
|
||||
$("#recent_topics_filter_buttons").set_find_results(selector, $stub);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,12 +104,12 @@ const get_content_element = () => {
|
||||
};
|
||||
|
||||
run_test("misc_helpers", () => {
|
||||
const elem = $.create("user-mention");
|
||||
rm.set_name_in_mention_element(elem, "Aaron");
|
||||
assert.equal(elem.text(), "@Aaron");
|
||||
elem.addClass("silent");
|
||||
rm.set_name_in_mention_element(elem, "Aaron, but silent");
|
||||
assert.equal(elem.text(), "Aaron, but silent");
|
||||
const $elem = $.create("user-mention");
|
||||
rm.set_name_in_mention_element($elem, "Aaron");
|
||||
assert.equal($elem.text(), "@Aaron");
|
||||
$elem.addClass("silent");
|
||||
rm.set_name_in_mention_element($elem, "Aaron, but silent");
|
||||
assert.equal($elem.text(), "Aaron, but silent");
|
||||
});
|
||||
|
||||
run_test("user-mention", () => {
|
||||
@@ -423,8 +423,8 @@ function test_code_playground(mock_template, viewing_code) {
|
||||
|
||||
return {
|
||||
prepends,
|
||||
copy_code: $copy_code_button,
|
||||
view_code: $view_code_in_playground,
|
||||
$copy_code: $copy_code_button,
|
||||
$view_code: $view_code_in_playground,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -434,12 +434,12 @@ run_test("code playground none", ({override, mock_template}) => {
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const {prepends, copy_code, view_code} = test_code_playground(mock_template, false);
|
||||
assert.deepEqual(prepends, [copy_code]);
|
||||
const {prepends, $copy_code, $view_code} = test_code_playground(mock_template, false);
|
||||
assert.deepEqual(prepends, [$copy_code]);
|
||||
assert_clipboard_setup();
|
||||
|
||||
assert.equal(view_code.attr("data-tippy-content"), undefined);
|
||||
assert.equal(view_code.attr("aria-label"), undefined);
|
||||
assert.equal($view_code.attr("data-tippy-content"), undefined);
|
||||
assert.equal($view_code.attr("aria-label"), undefined);
|
||||
});
|
||||
|
||||
run_test("code playground single", ({override, mock_template}) => {
|
||||
@@ -448,16 +448,16 @@ run_test("code playground single", ({override, mock_template}) => {
|
||||
return [{name: "Some Javascript Playground"}];
|
||||
});
|
||||
|
||||
const {prepends, copy_code, view_code} = test_code_playground(mock_template, true);
|
||||
assert.deepEqual(prepends, [view_code, copy_code]);
|
||||
const {prepends, $copy_code, $view_code} = test_code_playground(mock_template, true);
|
||||
assert.deepEqual(prepends, [$view_code, $copy_code]);
|
||||
assert_clipboard_setup();
|
||||
|
||||
assert.equal(
|
||||
view_code.attr("data-tippy-content"),
|
||||
$view_code.attr("data-tippy-content"),
|
||||
"translated: View in Some Javascript Playground",
|
||||
);
|
||||
assert.equal(view_code.attr("aria-label"), "translated: View in Some Javascript Playground");
|
||||
assert.equal(view_code.attr("aria-haspopup"), undefined);
|
||||
assert.equal($view_code.attr("aria-label"), "translated: View in Some Javascript Playground");
|
||||
assert.equal($view_code.attr("aria-haspopup"), undefined);
|
||||
});
|
||||
|
||||
run_test("code playground multiple", ({override, mock_template}) => {
|
||||
@@ -466,13 +466,13 @@ run_test("code playground multiple", ({override, mock_template}) => {
|
||||
return ["whatever", "whatever"];
|
||||
});
|
||||
|
||||
const {prepends, copy_code, view_code} = test_code_playground(mock_template, true);
|
||||
assert.deepEqual(prepends, [view_code, copy_code]);
|
||||
const {prepends, $copy_code, $view_code} = test_code_playground(mock_template, true);
|
||||
assert.deepEqual(prepends, [$view_code, $copy_code]);
|
||||
assert_clipboard_setup();
|
||||
|
||||
assert.equal(view_code.attr("data-tippy-content"), "translated: View in playground");
|
||||
assert.equal(view_code.attr("aria-label"), "translated: View in playground");
|
||||
assert.equal(view_code.attr("aria-haspopup"), "true");
|
||||
assert.equal($view_code.attr("data-tippy-content"), "translated: View in playground");
|
||||
assert.equal($view_code.attr("aria-label"), "translated: View in playground");
|
||||
assert.equal($view_code.attr("aria-haspopup"), "true");
|
||||
});
|
||||
|
||||
run_test("rtl", () => {
|
||||
|
||||
@@ -129,20 +129,20 @@ run_test("get_direction", () => {
|
||||
});
|
||||
|
||||
run_test("set_rtl_class_for_textarea rtl", () => {
|
||||
const textarea = $.create("some-textarea");
|
||||
assert.ok(!textarea.hasClass("rtl"));
|
||||
const $textarea = $.create("some-textarea");
|
||||
assert.ok(!$textarea.hasClass("rtl"));
|
||||
const text = "```quote\nمرحبا";
|
||||
textarea.val(text);
|
||||
rtl.set_rtl_class_for_textarea(textarea);
|
||||
assert.ok(textarea.hasClass("rtl"));
|
||||
$textarea.val(text);
|
||||
rtl.set_rtl_class_for_textarea($textarea);
|
||||
assert.ok($textarea.hasClass("rtl"));
|
||||
});
|
||||
|
||||
run_test("set_rtl_class_for_textarea ltr", () => {
|
||||
const textarea = $.create("some-textarea");
|
||||
textarea.addClass("rtl");
|
||||
assert.ok(textarea.hasClass("rtl"));
|
||||
const $textarea = $.create("some-textarea");
|
||||
$textarea.addClass("rtl");
|
||||
assert.ok($textarea.hasClass("rtl"));
|
||||
const text = "```quote\nEnglish text";
|
||||
textarea.val(text);
|
||||
rtl.set_rtl_class_for_textarea(textarea);
|
||||
assert.ok(!textarea.hasClass("rtl"));
|
||||
$textarea.val(text);
|
||||
rtl.set_rtl_class_for_textarea($textarea);
|
||||
assert.ok(!$textarea.hasClass("rtl"));
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ run_test("scroll_delta", () => {
|
||||
});
|
||||
|
||||
run_test("scroll_element_into_container", () => {
|
||||
const container = (function () {
|
||||
const $container = (function () {
|
||||
let top = 3;
|
||||
return {
|
||||
height: () => 100,
|
||||
@@ -103,21 +103,21 @@ run_test("scroll_element_into_container", () => {
|
||||
};
|
||||
})();
|
||||
|
||||
const elem1 = {
|
||||
const $elem1 = {
|
||||
innerHeight: () => 25,
|
||||
position: () => ({
|
||||
top: 0,
|
||||
}),
|
||||
};
|
||||
scroll_util.scroll_element_into_container(elem1, container);
|
||||
assert.equal(container.scrollTop(), 3);
|
||||
scroll_util.scroll_element_into_container($elem1, $container);
|
||||
assert.equal($container.scrollTop(), 3);
|
||||
|
||||
const elem2 = {
|
||||
const $elem2 = {
|
||||
innerHeight: () => 15,
|
||||
position: () => ({
|
||||
top: 250,
|
||||
}),
|
||||
};
|
||||
scroll_util.scroll_element_into_container(elem2, container);
|
||||
assert.equal(container.scrollTop(), 250 - 100 + 3 + 15);
|
||||
scroll_util.scroll_element_into_container($elem2, $container);
|
||||
assert.equal($container.scrollTop(), 250 - 100 + 3 + 15);
|
||||
});
|
||||
|
||||
@@ -51,50 +51,50 @@ test("clear_search_form", () => {
|
||||
});
|
||||
|
||||
test("update_button_visibility", () => {
|
||||
const search_query = $("#search_query");
|
||||
const search_button = $(".search_button");
|
||||
const $search_query = $("#search_query");
|
||||
const $search_button = $(".search_button");
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(search_button.prop("disabled"));
|
||||
assert.ok($search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => true;
|
||||
search_query.val("");
|
||||
$search_query.is = () => true;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("Test search term");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("Test search term");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => true;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
});
|
||||
|
||||
test("initialize", () => {
|
||||
const search_query_box = $("#search_query");
|
||||
const searchbox_form = $("#searchbox_form");
|
||||
const search_button = $(".search_button");
|
||||
const searchbox = $("#searchbox");
|
||||
const $search_query_box = $("#search_query");
|
||||
const $searchbox_form = $("#searchbox_form");
|
||||
const $search_button = $(".search_button");
|
||||
const $searchbox = $("#searchbox");
|
||||
|
||||
search_query_box[0] = "stub";
|
||||
$search_query_box[0] = "stub";
|
||||
|
||||
search_pill.get_search_string_for_current_filter = () => "is:starred";
|
||||
|
||||
search_suggestion.max_num_of_search_results = 99;
|
||||
search_query_box.typeahead = (opts) => {
|
||||
$search_query_box.typeahead = (opts) => {
|
||||
assert.equal(opts.fixed, true);
|
||||
assert.equal(opts.items, 99);
|
||||
assert.equal(opts.naturalSearch, true);
|
||||
@@ -144,7 +144,7 @@ test("initialize", () => {
|
||||
let operators;
|
||||
let is_blurred;
|
||||
let is_append_search_string_called;
|
||||
search_query_box.on("blur", () => {
|
||||
$search_query_box.on("blur", () => {
|
||||
is_blurred = true;
|
||||
});
|
||||
search_pill.append_search_string = () => {
|
||||
@@ -154,7 +154,7 @@ test("initialize", () => {
|
||||
const _setup = (search_box_val) => {
|
||||
is_blurred = false;
|
||||
is_append_search_string_called = false;
|
||||
search_query_box.val(search_box_val);
|
||||
$search_query_box.val(search_box_val);
|
||||
Filter.parse = (search_string) => {
|
||||
assert.equal(search_string, search_box_val);
|
||||
return operators;
|
||||
@@ -199,34 +199,35 @@ test("initialize", () => {
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(is_append_search_string_called);
|
||||
|
||||
search_query_box.off("blur");
|
||||
$search_query_box.off("blur");
|
||||
}
|
||||
};
|
||||
|
||||
search.initialize();
|
||||
|
||||
const search_pill_stub = $.create(".pill");
|
||||
search_pill_stub.closest = () => ({data: noop});
|
||||
const $search_pill_stub = $.create(".pill");
|
||||
$search_pill_stub.closest = () => ({data: noop});
|
||||
const stub_event = {
|
||||
relatedTarget: search_pill_stub,
|
||||
// FIXME: event.relatedTarget should not be a jQuery object
|
||||
relatedTarget: $search_pill_stub,
|
||||
};
|
||||
search_query_box.val("test string");
|
||||
$search_query_box.val("test string");
|
||||
narrow_state.search_string = () => "ver";
|
||||
search_query_box.trigger(new $.Event("blur", stub_event));
|
||||
assert.equal(search_query_box.val(), "test string");
|
||||
$search_query_box.trigger(new $.Event("blur", stub_event));
|
||||
assert.equal($search_query_box.val(), "test string");
|
||||
|
||||
let css_args;
|
||||
searchbox.css = (args) => {
|
||||
$searchbox.css = (args) => {
|
||||
css_args = args;
|
||||
};
|
||||
searchbox.trigger("focusout");
|
||||
$searchbox.trigger("focusout");
|
||||
assert.deepEqual(css_args, {"box-shadow": "unset"});
|
||||
|
||||
search.__Rewire__("is_using_input_method", false);
|
||||
searchbox_form.trigger("compositionend");
|
||||
$searchbox_form.trigger("compositionend");
|
||||
assert.ok(search.is_using_input_method);
|
||||
|
||||
const keydown = searchbox_form.get_on_handler("keydown");
|
||||
const keydown = $searchbox_form.get_on_handler("keydown");
|
||||
let default_prevented = false;
|
||||
let ev = {
|
||||
type: "keydown",
|
||||
@@ -235,7 +236,7 @@ test("initialize", () => {
|
||||
default_prevented = true;
|
||||
},
|
||||
};
|
||||
search_query_box.is = () => false;
|
||||
$search_query_box.is = () => false;
|
||||
assert.equal(keydown(ev), undefined);
|
||||
assert.ok(!default_prevented);
|
||||
|
||||
@@ -244,22 +245,22 @@ test("initialize", () => {
|
||||
assert.ok(!default_prevented);
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
$search_query_box.is = () => true;
|
||||
assert.equal(keydown(ev), undefined);
|
||||
assert.ok(default_prevented);
|
||||
|
||||
let operators;
|
||||
let is_blurred;
|
||||
narrow_state.active = () => false;
|
||||
search_query_box.off("blur");
|
||||
search_query_box.on("blur", () => {
|
||||
$search_query_box.off("blur");
|
||||
$search_query_box.on("blur", () => {
|
||||
is_blurred = true;
|
||||
});
|
||||
|
||||
const _setup = (search_box_val) => {
|
||||
is_blurred = false;
|
||||
search_button.prop("disabled", false);
|
||||
search_query_box.val(search_box_val);
|
||||
$search_button.prop("disabled", false);
|
||||
$search_query_box.val(search_box_val);
|
||||
Filter.parse = (search_string) => {
|
||||
assert.equal(search_string, search_box_val);
|
||||
return operators;
|
||||
@@ -284,41 +285,41 @@ test("initialize", () => {
|
||||
type: "keyup",
|
||||
which: 15,
|
||||
};
|
||||
search_query_box.is = () => false;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => false;
|
||||
$searchbox_form.trigger(ev);
|
||||
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => false;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => false;
|
||||
$searchbox_form.trigger(ev);
|
||||
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => true;
|
||||
$searchbox_form.trigger(ev);
|
||||
assert.ok(is_blurred);
|
||||
|
||||
_setup("ver");
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
searchbox_form.trigger(ev);
|
||||
$searchbox_form.trigger(ev);
|
||||
// No change on Enter keyup event when using input tool
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
_setup("ver");
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => true;
|
||||
$searchbox_form.trigger(ev);
|
||||
assert.ok(is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_button.prop("disabled", true);
|
||||
search_query_box.trigger("focus");
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
$search_button.prop("disabled", true);
|
||||
$search_query_box.trigger("focus");
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
});
|
||||
|
||||
test("initiate_search", () => {
|
||||
@@ -345,9 +346,9 @@ test("initiate_search", () => {
|
||||
|
||||
$("#search_query")[0] = "stub";
|
||||
|
||||
const searchbox = $("#searchbox");
|
||||
const $searchbox = $("#searchbox");
|
||||
let css_args;
|
||||
searchbox.css = (args) => {
|
||||
$searchbox.css = (args) => {
|
||||
css_args = args;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,45 +29,45 @@ set_global("setTimeout", (func) => func());
|
||||
const search = zrequire("search");
|
||||
|
||||
run_test("update_button_visibility", () => {
|
||||
const search_query = $("#search_query");
|
||||
const search_button = $(".search_button");
|
||||
const $search_query = $("#search_query");
|
||||
const $search_button = $(".search_button");
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(search_button.prop("disabled"));
|
||||
assert.ok($search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => true;
|
||||
search_query.val("");
|
||||
$search_query.is = () => true;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("Test search term");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("Test search term");
|
||||
narrow_state.active = () => false;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_query.is = () => false;
|
||||
search_query.val("");
|
||||
$search_query.is = () => false;
|
||||
$search_query.val("");
|
||||
narrow_state.active = () => true;
|
||||
search_button.prop("disabled", true);
|
||||
$search_button.prop("disabled", true);
|
||||
search.update_button_visibility();
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
});
|
||||
|
||||
run_test("initialize", () => {
|
||||
const search_query_box = $("#search_query");
|
||||
const searchbox_form = $("#searchbox_form");
|
||||
const search_button = $(".search_button");
|
||||
const $search_query_box = $("#search_query");
|
||||
const $searchbox_form = $("#searchbox_form");
|
||||
const $search_button = $(".search_button");
|
||||
|
||||
search_suggestion.max_num_of_search_results = 999;
|
||||
search_query_box.typeahead = (opts) => {
|
||||
$search_query_box.typeahead = (opts) => {
|
||||
assert.equal(opts.fixed, true);
|
||||
assert.equal(opts.items, 999);
|
||||
assert.equal(opts.naturalSearch, true);
|
||||
@@ -115,13 +115,13 @@ run_test("initialize", () => {
|
||||
{
|
||||
let operators;
|
||||
let is_blurred;
|
||||
search_query_box.on("blur", () => {
|
||||
$search_query_box.on("blur", () => {
|
||||
is_blurred = true;
|
||||
});
|
||||
/* Test updater */
|
||||
const _setup = (search_box_val) => {
|
||||
is_blurred = false;
|
||||
search_query_box.val(search_box_val);
|
||||
$search_query_box.val(search_box_val);
|
||||
Filter.parse = (search_string) => {
|
||||
assert.equal(search_string, search_box_val);
|
||||
return operators;
|
||||
@@ -159,26 +159,26 @@ run_test("initialize", () => {
|
||||
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
||||
assert.ok(!is_blurred);
|
||||
|
||||
search_query_box.off("blur");
|
||||
$search_query_box.off("blur");
|
||||
}
|
||||
};
|
||||
|
||||
search.initialize();
|
||||
|
||||
search_button.prop("disabled", true);
|
||||
search_query_box.trigger("focus");
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
$search_button.prop("disabled", true);
|
||||
$search_query_box.trigger("focus");
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
search_query_box.val("test string");
|
||||
$search_query_box.val("test string");
|
||||
narrow_state.search_string = () => "ver";
|
||||
search_query_box.trigger("blur");
|
||||
assert.equal(search_query_box.val(), "test string");
|
||||
$search_query_box.trigger("blur");
|
||||
assert.equal($search_query_box.val(), "test string");
|
||||
|
||||
search.__Rewire__("is_using_input_method", false);
|
||||
searchbox_form.trigger("compositionend");
|
||||
$searchbox_form.trigger("compositionend");
|
||||
assert.ok(search.is_using_input_method);
|
||||
|
||||
const keydown = searchbox_form.get_on_handler("keydown");
|
||||
const keydown = $searchbox_form.get_on_handler("keydown");
|
||||
let default_prevented = false;
|
||||
let ev = {
|
||||
type: "keydown",
|
||||
@@ -187,7 +187,7 @@ run_test("initialize", () => {
|
||||
default_prevented = true;
|
||||
},
|
||||
};
|
||||
search_query_box.is = () => false;
|
||||
$search_query_box.is = () => false;
|
||||
assert.equal(keydown(ev), undefined);
|
||||
assert.ok(!default_prevented);
|
||||
|
||||
@@ -196,7 +196,7 @@ run_test("initialize", () => {
|
||||
assert.ok(!default_prevented);
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
$search_query_box.is = () => true;
|
||||
assert.equal(keydown(ev), undefined);
|
||||
assert.ok(default_prevented);
|
||||
|
||||
@@ -206,15 +206,15 @@ run_test("initialize", () => {
|
||||
let operators;
|
||||
let is_blurred;
|
||||
narrow_state.active = () => false;
|
||||
search_query_box.off("blur");
|
||||
search_query_box.on("blur", () => {
|
||||
$search_query_box.off("blur");
|
||||
$search_query_box.on("blur", () => {
|
||||
is_blurred = true;
|
||||
});
|
||||
|
||||
const _setup = (search_box_val) => {
|
||||
is_blurred = false;
|
||||
search_button.prop("disabled", false);
|
||||
search_query_box.val(search_box_val);
|
||||
$search_button.prop("disabled", false);
|
||||
$search_query_box.val(search_box_val);
|
||||
Filter.parse = (search_string) => {
|
||||
assert.equal(search_string, search_box_val);
|
||||
return operators;
|
||||
@@ -235,37 +235,37 @@ run_test("initialize", () => {
|
||||
_setup("");
|
||||
|
||||
ev.key = "a";
|
||||
search_query_box.is = () => false;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => false;
|
||||
$searchbox_form.trigger(ev);
|
||||
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => false;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => false;
|
||||
$searchbox_form.trigger(ev);
|
||||
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => true;
|
||||
$searchbox_form.trigger(ev);
|
||||
assert.ok(is_blurred);
|
||||
|
||||
_setup("ver");
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
searchbox_form.trigger(ev);
|
||||
$searchbox_form.trigger(ev);
|
||||
// No change on Enter keyup event when using input tool
|
||||
assert.ok(!is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
|
||||
_setup("ver");
|
||||
ev.key = "Enter";
|
||||
search_query_box.is = () => true;
|
||||
searchbox_form.trigger(ev);
|
||||
$search_query_box.is = () => true;
|
||||
$searchbox_form.trigger(ev);
|
||||
assert.ok(is_blurred);
|
||||
assert.ok(!search_button.prop("disabled"));
|
||||
assert.ok(!$search_button.prop("disabled"));
|
||||
});
|
||||
|
||||
run_test("initiate_search", () => {
|
||||
|
||||
@@ -91,32 +91,32 @@ test("generate_botserverrc_content", () => {
|
||||
});
|
||||
|
||||
function test_create_bot_type_input_box_toggle(f) {
|
||||
const create_payload_url = $("#create_payload_url");
|
||||
const payload_url_inputbox = $("#payload_url_inputbox");
|
||||
const config_inputbox = $("#config_inputbox");
|
||||
const $create_payload_url = $("#create_payload_url");
|
||||
const $payload_url_inputbox = $("#payload_url_inputbox");
|
||||
const $config_inputbox = $("#config_inputbox");
|
||||
const EMBEDDED_BOT_TYPE = "4";
|
||||
const OUTGOING_WEBHOOK_BOT_TYPE = "3";
|
||||
const GENERIC_BOT_TYPE = "1";
|
||||
|
||||
$("#create_bot_type :selected").val(EMBEDDED_BOT_TYPE);
|
||||
f();
|
||||
assert.ok(!create_payload_url.hasClass("required"));
|
||||
assert.ok(!payload_url_inputbox.visible());
|
||||
assert.ok(!$create_payload_url.hasClass("required"));
|
||||
assert.ok(!$payload_url_inputbox.visible());
|
||||
assert.ok($("#select_service_name").hasClass("required"));
|
||||
assert.ok($("#service_name_list").visible());
|
||||
assert.ok(config_inputbox.visible());
|
||||
assert.ok($config_inputbox.visible());
|
||||
|
||||
$("#create_bot_type :selected").val(OUTGOING_WEBHOOK_BOT_TYPE);
|
||||
f();
|
||||
assert.ok(create_payload_url.hasClass("required"));
|
||||
assert.ok(payload_url_inputbox.visible());
|
||||
assert.ok(!config_inputbox.visible());
|
||||
assert.ok($create_payload_url.hasClass("required"));
|
||||
assert.ok($payload_url_inputbox.visible());
|
||||
assert.ok(!$config_inputbox.visible());
|
||||
|
||||
$("#create_bot_type :selected").val(GENERIC_BOT_TYPE);
|
||||
f();
|
||||
assert.ok(!create_payload_url.hasClass("required"));
|
||||
assert.ok(!payload_url_inputbox.visible());
|
||||
assert.ok(!config_inputbox.visible());
|
||||
assert.ok(!$create_payload_url.hasClass("required"));
|
||||
assert.ok(!$payload_url_inputbox.visible());
|
||||
assert.ok(!$config_inputbox.visible());
|
||||
}
|
||||
|
||||
test("test tab clicks", ({override}) => {
|
||||
@@ -125,10 +125,10 @@ test("test tab clicks", ({override}) => {
|
||||
$("#create_bot_form").validate = () => {};
|
||||
|
||||
$("#config_inputbox").children = () => {
|
||||
const mock_children = {
|
||||
const $mock_children = {
|
||||
hide: () => {},
|
||||
};
|
||||
return mock_children;
|
||||
return $mock_children;
|
||||
};
|
||||
|
||||
override(avatar, "build_bot_create_widget", () => {});
|
||||
@@ -137,55 +137,55 @@ test("test tab clicks", ({override}) => {
|
||||
|
||||
test_create_bot_type_input_box_toggle(() => $("#create_bot_type").trigger("change"));
|
||||
|
||||
function click_on_tab(tab_elem) {
|
||||
tab_elem.trigger("click");
|
||||
function click_on_tab($tab_elem) {
|
||||
$tab_elem.trigger("click");
|
||||
}
|
||||
|
||||
const tabs = {
|
||||
add: $("#bots_lists_navbar .add-a-new-bot-tab"),
|
||||
active: $("#bots_lists_navbar .active-bots-tab"),
|
||||
inactive: $("#bots_lists_navbar .inactive-bots-tab"),
|
||||
$add: $("#bots_lists_navbar .add-a-new-bot-tab"),
|
||||
$active: $("#bots_lists_navbar .active-bots-tab"),
|
||||
$inactive: $("#bots_lists_navbar .inactive-bots-tab"),
|
||||
};
|
||||
|
||||
$("#bots_lists_navbar .active").removeClass = (cls) => {
|
||||
assert.equal(cls, "active");
|
||||
for (const tab of Object.values(tabs)) {
|
||||
tab.removeClass("active");
|
||||
for (const $tab of Object.values(tabs)) {
|
||||
$tab.removeClass("active");
|
||||
}
|
||||
};
|
||||
|
||||
const forms = {
|
||||
add: $("#add-a-new-bot-form"),
|
||||
active: $("#active_bots_list"),
|
||||
inactive: $("#inactive_bots_list"),
|
||||
$add: $("#add-a-new-bot-form"),
|
||||
$active: $("#active_bots_list"),
|
||||
$inactive: $("#inactive_bots_list"),
|
||||
};
|
||||
|
||||
click_on_tab(tabs.add);
|
||||
assert.ok(tabs.add.hasClass("active"));
|
||||
assert.ok(!tabs.active.hasClass("active"));
|
||||
assert.ok(!tabs.inactive.hasClass("active"));
|
||||
click_on_tab(tabs.$add);
|
||||
assert.ok(tabs.$add.hasClass("active"));
|
||||
assert.ok(!tabs.$active.hasClass("active"));
|
||||
assert.ok(!tabs.$inactive.hasClass("active"));
|
||||
|
||||
assert.ok(forms.add.visible());
|
||||
assert.ok(!forms.active.visible());
|
||||
assert.ok(!forms.inactive.visible());
|
||||
assert.ok(forms.$add.visible());
|
||||
assert.ok(!forms.$active.visible());
|
||||
assert.ok(!forms.$inactive.visible());
|
||||
|
||||
click_on_tab(tabs.active);
|
||||
assert.ok(!tabs.add.hasClass("active"));
|
||||
assert.ok(tabs.active.hasClass("active"));
|
||||
assert.ok(!tabs.inactive.hasClass("active"));
|
||||
click_on_tab(tabs.$active);
|
||||
assert.ok(!tabs.$add.hasClass("active"));
|
||||
assert.ok(tabs.$active.hasClass("active"));
|
||||
assert.ok(!tabs.$inactive.hasClass("active"));
|
||||
|
||||
assert.ok(!forms.add.visible());
|
||||
assert.ok(forms.active.visible());
|
||||
assert.ok(!forms.inactive.visible());
|
||||
assert.ok(!forms.$add.visible());
|
||||
assert.ok(forms.$active.visible());
|
||||
assert.ok(!forms.$inactive.visible());
|
||||
|
||||
click_on_tab(tabs.inactive);
|
||||
assert.ok(!tabs.add.hasClass("active"));
|
||||
assert.ok(!tabs.active.hasClass("active"));
|
||||
assert.ok(tabs.inactive.hasClass("active"));
|
||||
click_on_tab(tabs.$inactive);
|
||||
assert.ok(!tabs.$add.hasClass("active"));
|
||||
assert.ok(!tabs.$active.hasClass("active"));
|
||||
assert.ok(tabs.$inactive.hasClass("active"));
|
||||
|
||||
assert.ok(!forms.add.visible());
|
||||
assert.ok(!forms.active.visible());
|
||||
assert.ok(forms.inactive.visible());
|
||||
assert.ok(!forms.$add.visible());
|
||||
assert.ok(!forms.$active.visible());
|
||||
assert.ok(forms.$inactive.visible());
|
||||
});
|
||||
|
||||
test("can_create_new_bots", () => {
|
||||
|
||||
@@ -51,15 +51,15 @@ run_test("settings", ({override_rewire}) => {
|
||||
stopPropagation: noop,
|
||||
};
|
||||
|
||||
const topic_fake_this = $.create("fake.settings-unmute-topic");
|
||||
const topic_tr_html = $('tr[data-topic="js"]');
|
||||
topic_fake_this.closest = (opts) => {
|
||||
const $topic_fake_this = $.create("fake.settings-unmute-topic");
|
||||
const $topic_tr_html = $('tr[data-topic="js"]');
|
||||
$topic_fake_this.closest = (opts) => {
|
||||
assert.equal(opts, "tr");
|
||||
return topic_tr_html;
|
||||
return $topic_tr_html;
|
||||
};
|
||||
|
||||
let topic_data_called = 0;
|
||||
topic_tr_html.attr = (opts) => {
|
||||
$topic_tr_html.attr = (opts) => {
|
||||
if (opts === "data-stream-id") {
|
||||
topic_data_called += 1;
|
||||
return frontend.stream_id;
|
||||
@@ -77,7 +77,7 @@ run_test("settings", ({override_rewire}) => {
|
||||
assert.equal(topic, "js");
|
||||
unmute_topic_called = true;
|
||||
};
|
||||
topic_click_handler.call(topic_fake_this, event);
|
||||
topic_click_handler.call($topic_fake_this, event);
|
||||
assert.ok(unmute_topic_called);
|
||||
assert.equal(topic_data_called, 2);
|
||||
});
|
||||
|
||||
@@ -42,15 +42,15 @@ run_test("settings", ({override_rewire}) => {
|
||||
stopPropagation: noop,
|
||||
};
|
||||
|
||||
const unmute_button = $.create("settings-unmute-user");
|
||||
const fake_row = $('tr[data-user-id="5"]');
|
||||
unmute_button.closest = (opts) => {
|
||||
const $unmute_button = $.create("settings-unmute-user");
|
||||
const $fake_row = $('tr[data-user-id="5"]');
|
||||
$unmute_button.closest = (opts) => {
|
||||
assert.equal(opts, "tr");
|
||||
return fake_row;
|
||||
return $fake_row;
|
||||
};
|
||||
|
||||
let row_attribute_fetched = false;
|
||||
fake_row.attr = (opts) => {
|
||||
$fake_row.attr = (opts) => {
|
||||
if (opts === "data-user-id") {
|
||||
row_attribute_fetched += 1;
|
||||
return "5";
|
||||
@@ -64,7 +64,7 @@ run_test("settings", ({override_rewire}) => {
|
||||
unmute_user_called = true;
|
||||
};
|
||||
|
||||
unmute_click_handler.call(unmute_button, event);
|
||||
unmute_click_handler.call($unmute_button, event);
|
||||
assert.ok(unmute_user_called);
|
||||
assert.ok(row_attribute_fetched);
|
||||
});
|
||||
|
||||
@@ -31,12 +31,12 @@ mock_esm("../../static/js/loading", {
|
||||
destroy_indicator: noop,
|
||||
});
|
||||
mock_esm("../../static/js/ui_report", {
|
||||
success(msg, elem) {
|
||||
elem.val(msg);
|
||||
success(msg, $elem) {
|
||||
$elem.val(msg);
|
||||
},
|
||||
|
||||
error(msg, xhr, elem) {
|
||||
elem.val(msg);
|
||||
error(msg, xhr, $elem) {
|
||||
$elem.val(msg);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -74,9 +74,9 @@ test("unloaded", () => {
|
||||
});
|
||||
|
||||
function simulate_realm_domains_table() {
|
||||
const tr_stub = $.create("realm-tr-stub");
|
||||
$("#realm_domains_table tbody").set_find_results("tr", tr_stub);
|
||||
tr_stub.remove = () => {};
|
||||
const $tr_stub = $.create("realm-tr-stub");
|
||||
$("#realm_domains_table tbody").set_find_results("tr", $tr_stub);
|
||||
$tr_stub.remove = () => {};
|
||||
|
||||
let appended;
|
||||
$("#realm_domains_table tbody").append = (html) => {
|
||||
@@ -90,7 +90,7 @@ function simulate_realm_domains_table() {
|
||||
}
|
||||
|
||||
function test_realms_domain_modal(override, add_realm_domain) {
|
||||
const info = $(".realm_domains_info");
|
||||
const $info = $(".realm_domains_info");
|
||||
|
||||
$("#add-realm-domain-widget").set_find_results(
|
||||
".new-realm-domain",
|
||||
@@ -117,46 +117,46 @@ function test_realms_domain_modal(override, add_realm_domain) {
|
||||
assert.ok(posted);
|
||||
|
||||
success_callback();
|
||||
assert.equal(info.val(), "translated HTML: Added successfully!");
|
||||
assert.equal($info.val(), "translated HTML: Added successfully!");
|
||||
|
||||
error_callback({});
|
||||
assert.equal(info.val(), "translated HTML: Failed");
|
||||
assert.equal($info.val(), "translated HTML: Failed");
|
||||
}
|
||||
|
||||
function createSaveButtons(subsection) {
|
||||
const stub_save_button_header = $(`#org-${CSS.escape(subsection)}`);
|
||||
const save_button_controls = $(".save-button-controls");
|
||||
const stub_save_button = $(`#org-submit-${CSS.escape(subsection)}`);
|
||||
const stub_discard_button = $(`#org-discard-${CSS.escape(subsection)}`);
|
||||
const stub_save_button_text = $(".save-discard-widget-button-text");
|
||||
stub_save_button_header.set_find_results(
|
||||
const $stub_save_button_header = $(`#org-${CSS.escape(subsection)}`);
|
||||
const $save_button_controls = $(".save-button-controls");
|
||||
const $stub_save_button = $(`#org-submit-${CSS.escape(subsection)}`);
|
||||
const $stub_discard_button = $(`#org-discard-${CSS.escape(subsection)}`);
|
||||
const $stub_save_button_text = $(".save-discard-widget-button-text");
|
||||
$stub_save_button_header.set_find_results(
|
||||
".subsection-failed-status p",
|
||||
$("<failed status element>"),
|
||||
);
|
||||
stub_save_button.closest = () => stub_save_button_header;
|
||||
save_button_controls.set_find_results(".save-button", stub_save_button);
|
||||
stub_save_button.set_find_results(".save-discard-widget-button-text", stub_save_button_text);
|
||||
stub_save_button_header.set_find_results(".save-button-controls", save_button_controls);
|
||||
stub_save_button_header.set_find_results(
|
||||
$stub_save_button.closest = () => $stub_save_button_header;
|
||||
$save_button_controls.set_find_results(".save-button", $stub_save_button);
|
||||
$stub_save_button.set_find_results(".save-discard-widget-button-text", $stub_save_button_text);
|
||||
$stub_save_button_header.set_find_results(".save-button-controls", $save_button_controls);
|
||||
$stub_save_button_header.set_find_results(
|
||||
".subsection-changes-discard button",
|
||||
$(`#org-discard-${CSS.escape(subsection)}`),
|
||||
);
|
||||
save_button_controls.set_find_results(".discard-button", stub_discard_button);
|
||||
$save_button_controls.set_find_results(".discard-button", $stub_discard_button);
|
||||
const props = {};
|
||||
props.hidden = false;
|
||||
save_button_controls.fadeIn = () => {
|
||||
$save_button_controls.fadeIn = () => {
|
||||
props.hidden = false;
|
||||
};
|
||||
save_button_controls.fadeOut = () => {
|
||||
$save_button_controls.fadeOut = () => {
|
||||
props.hidden = true;
|
||||
};
|
||||
return {
|
||||
props,
|
||||
save_button: stub_save_button,
|
||||
discard_button: stub_discard_button,
|
||||
save_button_header: stub_save_button_header,
|
||||
save_button_controls,
|
||||
save_button_text: stub_save_button_text,
|
||||
$save_button: $stub_save_button,
|
||||
$discard_button: $stub_discard_button,
|
||||
$save_button_header: $stub_save_button_header,
|
||||
$save_button_controls,
|
||||
$save_button_text: $stub_save_button_text,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -193,55 +193,55 @@ function test_submit_settings_form(override, submit_form) {
|
||||
let subsection = "other-permissions";
|
||||
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
|
||||
let stubs = createSaveButtons(subsection);
|
||||
let save_button = stubs.save_button;
|
||||
save_button.attr("id", `org-submit-${subsection}`);
|
||||
save_button.replace = () => `${subsection}`;
|
||||
let $save_button = stubs.$save_button;
|
||||
$save_button.attr("id", `org-submit-${subsection}`);
|
||||
$save_button.replace = () => `${subsection}`;
|
||||
|
||||
$("#id_realm_waiting_period_threshold").val(10);
|
||||
|
||||
const invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
|
||||
invite_to_stream_policy_elem.val("1");
|
||||
invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy");
|
||||
invite_to_stream_policy_elem.data = () => "number";
|
||||
const $invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
|
||||
$invite_to_stream_policy_elem.val("1");
|
||||
$invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy");
|
||||
$invite_to_stream_policy_elem.data = () => "number";
|
||||
|
||||
const create_public_stream_policy_elem = $("#id_realm_create_public_stream_policy");
|
||||
create_public_stream_policy_elem.val("2");
|
||||
create_public_stream_policy_elem.attr("id", "id_realm_create_public_stream_policy");
|
||||
create_public_stream_policy_elem.data = () => "number";
|
||||
const $create_public_stream_policy_elem = $("#id_realm_create_public_stream_policy");
|
||||
$create_public_stream_policy_elem.val("2");
|
||||
$create_public_stream_policy_elem.attr("id", "id_realm_create_public_stream_policy");
|
||||
$create_public_stream_policy_elem.data = () => "number";
|
||||
|
||||
const create_private_stream_policy_elem = $("#id_realm_create_private_stream_policy");
|
||||
create_private_stream_policy_elem.val("2");
|
||||
create_private_stream_policy_elem.attr("id", "id_realm_create_private_stream_policy");
|
||||
create_private_stream_policy_elem.data = () => "number";
|
||||
const $create_private_stream_policy_elem = $("#id_realm_create_private_stream_policy");
|
||||
$create_private_stream_policy_elem.val("2");
|
||||
$create_private_stream_policy_elem.attr("id", "id_realm_create_private_stream_policy");
|
||||
$create_private_stream_policy_elem.data = () => "number";
|
||||
|
||||
const add_custom_emoji_policy_elem = $("#id_realm_add_custom_emoji_policy");
|
||||
add_custom_emoji_policy_elem.val("1");
|
||||
add_custom_emoji_policy_elem.attr("id", "id_realm_add_custom_emoji_policy");
|
||||
add_custom_emoji_policy_elem.data = () => "number";
|
||||
const $add_custom_emoji_policy_elem = $("#id_realm_add_custom_emoji_policy");
|
||||
$add_custom_emoji_policy_elem.val("1");
|
||||
$add_custom_emoji_policy_elem.attr("id", "id_realm_add_custom_emoji_policy");
|
||||
$add_custom_emoji_policy_elem.data = () => "number";
|
||||
|
||||
const bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
|
||||
bot_creation_policy_elem.val("1");
|
||||
bot_creation_policy_elem.attr("id", "id_realm_bot_creation_policy");
|
||||
bot_creation_policy_elem.data = () => "number";
|
||||
const email_address_visibility_elem = $("#id_realm_email_address_visibility");
|
||||
email_address_visibility_elem.val("1");
|
||||
email_address_visibility_elem.attr("id", "id_realm_email_address_visibility");
|
||||
email_address_visibility_elem.data = () => "number";
|
||||
const $bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
|
||||
$bot_creation_policy_elem.val("1");
|
||||
$bot_creation_policy_elem.attr("id", "id_realm_bot_creation_policy");
|
||||
$bot_creation_policy_elem.data = () => "number";
|
||||
const $email_address_visibility_elem = $("#id_realm_email_address_visibility");
|
||||
$email_address_visibility_elem.val("1");
|
||||
$email_address_visibility_elem.attr("id", "id_realm_email_address_visibility");
|
||||
$email_address_visibility_elem.data = () => "number";
|
||||
|
||||
const invite_to_realm_policy_elem = $("#id_realm_invite_to_realm_policy");
|
||||
invite_to_realm_policy_elem.val("2");
|
||||
invite_to_realm_policy_elem.attr("id", "id_realm_invite_to_realm_policy");
|
||||
invite_to_realm_policy_elem.data = () => "number";
|
||||
const $invite_to_realm_policy_elem = $("#id_realm_invite_to_realm_policy");
|
||||
$invite_to_realm_policy_elem.val("2");
|
||||
$invite_to_realm_policy_elem.attr("id", "id_realm_invite_to_realm_policy");
|
||||
$invite_to_realm_policy_elem.data = () => "number";
|
||||
|
||||
let subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
||||
subsection_elem.closest = () => subsection_elem;
|
||||
subsection_elem.set_find_results(".prop-element", [
|
||||
bot_creation_policy_elem,
|
||||
email_address_visibility_elem,
|
||||
add_custom_emoji_policy_elem,
|
||||
create_public_stream_policy_elem,
|
||||
create_private_stream_policy_elem,
|
||||
invite_to_stream_policy_elem,
|
||||
let $subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
||||
$subsection_elem.closest = () => $subsection_elem;
|
||||
$subsection_elem.set_find_results(".prop-element", [
|
||||
$bot_creation_policy_elem,
|
||||
$email_address_visibility_elem,
|
||||
$add_custom_emoji_policy_elem,
|
||||
$create_public_stream_policy_elem,
|
||||
$create_private_stream_policy_elem,
|
||||
$invite_to_stream_policy_elem,
|
||||
]);
|
||||
|
||||
patched = false;
|
||||
@@ -261,17 +261,17 @@ function test_submit_settings_form(override, submit_form) {
|
||||
subsection = "user-defaults";
|
||||
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
|
||||
stubs = createSaveButtons(subsection);
|
||||
save_button = stubs.save_button;
|
||||
save_button.attr("id", `org-submit-${subsection}`);
|
||||
$save_button = stubs.$save_button;
|
||||
$save_button.attr("id", `org-submit-${subsection}`);
|
||||
|
||||
const realm_default_language_elem = $("#id_realm_default_language");
|
||||
realm_default_language_elem.val("en");
|
||||
realm_default_language_elem.attr("id", "id_realm_default_language");
|
||||
realm_default_language_elem.data = () => "string";
|
||||
const $realm_default_language_elem = $("#id_realm_default_language");
|
||||
$realm_default_language_elem.val("en");
|
||||
$realm_default_language_elem.attr("id", "id_realm_default_language");
|
||||
$realm_default_language_elem.data = () => "string";
|
||||
|
||||
subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
||||
subsection_elem.closest = () => subsection_elem;
|
||||
subsection_elem.set_find_results(".prop-element", [realm_default_language_elem]);
|
||||
$subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
||||
$subsection_elem.closest = () => $subsection_elem;
|
||||
$subsection_elem.set_find_results(".prop-element", [$realm_default_language_elem]);
|
||||
|
||||
submit_form(ev);
|
||||
assert.ok(patched);
|
||||
@@ -284,50 +284,50 @@ function test_submit_settings_form(override, submit_form) {
|
||||
// Testing only once for since callback is same for all cases
|
||||
success_callback();
|
||||
assert.equal(stubs.props.hidden, true);
|
||||
assert.equal(save_button.attr("data-status"), "saved");
|
||||
assert.equal(stubs.save_button_text.text(), "translated: Saved");
|
||||
assert.equal($save_button.attr("data-status"), "saved");
|
||||
assert.equal(stubs.$save_button_text.text(), "translated: Saved");
|
||||
}
|
||||
|
||||
function test_change_save_button_state() {
|
||||
const {save_button_controls, save_button_text, save_button, discard_button, props} =
|
||||
const {$save_button_controls, $save_button_text, $save_button, $discard_button, props} =
|
||||
createSaveButtons("msg-editing");
|
||||
save_button.attr("id", "org-submit-msg-editing");
|
||||
$save_button.attr("id", "org-submit-msg-editing");
|
||||
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "unsaved");
|
||||
assert.equal(save_button_text.text(), "translated: Save changes");
|
||||
settings_org.change_save_button_state($save_button_controls, "unsaved");
|
||||
assert.equal($save_button_text.text(), "translated: Save changes");
|
||||
assert.equal(props.hidden, false);
|
||||
assert.equal(save_button.attr("data-status"), "unsaved");
|
||||
assert.equal(discard_button.visible(), true);
|
||||
assert.equal($save_button.attr("data-status"), "unsaved");
|
||||
assert.equal($discard_button.visible(), true);
|
||||
}
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "saved");
|
||||
assert.equal(save_button_text.text(), "translated: Save changes");
|
||||
settings_org.change_save_button_state($save_button_controls, "saved");
|
||||
assert.equal($save_button_text.text(), "translated: Save changes");
|
||||
assert.equal(props.hidden, true);
|
||||
assert.equal(save_button.attr("data-status"), "");
|
||||
assert.equal($save_button.attr("data-status"), "");
|
||||
}
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "saving");
|
||||
assert.equal(save_button_text.text(), "translated: Saving");
|
||||
assert.equal(save_button.attr("data-status"), "saving");
|
||||
assert.equal(save_button.hasClass("saving"), true);
|
||||
assert.equal(discard_button.visible(), false);
|
||||
settings_org.change_save_button_state($save_button_controls, "saving");
|
||||
assert.equal($save_button_text.text(), "translated: Saving");
|
||||
assert.equal($save_button.attr("data-status"), "saving");
|
||||
assert.equal($save_button.hasClass("saving"), true);
|
||||
assert.equal($discard_button.visible(), false);
|
||||
}
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "discarded");
|
||||
settings_org.change_save_button_state($save_button_controls, "discarded");
|
||||
assert.equal(props.hidden, true);
|
||||
}
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "succeeded");
|
||||
settings_org.change_save_button_state($save_button_controls, "succeeded");
|
||||
assert.equal(props.hidden, true);
|
||||
assert.equal(save_button.attr("data-status"), "saved");
|
||||
assert.equal(save_button_text.text(), "translated: Saved");
|
||||
assert.equal($save_button.attr("data-status"), "saved");
|
||||
assert.equal($save_button_text.text(), "translated: Saved");
|
||||
}
|
||||
{
|
||||
settings_org.change_save_button_state(save_button_controls, "failed");
|
||||
settings_org.change_save_button_state($save_button_controls, "failed");
|
||||
assert.equal(props.hidden, false);
|
||||
assert.equal(save_button.attr("data-status"), "failed");
|
||||
assert.equal(save_button_text.text(), "translated: Save changes");
|
||||
assert.equal($save_button.attr("data-status"), "failed");
|
||||
assert.equal($save_button_text.text(), "translated: Save changes");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,8 +358,8 @@ function test_change_allow_subdomains(change_allow_subdomains) {
|
||||
stopPropagation: noop,
|
||||
};
|
||||
|
||||
const info = $(".realm_domains_info");
|
||||
info.fadeOut = noop;
|
||||
const $info = $(".realm_domains_info");
|
||||
$info.fadeOut = noop;
|
||||
const domain = "example.com";
|
||||
let allow = true;
|
||||
|
||||
@@ -372,33 +372,33 @@ function test_change_allow_subdomains(change_allow_subdomains) {
|
||||
error_callback = req.error;
|
||||
};
|
||||
|
||||
const domain_obj = $.create("domain object");
|
||||
domain_obj.text(domain);
|
||||
const $domain_obj = $.create("domain object");
|
||||
$domain_obj.text(domain);
|
||||
|
||||
const elem_obj = $.create("<elem html>");
|
||||
const parents_obj = $.create("parents object");
|
||||
const $elem_obj = $.create("<elem html>");
|
||||
const $parents_obj = $.create("parents object");
|
||||
|
||||
elem_obj.set_parents_result("tr", parents_obj);
|
||||
parents_obj.set_find_results(".domain", domain_obj);
|
||||
elem_obj.prop("checked", allow);
|
||||
$elem_obj.set_parents_result("tr", $parents_obj);
|
||||
$parents_obj.set_find_results(".domain", $domain_obj);
|
||||
$elem_obj.prop("checked", allow);
|
||||
|
||||
change_allow_subdomains.call(elem_obj, ev);
|
||||
change_allow_subdomains.call($elem_obj, ev);
|
||||
|
||||
success_callback();
|
||||
assert.equal(
|
||||
info.val(),
|
||||
$info.val(),
|
||||
"translated HTML: Update successful: Subdomains allowed for example.com",
|
||||
);
|
||||
|
||||
error_callback({});
|
||||
assert.equal(info.val(), "translated HTML: Failed");
|
||||
assert.equal($info.val(), "translated HTML: Failed");
|
||||
|
||||
allow = false;
|
||||
elem_obj.prop("checked", allow);
|
||||
change_allow_subdomains.call(elem_obj, ev);
|
||||
$elem_obj.prop("checked", allow);
|
||||
change_allow_subdomains.call($elem_obj, ev);
|
||||
success_callback();
|
||||
assert.equal(
|
||||
info.val(),
|
||||
$info.val(),
|
||||
"translated HTML: Update successful: Subdomains no longer allowed for example.com",
|
||||
);
|
||||
}
|
||||
@@ -431,9 +431,9 @@ function test_sync_realm_settings() {
|
||||
|
||||
{
|
||||
/* Test invalid settings property sync */
|
||||
const property_elem = $("#id_realm_invalid_settings_property");
|
||||
property_elem.attr("id", "id_realm_invalid_settings_property");
|
||||
property_elem.length = 1;
|
||||
const $property_elem = $("#id_realm_invalid_settings_property");
|
||||
$property_elem.attr("id", "id_realm_invalid_settings_property");
|
||||
$property_elem.length = 1;
|
||||
|
||||
blueslip.expect(
|
||||
"error",
|
||||
@@ -443,9 +443,9 @@ function test_sync_realm_settings() {
|
||||
}
|
||||
|
||||
function test_common_policy(property_name) {
|
||||
const property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
|
||||
property_elem.length = 1;
|
||||
property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
|
||||
const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
|
||||
$property_elem.length = 1;
|
||||
$property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
|
||||
|
||||
/* Each policy is initialized to 'by_members' and then all the values are tested
|
||||
in the following order - by_admins_only, by_moderators_only, by_full_members,
|
||||
@@ -453,14 +453,14 @@ function test_sync_realm_settings() {
|
||||
|
||||
page_params[`realm_${property_name}`] =
|
||||
settings_config.common_policy_values.by_members.code;
|
||||
property_elem.val(settings_config.common_policy_values.by_members.code);
|
||||
$property_elem.val(settings_config.common_policy_values.by_members.code);
|
||||
|
||||
for (const policy_value of Array.from(
|
||||
Object.values(settings_config.common_policy_values),
|
||||
)) {
|
||||
page_params[`realm_${property_name}`] = policy_value.code;
|
||||
settings_org.sync_realm_settings(property_name);
|
||||
assert.equal(property_elem.val(), policy_value.code);
|
||||
assert.equal($property_elem.val(), policy_value.code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,9 +471,9 @@ function test_sync_realm_settings() {
|
||||
|
||||
{
|
||||
/* Test message content edit limit minutes sync */
|
||||
const property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
property_elem.length = 1;
|
||||
property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
const $property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
$property_elem.length = 1;
|
||||
$property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
|
||||
page_params.realm_create_public_stream_policy = 1;
|
||||
page_params.realm_message_content_edit_limit_seconds = 120;
|
||||
@@ -484,9 +484,9 @@ function test_sync_realm_settings() {
|
||||
|
||||
{
|
||||
/* Test message content edit limit dropdown value sync */
|
||||
const property_elem = $("#id_realm_msg_edit_limit_setting");
|
||||
property_elem.length = 1;
|
||||
property_elem.attr("id", "id_realm_msg_edit_limit_setting");
|
||||
const $property_elem = $("#id_realm_msg_edit_limit_setting");
|
||||
$property_elem.length = 1;
|
||||
$property_elem.attr("id", "id_realm_msg_edit_limit_setting");
|
||||
|
||||
page_params.realm_allow_message_editing = false;
|
||||
page_params.realm_message_content_edit_limit_seconds = 120;
|
||||
@@ -506,9 +506,9 @@ function test_sync_realm_settings() {
|
||||
|
||||
{
|
||||
/* Test message content edit limit minutes sync */
|
||||
const property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
property_elem.length = 1;
|
||||
property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
const $property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
$property_elem.length = 1;
|
||||
$property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
|
||||
page_params.realm_create_public_stream_policy = 1;
|
||||
page_params.realm_message_content_edit_limit_seconds = 120;
|
||||
@@ -519,9 +519,9 @@ function test_sync_realm_settings() {
|
||||
|
||||
{
|
||||
/* Test organization joining restrictions settings sync */
|
||||
const property_elem = $("#id_realm_org_join_restrictions");
|
||||
property_elem.length = 1;
|
||||
property_elem.attr("id", "id_realm_org_join_restrictions");
|
||||
const $property_elem = $("#id_realm_org_join_restrictions");
|
||||
$property_elem.length = 1;
|
||||
$property_elem.attr("id", "id_realm_org_join_restrictions");
|
||||
|
||||
page_params.realm_emails_restricted_to_domains = true;
|
||||
page_params.realm_disallow_disposable_email_addresses = false;
|
||||
@@ -541,10 +541,10 @@ function test_sync_realm_settings() {
|
||||
}
|
||||
|
||||
function test_parse_time_limit() {
|
||||
const elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
const $elem = $("#id_realm_message_content_edit_limit_minutes");
|
||||
const test_function = (value, expected_value = value) => {
|
||||
elem.val(value);
|
||||
page_params.realm_message_content_edit_limit_seconds = settings_org.parse_time_limit(elem);
|
||||
$elem.val(value);
|
||||
page_params.realm_message_content_edit_limit_seconds = settings_org.parse_time_limit($elem);
|
||||
assert.equal(
|
||||
settings_org.get_realm_time_limits_in_minutes(
|
||||
"realm_message_content_edit_limit_seconds",
|
||||
@@ -587,40 +587,40 @@ function test_discard_changes_button(discard_changes) {
|
||||
settings_config.common_message_policy_values.by_everyone.code;
|
||||
page_params.realm_message_content_delete_limit_seconds = 120;
|
||||
|
||||
const allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
|
||||
const edit_topic_policy = $("#id_realm_edit_topic_policy").val(
|
||||
const $allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
|
||||
const $edit_topic_policy = $("#id_realm_edit_topic_policy").val(
|
||||
settings_config.common_message_policy_values.by_admins_only.code,
|
||||
);
|
||||
const msg_edit_limit_setting = $("#id_realm_msg_edit_limit_setting").val("custom_limit");
|
||||
const message_content_edit_limit_minutes = $(
|
||||
const $msg_edit_limit_setting = $("#id_realm_msg_edit_limit_setting").val("custom_limit");
|
||||
const $message_content_edit_limit_minutes = $(
|
||||
"#id_realm_message_content_edit_limit_minutes",
|
||||
).val(130);
|
||||
const msg_delete_limit_setting = $("#id_realm_msg_delete_limit_setting").val("custom_limit");
|
||||
const message_content_delete_limit_minutes = $(
|
||||
const $msg_delete_limit_setting = $("#id_realm_msg_delete_limit_setting").val("custom_limit");
|
||||
const $message_content_delete_limit_minutes = $(
|
||||
"#id_realm_message_content_delete_limit_minutes",
|
||||
).val(130);
|
||||
|
||||
allow_edit_history.attr("id", "id_realm_allow_edit_history");
|
||||
msg_edit_limit_setting.attr("id", "id_realm_msg_edit_limit_setting");
|
||||
msg_delete_limit_setting.attr("id", "id_realm_msg_delete_limit_setting");
|
||||
edit_topic_policy.attr("id", "id_realm_edit_topic_policy");
|
||||
message_content_edit_limit_minutes.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
message_content_delete_limit_minutes.attr(
|
||||
$allow_edit_history.attr("id", "id_realm_allow_edit_history");
|
||||
$msg_edit_limit_setting.attr("id", "id_realm_msg_edit_limit_setting");
|
||||
$msg_delete_limit_setting.attr("id", "id_realm_msg_delete_limit_setting");
|
||||
$edit_topic_policy.attr("id", "id_realm_edit_topic_policy");
|
||||
$message_content_edit_limit_minutes.attr("id", "id_realm_message_content_edit_limit_minutes");
|
||||
$message_content_delete_limit_minutes.attr(
|
||||
"id",
|
||||
"id_realm_message_content_delete_limit_minutes",
|
||||
);
|
||||
|
||||
const discard_button_parent = $(".org-subsection-parent");
|
||||
discard_button_parent.find = () => [
|
||||
allow_edit_history,
|
||||
msg_edit_limit_setting,
|
||||
msg_delete_limit_setting,
|
||||
edit_topic_policy,
|
||||
message_content_edit_limit_minutes,
|
||||
message_content_delete_limit_minutes,
|
||||
const $discard_button_parent = $(".org-subsection-parent");
|
||||
$discard_button_parent.find = () => [
|
||||
$allow_edit_history,
|
||||
$msg_edit_limit_setting,
|
||||
$msg_delete_limit_setting,
|
||||
$edit_topic_policy,
|
||||
$message_content_edit_limit_minutes,
|
||||
$message_content_delete_limit_minutes,
|
||||
];
|
||||
|
||||
$("#org-discard-msg-editing").closest = () => discard_button_parent;
|
||||
$("#org-discard-msg-editing").closest = () => $discard_button_parent;
|
||||
|
||||
const stubbed_function = settings_org.change_save_button_state;
|
||||
settings_org.__Rewire__("change_save_button_state", (save_button_controls, state) => {
|
||||
@@ -629,15 +629,15 @@ function test_discard_changes_button(discard_changes) {
|
||||
|
||||
discard_changes(ev);
|
||||
|
||||
assert.equal(allow_edit_history.prop("checked"), true);
|
||||
assert.equal($allow_edit_history.prop("checked"), true);
|
||||
assert.equal(
|
||||
edit_topic_policy.val(),
|
||||
$edit_topic_policy.val(),
|
||||
settings_config.common_message_policy_values.by_everyone.code,
|
||||
);
|
||||
assert.equal(msg_edit_limit_setting.val(), "upto_one_hour");
|
||||
assert.equal(message_content_edit_limit_minutes.val(), "60");
|
||||
assert.equal(msg_delete_limit_setting.val(), "upto_two_min");
|
||||
assert.equal(message_content_delete_limit_minutes.val(), "2");
|
||||
assert.equal($msg_edit_limit_setting.val(), "upto_one_hour");
|
||||
assert.equal($message_content_edit_limit_minutes.val(), "60");
|
||||
assert.equal($msg_delete_limit_setting.val(), "upto_two_min");
|
||||
assert.equal($message_content_delete_limit_minutes.val(), "2");
|
||||
|
||||
settings_org.__Rewire__("change_save_button_state", stubbed_function);
|
||||
}
|
||||
@@ -683,8 +683,8 @@ test("set_up", ({override, override_rewire, mock_template}) => {
|
||||
$("#enable_digest_emails_label").set_parent($.create("<stub digest setting checkbox>"));
|
||||
$("#id_realm_digest_weekday").set_parent($.create("<stub digest weekday setting dropdown>"));
|
||||
$("#allowed_domains_label").set_parent($.create("<stub-allowed-domain-label-parent>"));
|
||||
const waiting_period_parent_elem = $.create("waiting-period-parent-stub");
|
||||
$("#id_realm_waiting_period_threshold").set_parent(waiting_period_parent_elem);
|
||||
const $waiting_period_parent_elem = $.create("waiting-period-parent-stub");
|
||||
$("#id_realm_waiting_period_threshold").set_parent($waiting_period_parent_elem);
|
||||
$("#id_realm_create_web_public_stream_policy").set_parent(
|
||||
$.create("<stub-create-web-public-stream-policy-parent>"),
|
||||
);
|
||||
@@ -829,8 +829,8 @@ test("test get_sorted_options_list", () => {
|
||||
test("misc", ({override_rewire}) => {
|
||||
page_params.is_admin = false;
|
||||
|
||||
const stub_notification_disable_parent = $.create("<stub notification_disable parent");
|
||||
stub_notification_disable_parent.set_find_results(
|
||||
const $stub_notification_disable_parent = $.create("<stub notification_disable parent");
|
||||
$stub_notification_disable_parent.set_find_results(
|
||||
".dropdown_list_reset_button",
|
||||
$.create("<disable link>"),
|
||||
);
|
||||
@@ -904,14 +904,14 @@ test("misc", ({override_rewire}) => {
|
||||
"realm_signup_notifications_stream_id",
|
||||
"realm_default_code_block_language",
|
||||
];
|
||||
const dropdown_list_parent = $.create("<list parent>");
|
||||
dropdown_list_parent.set_find_results(
|
||||
const $dropdown_list_parent = $.create("<list parent>");
|
||||
$dropdown_list_parent.set_find_results(
|
||||
".dropdown_list_reset_button",
|
||||
$.create("<disable button>"),
|
||||
);
|
||||
for (const name of widget_settings) {
|
||||
const elem = $.create(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`);
|
||||
elem.closest = () => dropdown_list_parent;
|
||||
const $elem = $.create(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`);
|
||||
$elem.closest = () => $dropdown_list_parent;
|
||||
}
|
||||
|
||||
// We do not define any settings we need in page_params yet, but we don't need to for this test.
|
||||
@@ -923,32 +923,32 @@ test("misc", ({override_rewire}) => {
|
||||
settings_org.init_dropdown_widgets();
|
||||
|
||||
let setting_name = "realm_notifications_stream_id";
|
||||
let elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
||||
elem.closest = () => stub_notification_disable_parent;
|
||||
let $elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
||||
$elem.closest = () => $stub_notification_disable_parent;
|
||||
sub_store.__Rewire__("get", (stream_id) => {
|
||||
assert.equal(stream_id, 42);
|
||||
return {name: "some_stream"};
|
||||
});
|
||||
settings_org.notifications_stream_widget.render(42);
|
||||
assert.equal(elem.text(), "#some_stream");
|
||||
assert.ok(!elem.hasClass("text-warning"));
|
||||
assert.equal($elem.text(), "#some_stream");
|
||||
assert.ok(!$elem.hasClass("text-warning"));
|
||||
|
||||
settings_org.notifications_stream_widget.render(undefined);
|
||||
assert.equal(elem.text(), "translated: Disabled");
|
||||
assert.ok(elem.hasClass("text-warning"));
|
||||
assert.equal($elem.text(), "translated: Disabled");
|
||||
assert.ok($elem.hasClass("text-warning"));
|
||||
|
||||
setting_name = "realm_signup_notifications_stream_id";
|
||||
elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
||||
elem.closest = () => stub_notification_disable_parent;
|
||||
$elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
||||
$elem.closest = () => $stub_notification_disable_parent;
|
||||
sub_store.__Rewire__("get", (stream_id) => {
|
||||
assert.equal(stream_id, 75);
|
||||
return {name: "some_stream"};
|
||||
});
|
||||
settings_org.signup_notifications_stream_widget.render(75);
|
||||
assert.equal(elem.text(), "#some_stream");
|
||||
assert.ok(!elem.hasClass("text-warning"));
|
||||
assert.equal($elem.text(), "#some_stream");
|
||||
assert.ok(!$elem.hasClass("text-warning"));
|
||||
|
||||
settings_org.signup_notifications_stream_widget.render(undefined);
|
||||
assert.equal(elem.text(), "translated: Disabled");
|
||||
assert.ok(elem.hasClass("text-warning"));
|
||||
assert.equal($elem.text(), "translated: Disabled");
|
||||
assert.ok($elem.hasClass("text-warning"));
|
||||
});
|
||||
|
||||
@@ -43,19 +43,19 @@ function test_populate(opts, template_data) {
|
||||
const fields_data = opts.fields_data;
|
||||
|
||||
page_params.is_admin = opts.is_admin;
|
||||
const table = $("#admin_profile_fields_table");
|
||||
const rows = $.create("rows");
|
||||
const form = $.create("forms");
|
||||
table.set_find_results("tr.profile-field-row", rows);
|
||||
table.set_find_results("tr.profile-field-form", form);
|
||||
const $table = $("#admin_profile_fields_table");
|
||||
const $rows = $.create("rows");
|
||||
const $form = $.create("forms");
|
||||
$table.set_find_results("tr.profile-field-row", $rows);
|
||||
$table.set_find_results("tr.profile-field-form", $form);
|
||||
|
||||
table[0] = "stub";
|
||||
$table[0] = "stub";
|
||||
|
||||
rows.remove = () => {};
|
||||
form.remove = () => {};
|
||||
$rows.remove = () => {};
|
||||
$form.remove = () => {};
|
||||
|
||||
let num_appends = 0;
|
||||
table.append = () => {
|
||||
$table.append = () => {
|
||||
num_appends += 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ const settings_data = zrequire("settings_data");
|
||||
const settings_user_groups = zrequire("settings_user_groups");
|
||||
const user_pill = zrequire("user_pill");
|
||||
|
||||
function reset_test_setup(pill_container_stub) {
|
||||
function reset_test_setup($pill_container_stub) {
|
||||
function input_pill_stub(opts) {
|
||||
assert.equal(opts.container, pill_container_stub);
|
||||
assert.equal(opts.$container, $pill_container_stub);
|
||||
create_item_handler = opts.create_item_from_text;
|
||||
assert.ok(create_item_handler);
|
||||
return pills;
|
||||
@@ -119,18 +119,18 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
people.get_visible_email = () => bob.email;
|
||||
|
||||
let templates_render_called = false;
|
||||
const fake_rendered_temp = $.create("fake_admin_user_group_list_template_rendered");
|
||||
const $fake_rendered_temp = $.create("fake_admin_user_group_list_template_rendered");
|
||||
mock_template("settings/admin_user_group_list.hbs", false, (args) => {
|
||||
assert.equal(args.user_group.id, 1);
|
||||
assert.equal(args.user_group.name, "Mobile");
|
||||
assert.equal(args.user_group.description, "All mobile people");
|
||||
templates_render_called = true;
|
||||
return fake_rendered_temp;
|
||||
return $fake_rendered_temp;
|
||||
});
|
||||
|
||||
let user_groups_list_append_called = false;
|
||||
$("#user-groups").append = (rendered_temp) => {
|
||||
assert.equal(rendered_temp, fake_rendered_temp);
|
||||
assert.equal(rendered_temp, $fake_rendered_temp);
|
||||
user_groups_list_append_called = true;
|
||||
};
|
||||
|
||||
@@ -158,7 +158,7 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
|
||||
const all_pills = new Map();
|
||||
|
||||
const pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
|
||||
const $pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
|
||||
pills.appendValidatedData = (item) => {
|
||||
const id = item.user_id;
|
||||
assert.ok(!all_pills.has(id));
|
||||
@@ -171,11 +171,11 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
text_cleared = true;
|
||||
};
|
||||
|
||||
const input_field_stub = $.create("fake-input-field");
|
||||
pill_container_stub.children = () => input_field_stub;
|
||||
const $input_field_stub = $.create("fake-input-field");
|
||||
$pill_container_stub.children = () => $input_field_stub;
|
||||
|
||||
let input_typeahead_called = false;
|
||||
input_field_stub.typeahead = (config) => {
|
||||
$input_field_stub.typeahead = (config) => {
|
||||
assert.equal(config.items, 5);
|
||||
assert.ok(config.fixed);
|
||||
assert.ok(config.dropup);
|
||||
@@ -187,9 +187,9 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
assert.equal(typeof config.updater, "function");
|
||||
|
||||
(function test_highlighter() {
|
||||
const fake_person = $.create("fake-person");
|
||||
typeahead_helper.render_person = () => fake_person;
|
||||
assert.equal(config.highlighter(), fake_person);
|
||||
const $fake_person = $.create("fake-person");
|
||||
typeahead_helper.render_person = () => $fake_person;
|
||||
assert.equal(config.highlighter(), $fake_person);
|
||||
})();
|
||||
|
||||
const fake_context = {
|
||||
@@ -236,7 +236,7 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
})();
|
||||
|
||||
(function test_updater() {
|
||||
input_field_stub.text("@ali");
|
||||
$input_field_stub.text("@ali");
|
||||
user_groups.get_user_group_from_id = () => realm_user_group;
|
||||
|
||||
let saved_fade_out_called = false;
|
||||
@@ -334,7 +334,7 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
|
||||
handler();
|
||||
};
|
||||
|
||||
reset_test_setup(pill_container_stub);
|
||||
reset_test_setup($pill_container_stub);
|
||||
settings_user_groups.set_up();
|
||||
assert.ok(templates_render_called);
|
||||
assert.ok(user_groups_list_append_called);
|
||||
@@ -386,63 +386,63 @@ test_ui("with_external_user", ({override_rewire, mock_template}) => {
|
||||
$.clear_all_elements();
|
||||
|
||||
let user_group_find_called = 0;
|
||||
const user_group_stub = $(`div.user-group[id="${CSS.escape(1)}"]`);
|
||||
const name_field_stub = $.create("fake-name-field");
|
||||
const description_field_stub = $.create("fake-description-field");
|
||||
const input_stub = $.create("fake-input");
|
||||
user_group_stub.find = (elem) => {
|
||||
const $user_group_stub = $(`div.user-group[id="${CSS.escape(1)}"]`);
|
||||
const $name_field_stub = $.create("fake-name-field");
|
||||
const $description_field_stub = $.create("fake-description-field");
|
||||
const $input_stub = $.create("fake-input");
|
||||
$user_group_stub.find = (elem) => {
|
||||
if (elem === ".name") {
|
||||
user_group_find_called += 1;
|
||||
return name_field_stub;
|
||||
return $name_field_stub;
|
||||
}
|
||||
if (elem === ".description") {
|
||||
user_group_find_called += 1;
|
||||
return description_field_stub;
|
||||
return $description_field_stub;
|
||||
}
|
||||
throw new Error(`Unknown element ${elem}`);
|
||||
};
|
||||
|
||||
const pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
|
||||
const pill_stub = $.create("fake-pill");
|
||||
const $pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
|
||||
const $pill_stub = $.create("fake-pill");
|
||||
let pill_container_find_called = 0;
|
||||
pill_container_stub.find = (elem) => {
|
||||
$pill_container_stub.find = (elem) => {
|
||||
if (elem === ".input") {
|
||||
pill_container_find_called += 1;
|
||||
return input_stub;
|
||||
return $input_stub;
|
||||
}
|
||||
if (elem === ".pill") {
|
||||
pill_container_find_called += 1;
|
||||
return pill_stub;
|
||||
return $pill_stub;
|
||||
}
|
||||
throw new Error(`Unknown element ${elem}`);
|
||||
};
|
||||
|
||||
input_stub.css = (property, val) => {
|
||||
$input_stub.css = (property, val) => {
|
||||
assert.equal(property, "display");
|
||||
assert.equal(val, "none");
|
||||
};
|
||||
|
||||
// Test the 'off' handlers on the pill-container
|
||||
const turned_off = {};
|
||||
pill_container_stub.off = (event_name, sel = "whole") => {
|
||||
$pill_container_stub.off = (event_name, sel = "whole") => {
|
||||
turned_off[event_name + "/" + sel] = true;
|
||||
};
|
||||
|
||||
const exit_button = $.create("fake-pill-exit");
|
||||
pill_stub.set_find_results(".exit", exit_button);
|
||||
const $exit_button = $.create("fake-pill-exit");
|
||||
$pill_stub.set_find_results(".exit", $exit_button);
|
||||
let exit_button_called = false;
|
||||
exit_button.css = (property, value) => {
|
||||
$exit_button.css = (property, value) => {
|
||||
exit_button_called = true;
|
||||
assert.equal(property, "opacity");
|
||||
assert.equal(value, "0.5");
|
||||
};
|
||||
|
||||
// We return noop because these are already tested, so we skip them
|
||||
pill_container_stub.children = () => noop;
|
||||
$pill_container_stub.children = () => noop;
|
||||
|
||||
$("#user-groups").append = () => noop;
|
||||
|
||||
reset_test_setup(pill_container_stub);
|
||||
reset_test_setup($pill_container_stub);
|
||||
|
||||
settings_user_groups.set_up();
|
||||
|
||||
@@ -451,8 +451,8 @@ test_ui("with_external_user", ({override_rewire, mock_template}) => {
|
||||
|
||||
// Test different handlers with an external user
|
||||
const delete_handler = $("#user-groups").get_on_handler("click", ".delete");
|
||||
const fake_delete = $.create("fk-#user-groups.delete_btn");
|
||||
fake_delete.set_parents_result(".user-group", $(".user-group"));
|
||||
const $fake_delete = $.create("fk-#user-groups.delete_btn");
|
||||
$fake_delete.set_parents_result(".user-group", $(".user-group"));
|
||||
set_parents_result_called += 1;
|
||||
$(".user-group").attr("id", "1");
|
||||
set_attributes_called += 1;
|
||||
@@ -470,11 +470,11 @@ test_ui("with_external_user", ({override_rewire, mock_template}) => {
|
||||
const event = {
|
||||
stopPropagation: noop,
|
||||
};
|
||||
const pill_mouseenter_handler = pill_stub.get_on_handler("mouseenter");
|
||||
const pill_click_handler = pill_container_stub.get_on_handler("click");
|
||||
const pill_mouseenter_handler = $pill_stub.get_on_handler("mouseenter");
|
||||
const pill_click_handler = $pill_container_stub.get_on_handler("click");
|
||||
pill_mouseenter_handler(event);
|
||||
pill_click_handler(event);
|
||||
assert.equal(delete_handler.call(fake_delete), undefined);
|
||||
assert.equal(delete_handler.call($fake_delete), undefined);
|
||||
assert.equal(name_update_handler(), undefined);
|
||||
assert.equal(des_update_handler(), undefined);
|
||||
assert.equal(member_change_handler(), undefined);
|
||||
@@ -524,7 +524,7 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
stopPropagation: noop,
|
||||
preventDefault: noop,
|
||||
};
|
||||
const fake_this = $.create("fake-form.admin-user-group-form");
|
||||
const $fake_this = $.create("fake-form.admin-user-group-form");
|
||||
const fake_object_array = [
|
||||
{
|
||||
name: "fake-name",
|
||||
@@ -535,7 +535,7 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
value: "fake-value",
|
||||
},
|
||||
];
|
||||
fake_this.serializeArray = () => fake_object_array;
|
||||
$fake_this.serializeArray = () => fake_object_array;
|
||||
channel.post = (opts) => {
|
||||
const data = {
|
||||
members: "[null]",
|
||||
@@ -577,13 +577,13 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
})();
|
||||
};
|
||||
|
||||
handler.call(fake_this, event);
|
||||
handler.call($fake_this, event);
|
||||
})();
|
||||
|
||||
(function test_user_groups_delete_click_triggered() {
|
||||
const handler = $("#user-groups").get_on_handler("click", ".delete");
|
||||
const fake_this = $.create("fake-#user-groups.delete_btn");
|
||||
fake_this.set_parents_result(".user-group", $(".user-group"));
|
||||
const $fake_this = $.create("fake-#user-groups.delete_btn");
|
||||
$fake_this.set_parents_result(".user-group", $(".user-group"));
|
||||
$(".user-group").attr("id", "1");
|
||||
|
||||
channel.del = (opts) => {
|
||||
@@ -593,16 +593,16 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
assert.equal(opts.url, "/json/user_groups/1");
|
||||
assert.deepEqual(opts.data, data);
|
||||
|
||||
fake_this.text($t({defaultMessage: "fake-text"}));
|
||||
$fake_this.text($t({defaultMessage: "fake-text"}));
|
||||
opts.error();
|
||||
assert.equal(fake_this.text(), "translated: Failed!");
|
||||
assert.equal($fake_this.text(), "translated: Failed!");
|
||||
};
|
||||
|
||||
confirm_dialog.launch = (conf) => {
|
||||
conf.on_click();
|
||||
};
|
||||
|
||||
handler.call(fake_this);
|
||||
handler.call($fake_this);
|
||||
})();
|
||||
|
||||
(function test_user_groups_keypress_enter_triggered() {
|
||||
@@ -625,9 +625,10 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
api_endpoint_called = true;
|
||||
};
|
||||
channel.patch = noop;
|
||||
const fake_this = $.create("fake-#user-groups_do_not_blur");
|
||||
const $fake_this = $.create("fake-#user-groups_do_not_blur");
|
||||
const event = {
|
||||
relatedTarget: fake_this,
|
||||
// FIXME: event.relatedTarget should not be a jQuery object
|
||||
relatedTarget: $fake_this,
|
||||
};
|
||||
|
||||
// Any of the blur_exceptions trigger blur event.
|
||||
@@ -645,24 +646,24 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
continue;
|
||||
}
|
||||
api_endpoint_called = false;
|
||||
fake_this.closest = (class_name) => {
|
||||
$fake_this.closest = (class_name) => {
|
||||
if (class_name === blur_exception || class_name === user_group_selector) {
|
||||
return [1];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
handler.call(fake_this, event);
|
||||
handler.call($fake_this, event);
|
||||
assert.ok(!api_endpoint_called);
|
||||
}
|
||||
|
||||
api_endpoint_called = false;
|
||||
fake_this.closest = (class_name) => {
|
||||
$fake_this.closest = (class_name) => {
|
||||
if (class_name === ".typeahead") {
|
||||
return [1];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
handler.call(fake_this, event);
|
||||
handler.call($fake_this, event);
|
||||
assert.ok(!api_endpoint_called);
|
||||
|
||||
// Cancel button triggers blur event.
|
||||
@@ -671,7 +672,7 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
settings_user_groups_reload_called = true;
|
||||
});
|
||||
api_endpoint_called = false;
|
||||
fake_this.closest = (class_name) => {
|
||||
$fake_this.closest = (class_name) => {
|
||||
if (
|
||||
class_name === ".save-status.btn-danger" ||
|
||||
class_name === user_group_selector
|
||||
@@ -680,7 +681,7 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
}
|
||||
return [];
|
||||
};
|
||||
handler.call(fake_this, event);
|
||||
handler.call($fake_this, event);
|
||||
assert.ok(!api_endpoint_called);
|
||||
assert.ok(settings_user_groups_reload_called);
|
||||
}
|
||||
@@ -689,10 +690,10 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
(function test_update_cancel_button() {
|
||||
const handler_name = $(user_group_selector).get_on_handler("input", ".name");
|
||||
const handler_desc = $(user_group_selector).get_on_handler("input", ".description");
|
||||
const sib_des = $(description_selector);
|
||||
const sib_name = $(name_selector);
|
||||
sib_name.text($t({defaultMessage: "mobile"}));
|
||||
sib_des.text($t({defaultMessage: "All mobile members"}));
|
||||
const $sib_des = $(description_selector);
|
||||
const $sib_name = $(name_selector);
|
||||
$sib_name.text($t({defaultMessage: "mobile"}));
|
||||
$sib_des.text($t({defaultMessage: "All mobile members"}));
|
||||
|
||||
const group_data = {
|
||||
name: "translated: mobile",
|
||||
@@ -712,8 +713,8 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
};
|
||||
|
||||
// Cancel button removed if user group if user group has no changes.
|
||||
const fake_this = $.create("fake-#update_cancel_button");
|
||||
handler_name.call(fake_this);
|
||||
const $fake_this = $.create("fake-#update_cancel_button");
|
||||
handler_name.call($fake_this);
|
||||
assert.ok(cancel_fade_out_called);
|
||||
assert.ok(instructions_fade_out_called);
|
||||
|
||||
@@ -721,14 +722,14 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
$(user_group_selector + " .user-group-status").show();
|
||||
cancel_fade_out_called = false;
|
||||
instructions_fade_out_called = false;
|
||||
handler_name.call(fake_this);
|
||||
handler_name.call($fake_this);
|
||||
assert.ok(cancel_fade_out_called);
|
||||
assert.ok(instructions_fade_out_called);
|
||||
|
||||
// Check for handler_desc to achieve 100% coverage.
|
||||
cancel_fade_out_called = false;
|
||||
instructions_fade_out_called = false;
|
||||
handler_desc.call(fake_this);
|
||||
handler_desc.call($fake_this);
|
||||
assert.ok(cancel_fade_out_called);
|
||||
assert.ok(instructions_fade_out_called);
|
||||
})();
|
||||
@@ -736,10 +737,10 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
(function test_user_groups_save_group_changes_triggered() {
|
||||
const handler_name = $(user_group_selector).get_on_handler("blur", ".name");
|
||||
const handler_desc = $(user_group_selector).get_on_handler("blur", ".description");
|
||||
const sib_des = $(description_selector);
|
||||
const sib_name = $(name_selector);
|
||||
sib_name.text($t({defaultMessage: "mobile"}));
|
||||
sib_des.text($t({defaultMessage: "All mobile members"}));
|
||||
const $sib_des = $(description_selector);
|
||||
const $sib_name = $(name_selector);
|
||||
$sib_name.text($t({defaultMessage: "mobile"}));
|
||||
$sib_des.text($t({defaultMessage: "All mobile members"}));
|
||||
|
||||
const group_data = {members: new Set([2, 31])};
|
||||
user_groups.get_user_group_from_id = () => group_data;
|
||||
@@ -782,46 +783,47 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
assert.ok(saved_fade_to_called);
|
||||
})();
|
||||
(function test_post_error() {
|
||||
const user_group_error = $(user_group_selector + " .user-group-status");
|
||||
user_group_error.show();
|
||||
const $user_group_error = $(user_group_selector + " .user-group-status");
|
||||
$user_group_error.show();
|
||||
ui_report.error = (error_msg, error_obj, ele) => {
|
||||
const xhr = {
|
||||
responseText: '{"msg":"fake-msg"}',
|
||||
};
|
||||
assert.equal(error_msg, "translated HTML: Failed");
|
||||
assert.deepEqual(error_obj, xhr);
|
||||
assert.equal(ele, user_group_error);
|
||||
assert.equal(ele, $user_group_error);
|
||||
};
|
||||
const xhr = {
|
||||
responseText: '{"msg":"fake-msg", "attrib":"val"}',
|
||||
};
|
||||
opts.error(xhr);
|
||||
|
||||
assert.ok(user_group_error.visible());
|
||||
assert.ok($user_group_error.visible());
|
||||
})();
|
||||
};
|
||||
|
||||
const fake_this = $.create("fake-#user-groups_blur_name");
|
||||
fake_this.closest = () => [];
|
||||
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
|
||||
const $fake_this = $.create("fake-#user-groups_blur_name");
|
||||
$fake_this.closest = () => [];
|
||||
$fake_this.set_parents_result(user_group_selector, $(user_group_selector));
|
||||
const event = {
|
||||
relatedTarget: fake_this,
|
||||
// FIXME: event.relatedTarget should not be a jQuery object
|
||||
relatedTarget: $fake_this,
|
||||
};
|
||||
|
||||
api_endpoint_called = false;
|
||||
handler_name.call(fake_this, event);
|
||||
handler_name.call($fake_this, event);
|
||||
assert.ok(api_endpoint_called);
|
||||
|
||||
// Check API endpoint isn't called if name and desc haven't changed.
|
||||
group_data.name = "translated: mobile";
|
||||
group_data.description = "translated: All mobile members";
|
||||
api_endpoint_called = false;
|
||||
handler_name.call(fake_this, event);
|
||||
handler_name.call($fake_this, event);
|
||||
assert.ok(!api_endpoint_called);
|
||||
|
||||
// Check for handler_desc to achieve 100% coverage.
|
||||
api_endpoint_called = false;
|
||||
handler_desc.call(fake_this, event);
|
||||
handler_desc.call($fake_this, event);
|
||||
assert.ok(!api_endpoint_called);
|
||||
})();
|
||||
|
||||
@@ -869,15 +871,16 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
|
||||
})();
|
||||
};
|
||||
|
||||
const fake_this = $.create("fake-#user-groups_blur_input");
|
||||
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
|
||||
fake_this.closest = () => [];
|
||||
const $fake_this = $.create("fake-#user-groups_blur_input");
|
||||
$fake_this.set_parents_result(user_group_selector, $(user_group_selector));
|
||||
$fake_this.closest = () => [];
|
||||
const event = {
|
||||
relatedTarget: fake_this,
|
||||
// FIXME: event.relatedTarget should not be a jQuery object
|
||||
relatedTarget: $fake_this,
|
||||
};
|
||||
|
||||
api_endpoint_called = false;
|
||||
handler.call(fake_this, event);
|
||||
handler.call($fake_this, event);
|
||||
assert.ok(api_endpoint_called);
|
||||
})();
|
||||
});
|
||||
|
||||
@@ -11,30 +11,30 @@ const spoilers = zrequire("spoilers");
|
||||
// This function is taken from rendered_markdown.js and slightly modified.
|
||||
const $array = (array) => {
|
||||
const each = (func) => {
|
||||
for (const [index, elem] of array.entries()) {
|
||||
func.call(this, index, elem);
|
||||
for (const [index, $elem] of array.entries()) {
|
||||
func.call(this, index, $elem);
|
||||
}
|
||||
};
|
||||
return {each};
|
||||
};
|
||||
|
||||
const get_spoiler_elem = (title) => {
|
||||
const block = $.create(`block-${title}`);
|
||||
const header = $.create(`header-${title}`);
|
||||
const content = $.create(`content-${title}`);
|
||||
content.remove = () => {};
|
||||
header.text(title);
|
||||
block.set_find_results(".spoiler-header", header);
|
||||
block.set_find_results(".spoiler-content", content);
|
||||
return block;
|
||||
const $block = $.create(`block-${title}`);
|
||||
const $header = $.create(`header-${title}`);
|
||||
const $content = $.create(`content-${title}`);
|
||||
$content.remove = () => {};
|
||||
$header.text(title);
|
||||
$block.set_find_results(".spoiler-header", $header);
|
||||
$block.set_find_results(".spoiler-content", $content);
|
||||
return $block;
|
||||
};
|
||||
|
||||
run_test("hide spoilers in notifications", () => {
|
||||
const root = $.create("root element");
|
||||
const spoiler_1 = get_spoiler_elem("this is the title");
|
||||
const spoiler_2 = get_spoiler_elem("");
|
||||
root.set_find_results(".spoiler-block", $array([spoiler_1, spoiler_2]));
|
||||
spoilers.hide_spoilers_in_notification(root);
|
||||
assert.equal(spoiler_1.find(".spoiler-header").text(), "this is the title (…)");
|
||||
assert.equal(spoiler_2.find(".spoiler-header").text(), "(…)");
|
||||
const $root = $.create("root element");
|
||||
const $spoiler_1 = get_spoiler_elem("this is the title");
|
||||
const $spoiler_2 = get_spoiler_elem("");
|
||||
$root.set_find_results(".spoiler-block", $array([$spoiler_1, $spoiler_2]));
|
||||
spoilers.hide_spoilers_in_notification($root);
|
||||
assert.equal($spoiler_1.find(".spoiler-header").text(), "this is the title (…)");
|
||||
assert.equal($spoiler_2.find(".spoiler-header").text(), "(…)");
|
||||
});
|
||||
|
||||
@@ -136,32 +136,32 @@ test("update_property", ({override}) => {
|
||||
// Test desktop notifications
|
||||
stream_events.update_property(stream_id, "desktop_notifications", true);
|
||||
assert.equal(sub.desktop_notifications, true);
|
||||
let checkbox = checkbox_for("desktop_notifications");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
let $checkbox = checkbox_for("desktop_notifications");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
|
||||
// Tests audible notifications
|
||||
stream_events.update_property(stream_id, "audible_notifications", true);
|
||||
assert.equal(sub.audible_notifications, true);
|
||||
checkbox = checkbox_for("audible_notifications");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
$checkbox = checkbox_for("audible_notifications");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
|
||||
// Tests push notifications
|
||||
stream_events.update_property(stream_id, "push_notifications", true);
|
||||
assert.equal(sub.push_notifications, true);
|
||||
checkbox = checkbox_for("push_notifications");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
$checkbox = checkbox_for("push_notifications");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
|
||||
// Tests email notifications
|
||||
stream_events.update_property(stream_id, "email_notifications", true);
|
||||
assert.equal(sub.email_notifications, true);
|
||||
checkbox = checkbox_for("email_notifications");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
$checkbox = checkbox_for("email_notifications");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
|
||||
// Tests wildcard_mentions_notify notifications
|
||||
stream_events.update_property(stream_id, "wildcard_mentions_notify", true);
|
||||
assert.equal(sub.wildcard_mentions_notify, true);
|
||||
checkbox = checkbox_for("wildcard_mentions_notify");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
$checkbox = checkbox_for("wildcard_mentions_notify");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
|
||||
// Test name change
|
||||
{
|
||||
@@ -195,8 +195,8 @@ test("update_property", ({override}) => {
|
||||
{
|
||||
override(stream_list, "refresh_pinned_or_unpinned_stream", noop);
|
||||
stream_events.update_property(stream_id, "pin_to_top", true);
|
||||
checkbox = checkbox_for("pin_to_top");
|
||||
assert.equal(checkbox.prop("checked"), true);
|
||||
$checkbox = checkbox_for("pin_to_top");
|
||||
assert.equal($checkbox.prop("checked"), true);
|
||||
}
|
||||
|
||||
// Test stream privacy change event
|
||||
|
||||
@@ -19,7 +19,7 @@ const topic_list = mock_esm("../../static/js/topic_list");
|
||||
mock_esm("../../static/js/keydown_util", {
|
||||
handle: noop,
|
||||
});
|
||||
mock_esm("../../static/js/ui", {get_scroll_element: (element) => element});
|
||||
mock_esm("../../static/js/ui", {get_scroll_element: ($element) => $element});
|
||||
|
||||
const {Filter} = zrequire("../js/filter");
|
||||
const stream_sort = zrequire("stream_sort");
|
||||
@@ -47,13 +47,13 @@ const social = {
|
||||
let num_unread_for_stream;
|
||||
|
||||
function create_devel_sidebar_row({mock_template}) {
|
||||
const devel_count = $.create("devel-count");
|
||||
const subscription_block = $.create("devel-block");
|
||||
const $devel_count = $.create("devel-count");
|
||||
const $subscription_block = $.create("devel-block");
|
||||
|
||||
const sidebar_row = $("<devel sidebar row>");
|
||||
const $sidebar_row = $("<devel sidebar row>");
|
||||
|
||||
sidebar_row.set_find_results(".subscription_block", subscription_block);
|
||||
subscription_block.set_find_results(".unread_count", devel_count);
|
||||
$sidebar_row.set_find_results(".subscription_block", $subscription_block);
|
||||
$subscription_block.set_find_results(".unread_count", $devel_count);
|
||||
|
||||
mock_template("stream_sidebar_row.hbs", false, (data) => {
|
||||
assert.equal(data.uri, "#narrow/stream/100-devel");
|
||||
@@ -62,17 +62,17 @@ function create_devel_sidebar_row({mock_template}) {
|
||||
|
||||
num_unread_for_stream = 42;
|
||||
stream_list.create_sidebar_row(devel);
|
||||
assert.equal(devel_count.text(), "42");
|
||||
assert.equal($devel_count.text(), "42");
|
||||
}
|
||||
|
||||
function create_social_sidebar_row({mock_template}) {
|
||||
const social_count = $.create("social-count");
|
||||
const subscription_block = $.create("social-block");
|
||||
const $social_count = $.create("social-count");
|
||||
const $subscription_block = $.create("social-block");
|
||||
|
||||
const sidebar_row = $("<social sidebar row>");
|
||||
const $sidebar_row = $("<social sidebar row>");
|
||||
|
||||
sidebar_row.set_find_results(".subscription_block", subscription_block);
|
||||
subscription_block.set_find_results(".unread_count", social_count);
|
||||
$sidebar_row.set_find_results(".subscription_block", $subscription_block);
|
||||
$subscription_block.set_find_results(".unread_count", $social_count);
|
||||
|
||||
mock_template("stream_sidebar_row.hbs", false, (data) => {
|
||||
assert.equal(data.uri, "#narrow/stream/200-social");
|
||||
@@ -81,7 +81,7 @@ function create_social_sidebar_row({mock_template}) {
|
||||
|
||||
num_unread_for_stream = 99;
|
||||
stream_list.create_sidebar_row(social);
|
||||
assert.equal(social_count.text(), "99");
|
||||
assert.equal($social_count.text(), "99");
|
||||
}
|
||||
|
||||
function test_ui(label, f) {
|
||||
@@ -105,8 +105,8 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
|
||||
create_social_sidebar_row({mock_template});
|
||||
|
||||
const split = '<hr class="stream-split">';
|
||||
const devel_sidebar = $("<devel sidebar row>");
|
||||
const social_sidebar = $("<social sidebar row>");
|
||||
const $devel_sidebar = $("<devel sidebar row>");
|
||||
const $social_sidebar = $("<social sidebar row>");
|
||||
|
||||
let appended_elems;
|
||||
$("#stream_filters").append = (elems) => {
|
||||
@@ -123,20 +123,20 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
|
||||
assert.ok(topic_list_cleared);
|
||||
|
||||
const expected_elems = [
|
||||
devel_sidebar, // pinned
|
||||
$devel_sidebar, // pinned
|
||||
split, // separator
|
||||
social_sidebar, // not pinned
|
||||
$social_sidebar, // not pinned
|
||||
];
|
||||
|
||||
assert.deepEqual(appended_elems, expected_elems);
|
||||
|
||||
const social_li = $("<social sidebar row>");
|
||||
const $social_li = $("<social sidebar row>");
|
||||
const stream_id = social.stream_id;
|
||||
|
||||
social_li.length = 0;
|
||||
$social_li.length = 0;
|
||||
|
||||
const privacy_elem = $.create("privacy-stub");
|
||||
social_li.set_find_results(".stream-privacy", privacy_elem);
|
||||
const $privacy_elem = $.create("privacy-stub");
|
||||
$social_li.set_find_results(".stream-privacy", $privacy_elem);
|
||||
|
||||
social.invite_only = true;
|
||||
social.color = "#222222";
|
||||
@@ -147,25 +147,25 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
|
||||
return "<div>privacy-html";
|
||||
});
|
||||
stream_list.redraw_stream_privacy(social);
|
||||
assert.equal(privacy_elem.html(), "<div>privacy-html");
|
||||
assert.equal($privacy_elem.html(), "<div>privacy-html");
|
||||
|
||||
stream_list.set_in_home_view(stream_id, false);
|
||||
assert.ok(social_li.hasClass("out_of_home_view"));
|
||||
assert.ok($social_li.hasClass("out_of_home_view"));
|
||||
|
||||
stream_list.set_in_home_view(stream_id, true);
|
||||
assert.ok(!social_li.hasClass("out_of_home_view"));
|
||||
assert.ok(!$social_li.hasClass("out_of_home_view"));
|
||||
|
||||
const row = stream_list.stream_sidebar.get_row(stream_id);
|
||||
override_rewire(stream_data, "is_active", () => true);
|
||||
row.update_whether_active();
|
||||
assert.ok(!social_li.hasClass("inactive_stream"));
|
||||
assert.ok(!$social_li.hasClass("inactive_stream"));
|
||||
|
||||
override_rewire(stream_data, "is_active", () => false);
|
||||
row.update_whether_active();
|
||||
assert.ok(social_li.hasClass("inactive_stream"));
|
||||
assert.ok($social_li.hasClass("inactive_stream"));
|
||||
|
||||
let removed;
|
||||
social_li.remove = () => {
|
||||
$social_li.remove = () => {
|
||||
removed = true;
|
||||
};
|
||||
|
||||
@@ -183,33 +183,33 @@ test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
|
||||
create_social_sidebar_row({mock_template});
|
||||
|
||||
// non-pinned streams can be made inactive
|
||||
const social_sidebar = $("<social sidebar row>");
|
||||
const $social_sidebar = $("<social sidebar row>");
|
||||
let stream_id = social.stream_id;
|
||||
let row = stream_list.stream_sidebar.get_row(stream_id);
|
||||
override_rewire(stream_data, "is_active", () => false);
|
||||
|
||||
stream_list.build_stream_list();
|
||||
assert.ok(social_sidebar.hasClass("inactive_stream"));
|
||||
assert.ok($social_sidebar.hasClass("inactive_stream"));
|
||||
|
||||
override_rewire(stream_data, "is_active", () => true);
|
||||
row.update_whether_active();
|
||||
assert.ok(!social_sidebar.hasClass("inactive_stream"));
|
||||
assert.ok(!$social_sidebar.hasClass("inactive_stream"));
|
||||
|
||||
override_rewire(stream_data, "is_active", () => false);
|
||||
row.update_whether_active();
|
||||
assert.ok(social_sidebar.hasClass("inactive_stream"));
|
||||
assert.ok($social_sidebar.hasClass("inactive_stream"));
|
||||
|
||||
// pinned streams can never be made inactive
|
||||
const devel_sidebar = $("<devel sidebar row>");
|
||||
const $devel_sidebar = $("<devel sidebar row>");
|
||||
stream_id = devel.stream_id;
|
||||
row = stream_list.stream_sidebar.get_row(stream_id);
|
||||
override_rewire(stream_data, "is_active", () => false);
|
||||
|
||||
stream_list.build_stream_list();
|
||||
assert.ok(!devel_sidebar.hasClass("inactive_stream"));
|
||||
assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
|
||||
|
||||
row.update_whether_active();
|
||||
assert.ok(!devel_sidebar.hasClass("inactive_stream"));
|
||||
assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
|
||||
});
|
||||
|
||||
function add_row(sub) {
|
||||
@@ -218,11 +218,11 @@ function add_row(sub) {
|
||||
update_whether_active() {},
|
||||
get_li() {
|
||||
const html = "<" + sub.name + " sidebar row html>";
|
||||
const obj = $(html);
|
||||
const $obj = $(html);
|
||||
|
||||
obj.length = 1; // bypass blueslip error
|
||||
$obj.length = 1; // bypass blueslip error
|
||||
|
||||
return obj;
|
||||
return $obj;
|
||||
},
|
||||
};
|
||||
stream_list.stream_sidebar.set_row(sub.stream_id, row);
|
||||
@@ -293,30 +293,30 @@ function elem($obj) {
|
||||
}
|
||||
|
||||
test_ui("zoom_in_and_zoom_out", () => {
|
||||
const label1 = $.create("label1 stub");
|
||||
const label2 = $.create("label2 stub");
|
||||
const $label1 = $.create("label1 stub");
|
||||
const $label2 = $.create("label2 stub");
|
||||
|
||||
label1.show();
|
||||
label2.show();
|
||||
$label1.show();
|
||||
$label2.show();
|
||||
|
||||
assert.ok(label1.visible());
|
||||
assert.ok(label2.visible());
|
||||
assert.ok($label1.visible());
|
||||
assert.ok($label2.visible());
|
||||
|
||||
$.create(".stream-filters-label", {
|
||||
children: [elem(label1), elem(label2)],
|
||||
children: [elem($label1), elem($label2)],
|
||||
});
|
||||
|
||||
const splitter = $.create("hr stub");
|
||||
const $splitter = $.create("hr stub");
|
||||
|
||||
splitter.show();
|
||||
assert.ok(splitter.visible());
|
||||
$splitter.show();
|
||||
assert.ok($splitter.visible());
|
||||
|
||||
$.create(".stream-split", {
|
||||
children: [elem(splitter)],
|
||||
children: [elem($splitter)],
|
||||
});
|
||||
|
||||
const stream_li1 = $.create("stream1 stub");
|
||||
const stream_li2 = $.create("stream2 stub");
|
||||
const $stream_li1 = $.create("stream1 stub");
|
||||
const $stream_li2 = $.create("stream2 stub");
|
||||
|
||||
function make_attr(arg) {
|
||||
return (sel) => {
|
||||
@@ -325,12 +325,12 @@ test_ui("zoom_in_and_zoom_out", () => {
|
||||
};
|
||||
}
|
||||
|
||||
stream_li1.attr = make_attr("42");
|
||||
stream_li1.hide();
|
||||
stream_li2.attr = make_attr("99");
|
||||
$stream_li1.attr = make_attr("42");
|
||||
$stream_li1.hide();
|
||||
$stream_li2.attr = make_attr("99");
|
||||
|
||||
$.create("#stream_filters li.narrow-filter", {
|
||||
children: [elem(stream_li1), elem(stream_li2)],
|
||||
children: [elem($stream_li1), elem($stream_li2)],
|
||||
});
|
||||
|
||||
$("#stream-filters-container")[0] = {
|
||||
@@ -340,26 +340,26 @@ test_ui("zoom_in_and_zoom_out", () => {
|
||||
|
||||
stream_list.zoom_in_topics({stream_id: 42});
|
||||
|
||||
assert.ok(!label1.visible());
|
||||
assert.ok(!label2.visible());
|
||||
assert.ok(!splitter.visible());
|
||||
assert.ok(stream_li1.visible());
|
||||
assert.ok(!stream_li2.visible());
|
||||
assert.ok(!$label1.visible());
|
||||
assert.ok(!$label2.visible());
|
||||
assert.ok(!$splitter.visible());
|
||||
assert.ok($stream_li1.visible());
|
||||
assert.ok(!$stream_li2.visible());
|
||||
assert.ok($("#streams_list").hasClass("zoom-in"));
|
||||
|
||||
$("#stream_filters li.narrow-filter").show = () => {
|
||||
stream_li1.show();
|
||||
stream_li2.show();
|
||||
$stream_li1.show();
|
||||
$stream_li2.show();
|
||||
};
|
||||
|
||||
stream_li1.length = 1;
|
||||
stream_list.zoom_out_topics({stream_li: stream_li1});
|
||||
$stream_li1.length = 1;
|
||||
stream_list.zoom_out_topics({$stream_li: $stream_li1});
|
||||
|
||||
assert.ok(label1.visible());
|
||||
assert.ok(label2.visible());
|
||||
assert.ok(splitter.visible());
|
||||
assert.ok(stream_li1.visible());
|
||||
assert.ok(stream_li2.visible());
|
||||
assert.ok($label1.visible());
|
||||
assert.ok($label2.visible());
|
||||
assert.ok($splitter.visible());
|
||||
assert.ok($stream_li1.visible());
|
||||
assert.ok($stream_li2.visible());
|
||||
assert.ok($("#streams_list").hasClass("zoom-out"));
|
||||
});
|
||||
|
||||
@@ -591,8 +591,8 @@ test_ui("rename_stream", ({override_rewire, mock_template}) => {
|
||||
|
||||
stream_data.rename_sub(sub, new_name);
|
||||
|
||||
const li_stub = $.create("li stub");
|
||||
li_stub.length = 0;
|
||||
const $li_stub = $.create("li stub");
|
||||
$li_stub.length = 0;
|
||||
|
||||
mock_template("stream_sidebar_row.hbs", false, (payload) => {
|
||||
assert.deepEqual(payload, {
|
||||
@@ -606,12 +606,12 @@ test_ui("rename_stream", ({override_rewire, mock_template}) => {
|
||||
pin_to_top: true,
|
||||
dark_background: payload.dark_background,
|
||||
});
|
||||
return {to_$: () => li_stub};
|
||||
return {to_$: () => $li_stub};
|
||||
});
|
||||
|
||||
let count_updated;
|
||||
override_rewire(stream_list, "update_count_in_dom", (li) => {
|
||||
assert.equal(li, li_stub);
|
||||
override_rewire(stream_list, "update_count_in_dom", ($li) => {
|
||||
assert.equal($li, $li_stub);
|
||||
count_updated = true;
|
||||
});
|
||||
|
||||
@@ -638,17 +638,17 @@ test_ui("refresh_pin", ({override_rewire, mock_template}) => {
|
||||
pin_to_top: true,
|
||||
};
|
||||
|
||||
const li_stub = $.create("li stub");
|
||||
li_stub.length = 0;
|
||||
const $li_stub = $.create("li stub");
|
||||
$li_stub.length = 0;
|
||||
|
||||
mock_template("stream_sidebar_row.hbs", false, () => ({to_$: () => li_stub}));
|
||||
mock_template("stream_sidebar_row.hbs", false, () => ({to_$: () => $li_stub}));
|
||||
|
||||
override_rewire(stream_list, "update_count_in_dom", noop);
|
||||
$("#stream_filters").append = noop;
|
||||
|
||||
let scrolled;
|
||||
override_rewire(stream_list, "scroll_stream_into_view", (li) => {
|
||||
assert.equal(li, li_stub);
|
||||
override_rewire(stream_list, "scroll_stream_into_view", ($li) => {
|
||||
assert.equal($li, $li_stub);
|
||||
scrolled = true;
|
||||
});
|
||||
|
||||
|
||||
@@ -64,32 +64,32 @@ function clear_search_input() {
|
||||
|
||||
run_test("basics", ({override_rewire}) => {
|
||||
let cursor_helper;
|
||||
const input = $(".stream-list-filter");
|
||||
const section = $(".stream_search_section");
|
||||
const $input = $(".stream-list-filter");
|
||||
const $section = $(".stream_search_section");
|
||||
|
||||
expand_sidebar();
|
||||
section.addClass("notdisplayed");
|
||||
$section.addClass("notdisplayed");
|
||||
|
||||
cursor_helper = make_cursor_helper();
|
||||
|
||||
function verify_expanded() {
|
||||
assert.ok(!section.hasClass("notdisplayed"));
|
||||
assert.ok(!$section.hasClass("notdisplayed"));
|
||||
simulate_search_expanded();
|
||||
}
|
||||
|
||||
function verify_focused() {
|
||||
assert.ok(stream_list.searching());
|
||||
assert.ok(input.is_focused());
|
||||
assert.ok($input.is_focused());
|
||||
}
|
||||
|
||||
function verify_blurred() {
|
||||
assert.ok(stream_list.searching());
|
||||
assert.ok(input.is_focused());
|
||||
assert.ok($input.is_focused());
|
||||
}
|
||||
|
||||
function verify_collapsed() {
|
||||
assert.ok(section.hasClass("notdisplayed"));
|
||||
assert.ok(!input.is_focused());
|
||||
assert.ok($section.hasClass("notdisplayed"));
|
||||
assert.ok(!$input.is_focused());
|
||||
assert.ok(!stream_list.searching());
|
||||
simulate_search_collapsed();
|
||||
}
|
||||
@@ -126,7 +126,7 @@ run_test("basics", ({override_rewire}) => {
|
||||
|
||||
(function add_some_text_and_collapse() {
|
||||
cursor_helper = make_cursor_helper();
|
||||
input.val("foo");
|
||||
$input.val("foo");
|
||||
verify_list_updated(() => {
|
||||
toggle_filter();
|
||||
});
|
||||
@@ -149,7 +149,7 @@ run_test("basics", ({override_rewire}) => {
|
||||
stream_list.initiate_search();
|
||||
|
||||
// Clear a non-empty search.
|
||||
input.val("foo");
|
||||
$input.val("foo");
|
||||
verify_list_updated(() => {
|
||||
clear_search_input();
|
||||
});
|
||||
@@ -160,7 +160,7 @@ run_test("basics", ({override_rewire}) => {
|
||||
stream_list.initiate_search();
|
||||
|
||||
// Escape a non-empty search.
|
||||
input.val("foo");
|
||||
$input.val("foo");
|
||||
stream_list.escape_search();
|
||||
verify_blurred();
|
||||
|
||||
@@ -169,7 +169,7 @@ run_test("basics", ({override_rewire}) => {
|
||||
stream_list.initiate_search();
|
||||
|
||||
// Escape an empty search.
|
||||
input.val("");
|
||||
$input.val("");
|
||||
stream_list.escape_search();
|
||||
verify_collapsed();
|
||||
});
|
||||
|
||||
@@ -9,8 +9,8 @@ const $ = require("../zjsunit/zjquery");
|
||||
const denmark_stream_id = 101;
|
||||
|
||||
const ui = mock_esm("../../static/js/ui", {
|
||||
get_content_element: (element) => element,
|
||||
get_scroll_element: (element) => element,
|
||||
get_content_element: ($element) => $element,
|
||||
get_scroll_element: ($element) => $element,
|
||||
});
|
||||
|
||||
mock_esm("../../static/js/hash_util", {
|
||||
@@ -103,16 +103,16 @@ run_test("redraw_left_panel", ({mock_template}) => {
|
||||
$.create("#manage_streams_container .stream-row", {children: sub_stubs});
|
||||
|
||||
let ui_called = false;
|
||||
ui.reset_scrollbar = (elem) => {
|
||||
ui.reset_scrollbar = ($elem) => {
|
||||
ui_called = true;
|
||||
assert.equal(elem, $("#subscription_overlay .streams-list"));
|
||||
assert.equal($elem, $("#subscription_overlay .streams-list"));
|
||||
};
|
||||
|
||||
// Filtering has the side effect of setting the "active" class
|
||||
// on our current stream, even if it doesn't match the filter.
|
||||
const denmark_row = $(`.stream-row[data-stream-id='${CSS.escape(denmark_stream_id)}']`);
|
||||
const $denmark_row = $(`.stream-row[data-stream-id='${CSS.escape(denmark_stream_id)}']`);
|
||||
// sanity check it's not set to active
|
||||
assert.ok(!denmark_row.hasClass("active"));
|
||||
assert.ok(!$denmark_row.hasClass("active"));
|
||||
|
||||
function test_filter(params, expected_streams) {
|
||||
const stream_ids = stream_settings_ui.redraw_left_panel(params);
|
||||
@@ -127,7 +127,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
|
||||
assert.ok(ui_called);
|
||||
|
||||
// The denmark row is active, even though it's not displayed.
|
||||
assert.ok(denmark_row.hasClass("active"));
|
||||
assert.ok($denmark_row.hasClass("active"));
|
||||
|
||||
// Search with multiple keywords
|
||||
test_filter({input: "Denmark, Pol", subscribed_only: false}, [denmark, poland]);
|
||||
|
||||
@@ -19,14 +19,14 @@ run_test("scrub_realm", () => {
|
||||
$.get_initialize_function()();
|
||||
const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
|
||||
|
||||
const fake_this = $.create("fake-.scrub-realm-button");
|
||||
fake_this.data = (name) => {
|
||||
const $fake_this = $.create("fake-.scrub-realm-button");
|
||||
$fake_this.data = (name) => {
|
||||
assert.equal(name, "string-id");
|
||||
return "zulip";
|
||||
};
|
||||
|
||||
let submit_form_called = false;
|
||||
fake_this.form = {
|
||||
$fake_this.form = {
|
||||
submit: () => {
|
||||
submit_form_called = true;
|
||||
},
|
||||
@@ -36,7 +36,7 @@ run_test("scrub_realm", () => {
|
||||
};
|
||||
|
||||
window.prompt = () => "zulip";
|
||||
click_handler.call(fake_this, event);
|
||||
click_handler.call($fake_this, event);
|
||||
assert.ok(submit_form_called);
|
||||
|
||||
submit_form_called = false;
|
||||
@@ -45,7 +45,7 @@ run_test("scrub_realm", () => {
|
||||
window.alert = () => {
|
||||
alert_called = true;
|
||||
};
|
||||
click_handler.call(fake_this, event);
|
||||
click_handler.call($fake_this, event);
|
||||
assert.ok(!submit_form_called);
|
||||
assert.ok(alert_called);
|
||||
|
||||
|
||||
@@ -210,20 +210,20 @@ run_test("render_date_renders_time_html", () => {
|
||||
const expected_html = $t({defaultMessage: "Today"});
|
||||
|
||||
const attrs = {};
|
||||
const span_stub = $("<span />");
|
||||
const $span_stub = $("<span />");
|
||||
|
||||
span_stub.attr = (name, val) => {
|
||||
$span_stub.attr = (name, val) => {
|
||||
attrs[name] = val;
|
||||
return span_stub;
|
||||
return $span_stub;
|
||||
};
|
||||
|
||||
span_stub.append = (str) => {
|
||||
span_stub.html(str);
|
||||
return span_stub;
|
||||
$span_stub.append = (str) => {
|
||||
$span_stub.html(str);
|
||||
return $span_stub;
|
||||
};
|
||||
|
||||
const actual = timerender.render_date(message_time, undefined, today);
|
||||
assert.equal(actual.html(), expected_html);
|
||||
const $actual = timerender.render_date(message_time, undefined, today);
|
||||
assert.equal($actual.html(), expected_html);
|
||||
assert.equal(attrs["data-tippy-content"], "Friday, April 12, 2019");
|
||||
assert.equal(attrs.class, "timerender0");
|
||||
});
|
||||
@@ -234,12 +234,12 @@ run_test("render_date_renders_time_above_html", () => {
|
||||
const message_time = today;
|
||||
const message_time_above = add(today, {days: -1});
|
||||
|
||||
const span_stub = $("<span />");
|
||||
const $span_stub = $("<span />");
|
||||
|
||||
let appended_val;
|
||||
span_stub.append = (...val) => {
|
||||
$span_stub.append = (...val) => {
|
||||
appended_val = val;
|
||||
return span_stub;
|
||||
return $span_stub;
|
||||
};
|
||||
|
||||
const expected = [
|
||||
|
||||
@@ -104,12 +104,12 @@ run_test("narrowing", ({override_rewire}) => {
|
||||
});
|
||||
|
||||
run_test("update_count_in_dom", () => {
|
||||
function make_elem(elem, count_selector) {
|
||||
const count = $(count_selector);
|
||||
elem.set_find_results(".unread_count", count);
|
||||
count.set_parent(elem);
|
||||
function make_elem($elem, count_selector) {
|
||||
const $count = $(count_selector);
|
||||
$elem.set_find_results(".unread_count", $count);
|
||||
$count.set_parent($elem);
|
||||
|
||||
return elem;
|
||||
return $elem;
|
||||
}
|
||||
|
||||
const counts = {
|
||||
|
||||
@@ -39,7 +39,7 @@ people.add_active_user(levin);
|
||||
people.add_active_user(kitty);
|
||||
|
||||
run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) => {
|
||||
const typing_notifications = $("#typing_notifications");
|
||||
const $typing_notifications = $("#typing_notifications");
|
||||
|
||||
const two_typing_users_ids = [anna.user_id, vronsky.user_id];
|
||||
const three_typing_users_ids = [anna.user_id, vronsky.user_id, levin.user_id];
|
||||
@@ -51,32 +51,32 @@ run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) =
|
||||
// should be rendered but not 'Several people are typing…'
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => two_typing_users_ids);
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(typing_notifications.visible());
|
||||
assert.ok(typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok($typing_notifications.visible());
|
||||
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
|
||||
|
||||
// Having 3(=MAX_USERS_TO_DISPLAY_NAME) typists should also display only names
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => three_typing_users_ids);
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(typing_notifications.visible());
|
||||
assert.ok(typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok($typing_notifications.visible());
|
||||
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
|
||||
|
||||
// Having 4(>MAX_USERS_TO_DISPLAY_NAME) typists should display "Several people are typing…"
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => four_typing_users_ids);
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(typing_notifications.visible());
|
||||
assert.ok(typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok(!typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!typing_notifications.html().includes(`${kitty.full_name} is typing…`));
|
||||
assert.ok($typing_notifications.visible());
|
||||
assert.ok($typing_notifications.html().includes("Several people are typing…"));
|
||||
assert.ok(!$typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
||||
assert.ok(!$typing_notifications.html().includes(`${kitty.full_name} is typing…`));
|
||||
|
||||
// #typing_notifications should be hidden when there are no typists.
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => []);
|
||||
typing_events.render_notifications_for_narrow();
|
||||
assert.ok(!typing_notifications.visible());
|
||||
assert.ok(!$typing_notifications.visible());
|
||||
});
|
||||
|
||||
@@ -36,14 +36,14 @@ function test(label, f) {
|
||||
}
|
||||
|
||||
test("feature_check", ({override}) => {
|
||||
const upload_button = $.create("upload-button-stub");
|
||||
upload_button.addClass("notdisplayed");
|
||||
upload.feature_check(upload_button);
|
||||
assert.ok(upload_button.hasClass("notdisplayed"));
|
||||
const $upload_button = $.create("upload-button-stub");
|
||||
$upload_button.addClass("notdisplayed");
|
||||
upload.feature_check($upload_button);
|
||||
assert.ok($upload_button.hasClass("notdisplayed"));
|
||||
|
||||
override(window, "XMLHttpRequest", () => ({upload: true}));
|
||||
upload.feature_check(upload_button);
|
||||
assert.ok(!upload_button.hasClass("notdisplayed"));
|
||||
upload.feature_check($upload_button);
|
||||
assert.ok(!$upload_button.hasClass("notdisplayed"));
|
||||
});
|
||||
|
||||
test("get_item", () => {
|
||||
|
||||
@@ -194,7 +194,7 @@ test("filter_user_ids", ({override}) => {
|
||||
});
|
||||
|
||||
test("click on user header to toggle display", ({override}) => {
|
||||
const user_filter = $(".user-list-filter");
|
||||
const $user_filter = $(".user-list-filter");
|
||||
|
||||
override(popovers, "hide_all", () => {});
|
||||
override(popovers, "hide_all_except_sidebars", () => {});
|
||||
@@ -205,11 +205,11 @@ test("click on user header to toggle display", ({override}) => {
|
||||
|
||||
assert.ok(!$("#user_search_section").hasClass("notdisplayed"));
|
||||
|
||||
user_filter.val("bla");
|
||||
$user_filter.val("bla");
|
||||
|
||||
$("#userlist-header").trigger("click");
|
||||
assert.ok($("#user_search_section").hasClass("notdisplayed"));
|
||||
assert.equal(user_filter.val(), "");
|
||||
assert.equal($user_filter.val(), "");
|
||||
|
||||
$(".user-list-filter").closest = (selector) => {
|
||||
assert.equal(selector, ".app-main [class^='column-']");
|
||||
|
||||
@@ -35,16 +35,16 @@ const sample_events = [
|
||||
];
|
||||
|
||||
let events;
|
||||
let widget_elem;
|
||||
let $widget_elem;
|
||||
let is_event_handled;
|
||||
let is_widget_activated;
|
||||
|
||||
const fake_poll_widget = {
|
||||
activate(data) {
|
||||
is_widget_activated = true;
|
||||
widget_elem = data.elem;
|
||||
assert.ok(widget_elem.hasClass("widget-content"));
|
||||
widget_elem.handle_events = (e) => {
|
||||
$widget_elem = data.$elem;
|
||||
assert.ok($widget_elem.hasClass("widget-content"));
|
||||
$widget_elem.handle_events = (e) => {
|
||||
is_event_handled = true;
|
||||
assert.notDeepStrictEqual(e, events);
|
||||
events.shift();
|
||||
@@ -65,7 +65,7 @@ const widgetize = zrequire("widgetize");
|
||||
function test(label, f) {
|
||||
run_test(label, ({override}) => {
|
||||
events = [...sample_events];
|
||||
widget_elem = undefined;
|
||||
$widget_elem = undefined;
|
||||
is_event_handled = false;
|
||||
is_widget_activated = false;
|
||||
widgetize.clear_for_testing();
|
||||
@@ -76,10 +76,10 @@ function test(label, f) {
|
||||
test("activate", ({override}) => {
|
||||
// Both widgetize.activate and widgetize.handle_event are tested
|
||||
// here to use the "caching" of widgets
|
||||
const row = $.create("<stub message row>");
|
||||
row.attr("id", "zhome2909");
|
||||
const message_content = $.create("#zhome2909");
|
||||
row.set_find_results(".message_content", message_content);
|
||||
const $row = $.create("<stub message row>");
|
||||
$row.attr("id", "zhome2909");
|
||||
const $message_content = $.create("#zhome2909");
|
||||
$row.set_find_results(".message_content", $message_content);
|
||||
|
||||
let narrow_active;
|
||||
override(narrow_state, "active", () => narrow_active);
|
||||
@@ -94,16 +94,16 @@ test("activate", ({override}) => {
|
||||
assert.equal(data.msg_type, "widget");
|
||||
assert.equal(data.data, "test_data");
|
||||
},
|
||||
row,
|
||||
$row,
|
||||
widget_type: "poll",
|
||||
};
|
||||
|
||||
let is_widget_elem_inserted;
|
||||
|
||||
message_content.append = (elem) => {
|
||||
$message_content.append = ($elem) => {
|
||||
is_widget_elem_inserted = true;
|
||||
assert.equal(elem, widget_elem);
|
||||
assert.ok(elem.hasClass("widget-content"));
|
||||
assert.equal($elem, $widget_elem);
|
||||
assert.ok($elem.hasClass("widget-content"));
|
||||
};
|
||||
|
||||
is_widget_elem_inserted = false;
|
||||
@@ -111,19 +111,19 @@ test("activate", ({override}) => {
|
||||
is_event_handled = false;
|
||||
assert.ok(!widgetize.widget_contents.has(opts.message.id));
|
||||
|
||||
message_content.set_find_results(".widget-content", false);
|
||||
$message_content.set_find_results(".widget-content", false);
|
||||
widgetize.activate(opts);
|
||||
|
||||
assert.ok(is_widget_elem_inserted);
|
||||
assert.ok(is_widget_activated);
|
||||
assert.ok(is_event_handled);
|
||||
assert.equal(widgetize.widget_contents.get(opts.message.id), widget_elem);
|
||||
assert.equal(widgetize.widget_contents.get(opts.message.id), $widget_elem);
|
||||
|
||||
is_widget_elem_inserted = false;
|
||||
is_widget_activated = false;
|
||||
is_event_handled = false;
|
||||
|
||||
message_content.set_find_results(".widget-content", false);
|
||||
$message_content.set_find_results(".widget-content", false);
|
||||
widgetize.activate(opts);
|
||||
|
||||
assert.ok(is_widget_elem_inserted);
|
||||
@@ -135,7 +135,7 @@ test("activate", ({override}) => {
|
||||
is_widget_activated = false;
|
||||
is_event_handled = false;
|
||||
|
||||
message_content.set_find_results(".widget-content", false);
|
||||
$message_content.set_find_results(".widget-content", false);
|
||||
widgetize.activate(opts);
|
||||
|
||||
assert.ok(!is_widget_elem_inserted);
|
||||
@@ -171,7 +171,7 @@ test("activate", ({override}) => {
|
||||
message_id: 2001,
|
||||
sender_id: 102,
|
||||
};
|
||||
widget_elem.handle_events = (e) => {
|
||||
$widget_elem.handle_events = (e) => {
|
||||
is_event_handled = true;
|
||||
assert.deepEqual(e, [post_activate_event]);
|
||||
};
|
||||
@@ -191,7 +191,7 @@ test("activate", ({override}) => {
|
||||
});
|
||||
override(message_lists.current, "get_row", (idx) => {
|
||||
assert.equal(idx, 2001);
|
||||
return row;
|
||||
return $row;
|
||||
});
|
||||
widgetize.set_widgets_for_list();
|
||||
});
|
||||
|
||||
@@ -45,28 +45,28 @@ run_test("basics", () => {
|
||||
|
||||
// Next, look at how several functions correctly simulate setting
|
||||
// and getting for you.
|
||||
const widget = $("#my-widget");
|
||||
const $widget = $("#my-widget");
|
||||
|
||||
widget.attr("data-employee-id", 42);
|
||||
assert.equal(widget.attr("data-employee-id"), 42);
|
||||
assert.equal(widget.data("employee-id"), 42);
|
||||
$widget.attr("data-employee-id", 42);
|
||||
assert.equal($widget.attr("data-employee-id"), 42);
|
||||
assert.equal($widget.data("employee-id"), 42);
|
||||
|
||||
widget.data("department-id", 77);
|
||||
assert.equal(widget.attr("data-department-id"), 77);
|
||||
assert.equal(widget.data("department-id"), 77);
|
||||
$widget.data("department-id", 77);
|
||||
assert.equal($widget.attr("data-department-id"), 77);
|
||||
assert.equal($widget.data("department-id"), 77);
|
||||
|
||||
widget.data("department-name", "hr");
|
||||
assert.equal(widget.attr("data-department-name"), "hr");
|
||||
assert.equal(widget.data("department-name"), "hr");
|
||||
$widget.data("department-name", "hr");
|
||||
assert.equal($widget.attr("data-department-name"), "hr");
|
||||
assert.equal($widget.data("department-name"), "hr");
|
||||
|
||||
widget.html("<b>hello</b>");
|
||||
assert.equal(widget.html(), "<b>hello</b>");
|
||||
$widget.html("<b>hello</b>");
|
||||
assert.equal($widget.html(), "<b>hello</b>");
|
||||
|
||||
widget.prop("title", "My widget");
|
||||
assert.equal(widget.prop("title"), "My widget");
|
||||
$widget.prop("title", "My widget");
|
||||
assert.equal($widget.prop("title"), "My widget");
|
||||
|
||||
widget.val("42");
|
||||
assert.equal(widget.val(), "42");
|
||||
$widget.val("42");
|
||||
assert.equal($widget.val(), "42");
|
||||
});
|
||||
|
||||
run_test("finding_related_objects", () => {
|
||||
@@ -84,17 +84,17 @@ run_test("finding_related_objects", () => {
|
||||
// But you can set up your tests to simulate DOM relationships.
|
||||
//
|
||||
// We will use set_find_results(), which is a special zjquery helper.
|
||||
const emoji = $('<div class="emoji">');
|
||||
$("#my-message").set_find_results(".emoji", emoji);
|
||||
const $emoji = $('<div class="emoji">');
|
||||
$("#my-message").set_find_results(".emoji", $emoji);
|
||||
|
||||
// And then calling the function produces the desired effect:
|
||||
update_message_emoji("foo.png");
|
||||
assert.equal(emoji.attr("src"), "foo.png");
|
||||
assert.equal($emoji.attr("src"), "foo.png");
|
||||
|
||||
// Sometimes you want to deliberately test paths that do not find an
|
||||
// element. You can pass 'false' as the result for those cases.
|
||||
emoji.set_find_results(".random", false);
|
||||
assert.equal(emoji.find(".random").length, 0);
|
||||
$emoji.set_find_results(".random", false);
|
||||
assert.equal($emoji.find(".random").length, 0);
|
||||
/*
|
||||
An important thing to understand is that zjquery doesn't truly
|
||||
simulate DOM. The way you make relationships work in zjquery
|
||||
@@ -103,12 +103,12 @@ run_test("finding_related_objects", () => {
|
||||
Here is another example.
|
||||
*/
|
||||
|
||||
const my_parents = $("#folder1,#folder4");
|
||||
const elem = $("#folder555");
|
||||
const $my_parents = $("#folder1,#folder4");
|
||||
const $elem = $("#folder555");
|
||||
|
||||
elem.set_parents_result(".folder", my_parents);
|
||||
elem.parents(".folder").addClass("active");
|
||||
assert.ok(my_parents.hasClass("active"));
|
||||
$elem.set_parents_result(".folder", $my_parents);
|
||||
$elem.parents(".folder").addClass("active");
|
||||
assert.ok($my_parents.hasClass("active"));
|
||||
});
|
||||
|
||||
run_test("clicks", () => {
|
||||
@@ -188,12 +188,12 @@ run_test("create", () => {
|
||||
// You can create jQuery objects that aren't tied to any particular
|
||||
// selector, and which just have a name.
|
||||
|
||||
const obj1 = $.create("the table holding employees");
|
||||
const obj2 = $.create("the collection of rows in the table");
|
||||
const $obj1 = $.create("the table holding employees");
|
||||
const $obj2 = $.create("the collection of rows in the table");
|
||||
|
||||
obj1.show();
|
||||
assert.ok(obj1.visible());
|
||||
$obj1.show();
|
||||
assert.ok($obj1.visible());
|
||||
|
||||
obj2.addClass(".striped");
|
||||
assert.ok(obj2.hasClass(".striped"));
|
||||
$obj2.addClass(".striped");
|
||||
assert.ok($obj2.hasClass(".striped"));
|
||||
});
|
||||
|
||||
@@ -331,8 +331,8 @@ class CommonUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
const row = zulip_test.last_visible_row();
|
||||
if (zulip_test.row_id(row) !== last_msg.id) {
|
||||
const $row = zulip_test.last_visible_row();
|
||||
if (zulip_test.row_id($row) !== last_msg.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ class CommonUtils {
|
||||
don't add the star icon until the server
|
||||
responds.
|
||||
*/
|
||||
return row.find(".star").length === 1;
|
||||
return $row.find(".star").length === 1;
|
||||
},
|
||||
{},
|
||||
content,
|
||||
|
||||
@@ -31,8 +31,8 @@ async function copy_messages(
|
||||
$("body").trigger(new $.Event("keydown", {which: 67, ctrlKey: true}));
|
||||
|
||||
// find temp div with copied text
|
||||
const temp_div = $("#copytempdiv");
|
||||
return temp_div
|
||||
const $temp_div = $("#copytempdiv");
|
||||
return $temp_div
|
||||
.children("p")
|
||||
.get()
|
||||
.map((p) => p.textContent!);
|
||||
|
||||
@@ -4,10 +4,10 @@ import common from "../puppeteer_lib/common";
|
||||
|
||||
async function click_delete_and_return_last_msg_id(page: Page): Promise<string | undefined> {
|
||||
return await page.evaluate(() => {
|
||||
const msg = $("#zhome .message_row").last();
|
||||
msg.find(".message_control_button.actions_hover").trigger("click");
|
||||
const $msg = $("#zhome .message_row").last();
|
||||
$msg.find(".message_control_button.actions_hover").trigger("click");
|
||||
$(".delete_message").trigger("click");
|
||||
return msg.attr("id");
|
||||
return $msg.attr("id");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import common from "../puppeteer_lib/common";
|
||||
|
||||
async function trigger_edit_last_message(page: Page): Promise<void> {
|
||||
await page.evaluate(() => {
|
||||
const msg = $("#zhome .message_row").last();
|
||||
msg.find(".message_control_button.actions_hover").trigger("click");
|
||||
const $msg = $("#zhome .message_row").last();
|
||||
$msg.find(".message_control_button.actions_hover").trigger("click");
|
||||
$(".popover_edit_message").trigger("click");
|
||||
});
|
||||
await page.waitForSelector(".message_edit_content", {visible: true});
|
||||
|
||||
@@ -12,17 +12,17 @@ async function stars_count(page: Page): Promise<number> {
|
||||
|
||||
async function toggle_test_star_message(page: Page): Promise<void> {
|
||||
await page.evaluate((message: string) => {
|
||||
const msg = $(`.message_content:contains("${CSS.escape(message)}"):visible`).last();
|
||||
if (msg.length !== 1) {
|
||||
const $msg = $(`.message_content:contains("${CSS.escape(message)}"):visible`).last();
|
||||
if ($msg.length !== 1) {
|
||||
throw new Error("cannot find test star message");
|
||||
}
|
||||
|
||||
const star_icon = msg.closest(".messagebox").find(".star");
|
||||
if (star_icon.length !== 1) {
|
||||
const $star_icon = $msg.closest(".messagebox").find(".star");
|
||||
if ($star_icon.length !== 1) {
|
||||
throw new Error("cannot find star icon");
|
||||
}
|
||||
|
||||
star_icon.trigger("click");
|
||||
$star_icon.trigger("click");
|
||||
}, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ exports.mock_cjs = (module_path, obj) => {
|
||||
};
|
||||
|
||||
exports.mock_jquery = ($) => {
|
||||
jquery_function = $;
|
||||
jquery_function = $; // eslint-disable-line no-jquery/variable-pattern
|
||||
return $;
|
||||
};
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ function make_zjquery() {
|
||||
const fn = {};
|
||||
|
||||
function new_elem(selector, create_opts) {
|
||||
const elem = FakeElement(selector, {...create_opts});
|
||||
Object.assign(elem, fn);
|
||||
const $elem = FakeElement(selector, {...create_opts});
|
||||
Object.assign($elem, fn);
|
||||
|
||||
// Create a proxy handler to detect missing stubs.
|
||||
//
|
||||
@@ -76,7 +76,7 @@ function make_zjquery() {
|
||||
},
|
||||
};
|
||||
|
||||
const proxy = new Proxy(elem, handler);
|
||||
const proxy = new Proxy($elem, handler);
|
||||
|
||||
return proxy;
|
||||
}
|
||||
@@ -130,8 +130,8 @@ function make_zjquery() {
|
||||
verify_selector_for_zulip(selector);
|
||||
|
||||
if (!elems.has(selector)) {
|
||||
const elem = new_elem(selector);
|
||||
elems.set(selector, elem);
|
||||
const $elem = new_elem(selector);
|
||||
elems.set(selector, $elem);
|
||||
}
|
||||
return elems.get(selector);
|
||||
};
|
||||
@@ -146,10 +146,10 @@ function make_zjquery() {
|
||||
|
||||
zjquery.create = function (name, opts) {
|
||||
assert.ok(!elems.has(name), "You already created an object with this name!!");
|
||||
const elem = new_elem(name, opts);
|
||||
elems.set(name, elem);
|
||||
const $elem = new_elem(name, opts);
|
||||
elems.set(name, $elem);
|
||||
|
||||
return elem;
|
||||
return $elem;
|
||||
};
|
||||
|
||||
zjquery.trim = function (s) {
|
||||
@@ -250,4 +250,4 @@ const $ = new Proxy(make_zjquery(), {
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = $;
|
||||
module.exports = $; // eslint-disable-line no-jquery/variable-pattern
|
||||
|
||||
@@ -15,38 +15,38 @@ function FakeElement(selector, opts) {
|
||||
let height;
|
||||
|
||||
const find_results = new Map();
|
||||
let my_parent;
|
||||
let $my_parent;
|
||||
const parents_result = new Map();
|
||||
const properties = new Map();
|
||||
const attrs = new Map();
|
||||
const classes = new Map();
|
||||
const event_store = make_event_store(selector);
|
||||
|
||||
const self = {
|
||||
const $self = {
|
||||
addClass(class_name) {
|
||||
classes.set(class_name, true);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
append(arg) {
|
||||
html = html + arg;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
attr(name, val) {
|
||||
if (val === undefined) {
|
||||
return attrs.get(name);
|
||||
}
|
||||
attrs.set(name, val);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
data(name, val) {
|
||||
if (val === undefined) {
|
||||
return attrs.get("data-" + name);
|
||||
}
|
||||
attrs.set("data-" + name, val);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
delay() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
debug() {
|
||||
return {
|
||||
@@ -59,22 +59,22 @@ function FakeElement(selector, opts) {
|
||||
if (arg === undefined) {
|
||||
find_results.clear();
|
||||
}
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
eq() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
expectOne() {
|
||||
// silently do nothing
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
fadeTo: noop,
|
||||
find(child_selector) {
|
||||
const child = find_results.get(child_selector);
|
||||
if (child) {
|
||||
return child;
|
||||
const $child = find_results.get(child_selector);
|
||||
if ($child) {
|
||||
return $child;
|
||||
}
|
||||
if (child === false) {
|
||||
if ($child === false) {
|
||||
// This is deliberately set to simulate missing find results.
|
||||
// Return an empty array, the most common check is
|
||||
// if ($.find().length) { //success }
|
||||
@@ -84,12 +84,12 @@ function FakeElement(selector, opts) {
|
||||
We need you to simulate the results of $(...).find(...)
|
||||
by using set_find_results. You want something like this:
|
||||
|
||||
const container = ...;
|
||||
const child = ...;
|
||||
container.set_find_results("${child_selector}", child);
|
||||
const $container = ...;
|
||||
const $child = ...;
|
||||
$container.set_find_results("${child_selector}", $child);
|
||||
|
||||
Then calling container.find("${child_selector}") will return
|
||||
the "child" zjquery element.
|
||||
Then calling $container.find("${child_selector}") will return
|
||||
the "$child" zjquery element.
|
||||
|
||||
`);
|
||||
},
|
||||
@@ -107,12 +107,12 @@ function FakeElement(selector, opts) {
|
||||
},
|
||||
hide() {
|
||||
shown = false;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
html(arg) {
|
||||
if (arg !== undefined) {
|
||||
html = arg;
|
||||
return self;
|
||||
return $self;
|
||||
}
|
||||
return html;
|
||||
},
|
||||
@@ -121,9 +121,9 @@ function FakeElement(selector, opts) {
|
||||
return shown;
|
||||
}
|
||||
if (arg === ":focus") {
|
||||
return self.is_focused();
|
||||
return $self.is_focused();
|
||||
}
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
is_focused() {
|
||||
// is_focused is not a jQuery thing; this is
|
||||
@@ -132,7 +132,7 @@ function FakeElement(selector, opts) {
|
||||
},
|
||||
off(...args) {
|
||||
event_store.off(...args);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
offset() {
|
||||
return {
|
||||
@@ -142,44 +142,44 @@ function FakeElement(selector, opts) {
|
||||
},
|
||||
on(...args) {
|
||||
event_store.on(...args);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
one(...args) {
|
||||
event_store.one(...args);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
parent() {
|
||||
return my_parent;
|
||||
return $my_parent;
|
||||
},
|
||||
parents(parents_selector) {
|
||||
const result = parents_result.get(parents_selector);
|
||||
const $result = parents_result.get(parents_selector);
|
||||
assert.ok(
|
||||
result,
|
||||
$result,
|
||||
"You need to call set_parents_result for " + parents_selector + " in " + selector,
|
||||
);
|
||||
return result;
|
||||
return $result;
|
||||
},
|
||||
prepend(arg) {
|
||||
html = arg + html;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
prop(name, val) {
|
||||
if (val === undefined) {
|
||||
return properties.get(name);
|
||||
}
|
||||
properties.set(name, val);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
removeAttr(name) {
|
||||
attrs.delete(name);
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
removeClass(class_names) {
|
||||
class_names = class_names.split(" ");
|
||||
for (const class_name of class_names) {
|
||||
classes.delete(class_name);
|
||||
}
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
remove() {
|
||||
throw new Error(`
|
||||
@@ -193,68 +193,68 @@ function FakeElement(selector, opts) {
|
||||
},
|
||||
removeData: noop,
|
||||
replaceWith() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
scrollTop() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
serializeArray() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
set_find_results(find_selector, jquery_object) {
|
||||
if (jquery_object === undefined) {
|
||||
set_find_results(find_selector, $jquery_object) {
|
||||
if ($jquery_object === undefined) {
|
||||
throw new Error(
|
||||
"Please make the 'find result' be something like $.create('unused')",
|
||||
);
|
||||
}
|
||||
find_results.set(find_selector, jquery_object);
|
||||
find_results.set(find_selector, $jquery_object);
|
||||
},
|
||||
set_height(fake_height) {
|
||||
height = fake_height;
|
||||
},
|
||||
set_parent(parent_elem) {
|
||||
my_parent = parent_elem;
|
||||
set_parent($parent_elem) {
|
||||
$my_parent = $parent_elem;
|
||||
},
|
||||
set_parents_result(selector, result) {
|
||||
parents_result.set(selector, result);
|
||||
set_parents_result(selector, $result) {
|
||||
parents_result.set(selector, $result);
|
||||
},
|
||||
show() {
|
||||
shown = true;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
slice() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
stop() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
text(...args) {
|
||||
if (args.length !== 0) {
|
||||
if (args[0] !== undefined) {
|
||||
text = args[0].toString();
|
||||
}
|
||||
return self;
|
||||
return $self;
|
||||
}
|
||||
return text;
|
||||
},
|
||||
toggle(show) {
|
||||
assert.ok([true, false].includes(show));
|
||||
shown = show;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
tooltip() {
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
trigger(ev) {
|
||||
event_store.trigger(self, ev);
|
||||
return self;
|
||||
event_store.trigger($self, ev);
|
||||
return $self;
|
||||
},
|
||||
val(...args) {
|
||||
if (args.length === 0) {
|
||||
return value || "";
|
||||
}
|
||||
[value] = args;
|
||||
return self;
|
||||
return $self;
|
||||
},
|
||||
visible() {
|
||||
return shown;
|
||||
@@ -262,34 +262,34 @@ function FakeElement(selector, opts) {
|
||||
};
|
||||
|
||||
if (opts.children) {
|
||||
self.map = (f) => opts.children.map((i, elem) => f(elem, i));
|
||||
self.each = (f) => {
|
||||
$self.map = (f) => opts.children.map((i, elem) => f(elem, i));
|
||||
$self.each = (f) => {
|
||||
for (const child of opts.children) {
|
||||
f.call(child);
|
||||
}
|
||||
};
|
||||
self[Symbol.iterator] = function* () {
|
||||
$self[Symbol.iterator] = function* () {
|
||||
for (const child of opts.children) {
|
||||
yield child;
|
||||
}
|
||||
};
|
||||
|
||||
for (const [i, child] of opts.children.entries()) {
|
||||
self[i] = child;
|
||||
$self[i] = child;
|
||||
}
|
||||
|
||||
self.length = opts.children.length;
|
||||
$self.length = opts.children.length;
|
||||
}
|
||||
|
||||
if (selector[0] === "<") {
|
||||
self.html(selector);
|
||||
$self.html(selector);
|
||||
}
|
||||
|
||||
self.selector = selector;
|
||||
$self.selector = selector;
|
||||
|
||||
self.__zjquery = true;
|
||||
$self.__zjquery = true;
|
||||
|
||||
return self;
|
||||
return $self;
|
||||
}
|
||||
|
||||
function make_event_store(selector) {
|
||||
@@ -394,7 +394,8 @@ function make_event_store(selector) {
|
||||
ev = new FakeEvent(ev);
|
||||
}
|
||||
if (!ev.target) {
|
||||
ev.target = $element;
|
||||
// FIXME: event.target should not be a jQuery object
|
||||
ev.target = $element; // eslint-disable-line no-jquery/variable-pattern
|
||||
}
|
||||
const func = on_functions.get(ev.type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user