2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
2019-04-19 18:17:41 +02:00
|
|
|
const fs = require("fs");
|
2023-02-24 02:47:55 +01:00
|
|
|
const path = require("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
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
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(
|
|
|
|
path.resolve(__dirname, "../../templates/analytics/realm_details.html"),
|
|
|
|
"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;
|
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
zrequire("../src/analytics/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()();
|
2020-07-15 01:29:15 +02:00
|
|
|
const click_handler = $("body").get_on_handler("click", ".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");
|
|
|
|
$fake_this.data = (name) => {
|
2020-08-13 19:02:01 +02:00
|
|
|
assert.equal(name, "string-id");
|
|
|
|
return "zulip";
|
|
|
|
};
|
|
|
|
|
|
|
|
let submit_form_called = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$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";
|
2022-01-25 11:36:19 +01: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;
|
|
|
|
};
|
2022-01-25 11:36:19 +01: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
|
|
|
|
2019-09-11 13:40:45 +02:00
|
|
|
assert.equal(document.querySelectorAll(".scrub-realm-button").length, 1);
|
2019-04-19 18:17:41 +02:00
|
|
|
});
|