zjquery: Eliminate css() helper.

We use css() pretty rarely in our codebase, and
it can sometimes be used mistakenly, when a better
alternative is to toggle a class for external css.

It's hard to support the full API in zjquery, so
we just punt and tell folks to create their own
stubs.

Most of the existing tests that were "fixed" here
weren't actually verifying the behavior of the css()
calls, and for those I just create no-op stubs.

In a few places I verify that css() was called as
expected.
This commit is contained in:
Steve Howell 2021-06-04 17:27:45 +00:00 committed by Tim Abbott
parent 38d9e26a6c
commit 94ffef4de9
7 changed files with 30 additions and 10 deletions

View File

@ -94,6 +94,10 @@ function override_private_message_recipient(override) {
function test(label, f) { function test(label, f) {
run_test(label, (override) => { run_test(label, (override) => {
// We don't test the css calls; we just skip over them.
$("#compose").css = () => {};
$(".new_message_textarea").css = () => {};
people.init(); people.init();
compose_state.set_message_type(false); compose_state.set_message_type(false);
f(override); f(override);

View File

@ -76,6 +76,7 @@ const short_msg = {
function test(label, f) { function test(label, f) {
run_test(label, (override) => { run_test(label, (override) => {
$("#draft_overlay").css = () => {};
localStorage.clear(); localStorage.clear();
f(override); f(override);
}); });

View File

@ -339,6 +339,8 @@ function stub_out_filter_buttons() {
function test(label, f) { function test(label, f) {
run_test(label, (override) => { run_test(label, (override) => {
$(".header").css = () => {};
messages = sample_messages.map((message) => ({...message})); messages = sample_messages.map((message) => ({...message}));
f(override); f(override);
}); });

View File

@ -216,9 +216,12 @@ test("initialize", () => {
search_query_box.trigger(new $.Event("blur", stub_event)); search_query_box.trigger(new $.Event("blur", stub_event));
assert.equal(search_query_box.val(), "test string"); assert.equal(search_query_box.val(), "test string");
searchbox.css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"}); let css_args;
searchbox.css = (args) => {
css_args = args;
};
searchbox.trigger("focusout"); searchbox.trigger("focusout");
assert.deepEqual(searchbox.css(), {"box-shadow": "unset"}); assert.deepEqual(css_args, {"box-shadow": "unset"});
search.__Rewire__("is_using_input_method", false); search.__Rewire__("is_using_input_method", false);
searchbox_form.trigger("compositionend"); searchbox_form.trigger("compositionend");
@ -343,8 +346,15 @@ test("initiate_search", () => {
$("#search_query")[0] = "stub"; $("#search_query")[0] = "stub";
const searchbox = $("#searchbox");
let css_args;
searchbox.css = (args) => {
css_args = args;
};
search.initiate_search(); search.initiate_search();
assert(typeahead_forced_open); assert(typeahead_forced_open);
assert(is_searchbox_text_selected); assert(is_searchbox_text_selected);
assert(is_searchbox_focused); assert(is_searchbox_focused);
assert.deepEqual(css_args, {"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
}); });

View File

@ -287,11 +287,21 @@ run_test("initiate_search", () => {
is_searchbox_text_selected = true; is_searchbox_text_selected = true;
}); });
let searchbox_css_args;
$("#searchbox").css = (args) => {
searchbox_css_args = args;
};
search.initiate_search(); search.initiate_search();
assert(typeahead_forced_open); assert(typeahead_forced_open);
assert(is_searchbox_text_selected); assert(is_searchbox_text_selected);
assert.equal($("#search_query").val(), "ver"); assert.equal($("#search_query").val(), "ver");
assert.deepEqual(searchbox_css_args, {
"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)",
});
// test that we append space for user convenience // test that we append space for user convenience
narrow_state.filter = () => ({is_search: () => false}); narrow_state.filter = () => ({is_search: () => false});
search.initiate_search(); search.initiate_search();

View File

@ -62,6 +62,7 @@ const dropdown_list_widget = zrequire("dropdown_list_widget");
function test(label, f) { function test(label, f) {
run_test(label, (override) => { run_test(label, (override) => {
$("#realm-icon-upload-widget .upload-spinner-background").css = () => {};
page_params.is_admin = false; page_params.is_admin = false;
page_params.realm_domains = [ page_params.realm_domains = [
{domain: "example.com", allow_subdomains: true}, {domain: "example.com", allow_subdomains: true},

View File

@ -174,7 +174,6 @@ function make_new_elem(selector, opts) {
let html = "never-been-set"; let html = "never-been-set";
let text = "never-been-set"; let text = "never-been-set";
let value; let value;
let css;
let shown = false; let shown = false;
let height; let height;
@ -202,13 +201,6 @@ function make_new_elem(selector, opts) {
attrs.set(name, val); attrs.set(name, val);
return self; return self;
}, },
css(...args) {
if (args.length === 0) {
return css || {};
}
[css] = args;
return self;
},
data(name, val) { data(name, val) {
if (val === undefined) { if (val === undefined) {
return attrs.get("data-" + name); return attrs.get("data-" + name);