support: Avoid $(callback) to reduce zjquery complexity.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-10-25 17:43:15 -07:00
committed by Tim Abbott
parent 1a41a13ea3
commit 5bdb734cde
4 changed files with 7 additions and 31 deletions

View File

@@ -2,7 +2,7 @@ import ClipboardJS from "clipboard";
import $ from "jquery";
import assert from "minimalistic-assert";
$(() => {
function initialize(): void {
$("body").on("click", "button.scrub-realm-button", function (this: HTMLButtonElement, e) {
e.preventDefault();
const message =
@@ -100,4 +100,6 @@ $(() => {
}
},
);
});
}
initialize();

View File

@@ -87,7 +87,6 @@ const noop = function () {};
require("../../src/templates.ts"); // register Zulip extensions
async function run_one_module(file) {
zjquery.clear_initialize_function();
zjquery.clear_all_elements();
console.info("running test " + path.basename(file, ".test.cjs"));
test.set_current_file_name(file);

View File

@@ -82,24 +82,8 @@ function make_zjquery() {
return proxy;
}
let initialize_function;
const zjquery = function (arg, arg2) {
if (typeof arg === "function") {
assert.ok(
!initialize_function,
`
We are trying to avoid the $(...) mechanism
for initializing modules in our codebase,
and the code that you are compiling/running
has tried to do this twice. Please either
clean up the real code or reduce the scope
of what you are testing in this test module.
`,
);
initialize_function = arg;
return undefined;
}
assert.ok(typeof arg !== "function", "zjquery does not support $(callback)");
// If somebody is passing us an element, we return
// the element itself if it's been created with
@@ -141,14 +125,6 @@ function make_zjquery() {
return elems.get(selector);
};
zjquery.get_initialize_function = function () {
return initialize_function;
};
zjquery.clear_initialize_function = function () {
initialize_function = undefined;
};
zjquery.create = function (name, opts) {
assert.ok(!elems.has(name), "You already created an object with this name!!");
const $elem = new_elem(name, opts);

View File

@@ -21,10 +21,9 @@ mock_cjs("clipboard", class Clipboard {});
zrequire("../src/support/support");
run_test("scrub_realm", () => {
$.get_initialize_function()();
const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
run_test("scrub_realm", () => {
const $fake_this = $.create("fake-.scrub-realm-button");
$fake_this.attr = (name) => {
assert.equal(name, "data-string-id");