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");
|
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
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2022-03-02 06:52:04 +01:00
|
|
|
const template = fs.readFileSync("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;
|
|
|
|
|
2021-03-13 15:49:01 +01:00
|
|
|
zrequire("../js/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 = {
|
2020-08-13 19:02:01 +02:00
|
|
|
submit: () => {
|
|
|
|
submit_form_called = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const event = {
|
|
|
|
preventDefault: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
});
|