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-02-21 15:38:51 +01: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
|
|
|
|
2019-09-11 13:40:45 +02:00
|
|
|
const template = fs.readFileSync("templates/analytics/realm_details.html", "utf-8");
|
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;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("scrub_realm", () => {
|
2020-12-01 01:04:48 +01:00
|
|
|
zrequire("support", "js/analytics/support");
|
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
|
|
|
|
|
|
|
const fake_this = $.create("fake-.scrub-realm-button");
|
|
|
|
fake_this.data = (name) => {
|
|
|
|
assert.equal(name, "string-id");
|
|
|
|
return "zulip";
|
|
|
|
};
|
|
|
|
|
|
|
|
let submit_form_called = false;
|
|
|
|
fake_this.form = {
|
|
|
|
submit: () => {
|
|
|
|
submit_form_called = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const event = {
|
|
|
|
preventDefault: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
window.prompt = () => "zulip";
|
|
|
|
click_handler.call(fake_this, event);
|
|
|
|
assert(submit_form_called);
|
|
|
|
|
|
|
|
submit_form_called = false;
|
|
|
|
window.prompt = () => "invalid-string-id";
|
|
|
|
let alert_called = false;
|
|
|
|
window.alert = () => {
|
|
|
|
alert_called = true;
|
|
|
|
};
|
|
|
|
click_handler.call(fake_this, event);
|
|
|
|
assert(!submit_form_called);
|
|
|
|
assert(alert_called);
|
|
|
|
|
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
|
|
|
});
|