Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

support: Fix implicit use of any.

Anders Kaseorg40440248e6e1
diff --git a/web/src/support/support.ts b/web/src/support/support.ts
index 984a457db6b..b9a360d47e6 100644
--- a/web/src/support/support.ts
+++ b/web/src/support/support.ts
@@ -1,8 +1,9 @@
import ClipboardJS from "clipboard";
import $ from "jquery";
+import assert from "minimalistic-assert";
$(() => {
- $("body").on("click", ".scrub-realm-button", function (e) {
+ $("body").on("click", "button.scrub-realm-button", function (this: HTMLButtonElement, e) {
e.preventDefault();
const message =
"Confirm the string_id of the realm you want to scrub.\n\n WARNING! This action is irreversible!";
@@ -10,6 +11,7 @@ $(() => {
// eslint-disable-next-line no-alert
const confirmed_string_id = window.prompt(message);
if (confirmed_string_id === actual_string_id) {
+ assert(this.form !== null);
this.form.submit();
} else {
// eslint-disable-next-line no-alert
@@ -17,7 +19,7 @@ $(() => {
}
});
- $("body").on("click", ".delete-user-button", function (e) {
+ $("body").on("click", "button.delete-user-button", function (this: HTMLButtonElement, e) {
e.preventDefault();
const message =
"Confirm the email of the user you want to delete.\n\n WARNING! This action is irreversible!";
@@ -31,6 +33,7 @@ $(() => {
"Now provide string_id of the realm to confirm.",
);
if (confirmed_string_id === actual_string_id) {
+ assert(this.form !== null);
this.form.submit();
} else {
// eslint-disable-next-line no-alert
diff --git a/web/tests/support.test.js b/web/tests/support.test.js
index 79dbaaa614b..b2588dd2a4d 100644
--- a/web/tests/support.test.js
+++ b/web/tests/support.test.js
@@ -23,7 +23,7 @@ zrequire("../src/support/support");
run_test("scrub_realm", () => {
$.get_initialize_function()();
- const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
+ const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
const $fake_this = $.create("fake-.scrub-realm-button");
$fake_this.attr = (name) => {
@@ -32,7 +32,8 @@ run_test("scrub_realm", () => {
};
let submit_form_called = false;
- $fake_this.form = {
+ const fake_this = {to_$: () => $fake_this};
+ fake_this.form = {
submit() {
submit_form_called = true;
},
@@ -42,7 +43,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;
@@ -51,11 +52,11 @@ 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);
assert.equal(typeof click_handler, "function");
- assert.equal(document.querySelectorAll(".scrub-realm-button").length, 1);
+ assert.equal(document.querySelectorAll("button.scrub-realm-button").length, 1);
});