mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	This bug made it impossible to scrub realms where the string_id was a number, e.g. 123.zulipchat.com because confirmed_string_id === actual_string_id comparison failed due to one being a string and the other a number. Per http://api.jquery.com/data/#data-html5: Every attempt is made to convert the attribute's string value to a JavaScript value (this includes booleans, numbers, objects, arrays, and null). To retrieve a data-* attribute value as an unconverted string, use the attr() method.
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const {strict: assert} = require("assert");
 | 
						|
const fs = require("fs");
 | 
						|
const path = require("path");
 | 
						|
 | 
						|
const {JSDOM} = require("jsdom");
 | 
						|
 | 
						|
const {zrequire} = require("./lib/namespace");
 | 
						|
const {run_test} = require("./lib/test");
 | 
						|
const $ = require("./lib/zjquery");
 | 
						|
 | 
						|
const template = fs.readFileSync(
 | 
						|
    path.resolve(__dirname, "../../templates/analytics/realm_details.html"),
 | 
						|
    "utf8",
 | 
						|
);
 | 
						|
const dom = new JSDOM(template, {pretendToBeVisual: true});
 | 
						|
const document = dom.window.document;
 | 
						|
 | 
						|
zrequire("../src/analytics/support");
 | 
						|
 | 
						|
run_test("scrub_realm", () => {
 | 
						|
    $.get_initialize_function()();
 | 
						|
    const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
 | 
						|
 | 
						|
    const $fake_this = $.create("fake-.scrub-realm-button");
 | 
						|
    $fake_this.attr = (name) => {
 | 
						|
        assert.equal(name, "data-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.ok(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.ok(!submit_form_called);
 | 
						|
    assert.ok(alert_called);
 | 
						|
 | 
						|
    assert.equal(typeof click_handler, "function");
 | 
						|
 | 
						|
    assert.equal(document.querySelectorAll(".scrub-realm-button").length, 1);
 | 
						|
});
 |