2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, 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");
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const muting_ui = set_global("muting_ui", {});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("timerender");
|
2021-02-10 04:53:22 +01:00
|
|
|
const settings_muting = zrequire("settings_muting");
|
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const muting = zrequire("muting");
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
const noop = () => {};
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const frontend = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "frontend",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(frontend);
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("settings", () => {
|
|
|
|
muting.add_muted_topic(frontend.stream_id, "js", 1577836800);
|
2021-01-03 12:28:09 +01:00
|
|
|
let set_up_topic_ui_called = false;
|
2021-02-23 14:37:26 +01:00
|
|
|
muting_ui.set_up_muted_topics_ui = () => {
|
2020-04-22 23:22:26 +02:00
|
|
|
const opts = muting.get_muted_topics();
|
2020-02-05 13:14:24 +01:00
|
|
|
assert.deepEqual(opts, [
|
|
|
|
{
|
|
|
|
date_muted: 1577836800000,
|
2021-01-02 06:19:48 +01:00
|
|
|
date_muted_str: "Jan\u00A001,\u00A02020",
|
2020-02-05 13:14:24 +01:00
|
|
|
stream: frontend.name,
|
|
|
|
stream_id: frontend.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "js",
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
|
|
|
]);
|
2021-01-03 12:28:09 +01:00
|
|
|
set_up_topic_ui_called = true;
|
2018-04-09 15:22:26 +02:00
|
|
|
};
|
|
|
|
|
2020-07-12 00:13:47 +02:00
|
|
|
assert.equal(settings_muting.loaded, false);
|
|
|
|
|
2018-04-09 15:22:26 +02:00
|
|
|
settings_muting.set_up();
|
2020-07-12 00:13:47 +02:00
|
|
|
assert.equal(settings_muting.loaded, true);
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2021-01-03 12:28:09 +01:00
|
|
|
const topic_click_handler = $("body").get_on_handler("click", ".settings-unmute-topic");
|
|
|
|
assert.equal(typeof topic_click_handler, "function");
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2018-04-09 15:22:26 +02:00
|
|
|
stopImmediatePropagation: noop,
|
|
|
|
};
|
|
|
|
|
2021-01-03 12:28:09 +01:00
|
|
|
const topic_fake_this = $.create("fake.settings-unmute-topic");
|
|
|
|
const topic_tr_html = $('tr[data-topic="js"]');
|
2021-02-23 14:37:26 +01:00
|
|
|
topic_fake_this.closest = (opts) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts, "tr");
|
2021-01-03 12:28:09 +01:00
|
|
|
return topic_tr_html;
|
2018-04-09 15:22:26 +02:00
|
|
|
};
|
|
|
|
|
2021-02-25 16:07:04 +01:00
|
|
|
topic_tr_html.remove = () => {};
|
|
|
|
|
2021-01-03 12:28:09 +01:00
|
|
|
let topic_data_called = 0;
|
2021-02-23 14:37:26 +01:00
|
|
|
topic_tr_html.attr = (opts) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (opts === "data-stream-id") {
|
2021-01-03 12:28:09 +01:00
|
|
|
topic_data_called += 1;
|
2018-12-14 17:52:01 +01:00
|
|
|
return frontend.stream_id;
|
2018-04-09 15:22:26 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
if (opts === "data-topic") {
|
2021-01-03 12:28:09 +01:00
|
|
|
topic_data_called += 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
return "js";
|
2018-04-09 15:22:26 +02:00
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
throw new Error(`Unknown attribute ${opts}`);
|
2018-04-09 15:22:26 +02:00
|
|
|
};
|
|
|
|
|
2021-01-03 12:28:09 +01:00
|
|
|
let unmute_topic_called = false;
|
2021-02-23 14:37:26 +01:00
|
|
|
muting_ui.unmute_topic = (stream_id, topic) => {
|
2018-12-14 17:20:35 +01:00
|
|
|
assert.equal(stream_id, frontend.stream_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(topic, "js");
|
2021-01-03 12:28:09 +01:00
|
|
|
unmute_topic_called = true;
|
2018-04-09 15:22:26 +02:00
|
|
|
};
|
2021-01-03 12:28:09 +01:00
|
|
|
topic_click_handler.call(topic_fake_this, event);
|
|
|
|
assert(unmute_topic_called);
|
|
|
|
assert(set_up_topic_ui_called);
|
|
|
|
assert.equal(topic_data_called, 2);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2020-07-12 00:13:47 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("reset", () => {
|
2020-07-12 00:13:47 +02:00
|
|
|
settings_muting.reset();
|
|
|
|
assert.equal(settings_muting.loaded, false);
|
|
|
|
});
|