2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
|
|
|
const fs = require("node:fs");
|
|
|
|
const path = require("node:path");
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
const {JSDOM} = require("jsdom");
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2024-05-03 03:12:43 +02:00
|
|
|
const {mock_cjs, zrequire} = require("./lib/namespace");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-24 02:47:55 +01:00
|
|
|
const template = fs.readFileSync(
|
2024-01-29 15:08:13 +01:00
|
|
|
path.resolve(__dirname, "../../templates/corporate/support/realm_details.html"),
|
2023-02-24 02:47:55 +01:00
|
|
|
"utf8",
|
|
|
|
);
|
2020-07-16 22:40:18 +02:00
|
|
|
const dom = new JSDOM(template, {pretendToBeVisual: true});
|
2019-04-19 18:17:41 +02:00
|
|
|
const document = dom.window.document;
|
|
|
|
|
2024-05-03 03:12:43 +02:00
|
|
|
mock_cjs("clipboard", class Clipboard {});
|
|
|
|
|
2024-02-29 18:52:42 +01:00
|
|
|
zrequire("../src/support/support");
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("scrub_realm", () => {
|
2021-03-13 15:49:01 +01:00
|
|
|
$.get_initialize_function()();
|
2024-05-03 23:23:50 +02:00
|
|
|
const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
|
2020-08-13 19:02:01 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $fake_this = $.create("fake-.scrub-realm-button");
|
2023-03-24 23:28:19 +01:00
|
|
|
$fake_this.attr = (name) => {
|
|
|
|
assert.equal(name, "data-string-id");
|
2020-08-13 19:02:01 +02:00
|
|
|
return "zulip";
|
|
|
|
};
|
|
|
|
|
|
|
|
let submit_form_called = false;
|
2024-05-03 23:23:50 +02:00
|
|
|
const fake_this = {to_$: () => $fake_this};
|
|
|
|
fake_this.form = {
|
2022-11-17 23:33:43 +01:00
|
|
|
submit() {
|
2020-08-13 19:02:01 +02:00
|
|
|
submit_form_called = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const event = {
|
2022-11-17 23:33:43 +01:00
|
|
|
preventDefault() {},
|
2020-08-13 19:02:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
window.prompt = () => "zulip";
|
2024-05-03 23:23:50 +02:00
|
|
|
click_handler.call(fake_this, event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(submit_form_called);
|
2020-08-13 19:02:01 +02:00
|
|
|
|
|
|
|
submit_form_called = false;
|
|
|
|
window.prompt = () => "invalid-string-id";
|
|
|
|
let alert_called = false;
|
|
|
|
window.alert = () => {
|
|
|
|
alert_called = true;
|
|
|
|
};
|
2024-05-03 23:23:50 +02:00
|
|
|
click_handler.call(fake_this, event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!submit_form_called);
|
|
|
|
assert.ok(alert_called);
|
2020-08-13 19:02:01 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(typeof click_handler, "function");
|
2019-04-19 18:17:41 +02:00
|
|
|
|
2024-05-03 23:23:50 +02:00
|
|
|
assert.equal(document.querySelectorAll("button.scrub-realm-button").length, 1);
|
2019-04-19 18:17:41 +02:00
|
|
|
});
|