2021-04-17 07:22:25 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
const {mock_esm, zrequire} = require("../zjsunit/namespace");
|
2021-04-17 07:22:25 +02:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
|
|
|
const $ = require("../zjsunit/zjquery");
|
|
|
|
|
2021-07-08 20:28:14 +02:00
|
|
|
const muted_users_ui = mock_esm("../../static/js/muted_users_ui");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
|
|
|
const settings_muted_users = zrequire("settings_muted_users");
|
2021-06-27 21:38:26 +02:00
|
|
|
const muted_users = zrequire("muted_users");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
|
|
|
const noop = () => {};
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
run_test("settings", ({override_rewire}) => {
|
2021-06-27 21:38:26 +02:00
|
|
|
muted_users.add_muted_user(5, 1577836800);
|
2021-04-17 07:22:25 +02:00
|
|
|
let populate_list_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(settings_muted_users, "populate_list", () => {
|
2021-06-27 21:38:26 +02:00
|
|
|
const opts = muted_users.get_muted_users();
|
2021-04-17 07:22:25 +02:00
|
|
|
assert.deepEqual(opts, [
|
|
|
|
{
|
|
|
|
date_muted: 1577836800000,
|
|
|
|
date_muted_str: "Jan\u00A001,\u00A02020",
|
|
|
|
id: 5,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
populate_list_called = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
settings_muted_users.reset();
|
|
|
|
assert.equal(settings_muted_users.loaded, false);
|
|
|
|
|
|
|
|
settings_muted_users.set_up();
|
|
|
|
assert.equal(settings_muted_users.loaded, true);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(populate_list_called);
|
2021-04-17 07:22:25 +02:00
|
|
|
|
|
|
|
const unmute_click_handler = $("body").get_on_handler("click", ".settings-unmute-user");
|
|
|
|
assert.equal(typeof unmute_click_handler, "function");
|
|
|
|
|
|
|
|
const event = {
|
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $unmute_button = $.create("settings-unmute-user");
|
|
|
|
const $fake_row = $('tr[data-user-id="5"]');
|
|
|
|
$unmute_button.closest = (opts) => {
|
2021-04-17 07:22:25 +02:00
|
|
|
assert.equal(opts, "tr");
|
2022-01-25 11:36:19 +01:00
|
|
|
return $fake_row;
|
2021-04-17 07:22:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let row_attribute_fetched = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$fake_row.attr = (opts) => {
|
2021-04-17 07:22:25 +02:00
|
|
|
if (opts === "data-user-id") {
|
|
|
|
row_attribute_fetched += 1;
|
|
|
|
return "5";
|
|
|
|
}
|
|
|
|
throw new Error(`Unknown attribute ${opts}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
let unmute_user_called = false;
|
2021-07-08 20:28:14 +02:00
|
|
|
muted_users_ui.unmute_user = (user_id) => {
|
2021-04-17 07:22:25 +02:00
|
|
|
assert.equal(user_id, 5);
|
|
|
|
unmute_user_called = true;
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
unmute_click_handler.call($unmute_button, event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(unmute_user_called);
|
|
|
|
assert.ok(row_attribute_fetched);
|
2021-04-17 07:22:25 +02:00
|
|
|
});
|