2021-04-17 07:22:25 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
2023-05-03 07:06:19 +02:00
|
|
|
const noop = () => {};
|
|
|
|
|
2023-10-01 21:48:06 +02:00
|
|
|
const channel = mock_esm("../src/channel");
|
2023-05-03 07:06:19 +02:00
|
|
|
const list_widget = mock_esm("../src/list_widget", {
|
|
|
|
generic_sort_functions: noop,
|
|
|
|
});
|
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");
|
2022-07-10 01:06:33 +02:00
|
|
|
const people = zrequire("people");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test("settings", ({override}) => {
|
|
|
|
people.add_active_user({user_id: 5, email: "five@zulip.com", full_name: "Feivel Fiverson"});
|
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;
|
2023-06-29 21:59:08 +02:00
|
|
|
override(list_widget, "create", (_$container, list) => {
|
2022-07-10 01:06:33 +02:00
|
|
|
assert.deepEqual(list, [
|
2021-04-17 07:22:25 +02:00
|
|
|
{
|
2023-10-26 04:11:17 +02:00
|
|
|
date_muted: 1577836800000,
|
2023-01-08 18:08:49 +01:00
|
|
|
date_muted_str: "Jan 1, 2020",
|
2022-07-10 01:06:33 +02:00
|
|
|
user_id: 5,
|
|
|
|
user_name: "Feivel Fiverson",
|
2021-04-17 07:22:25 +02:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
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) => {
|
2022-04-09 23:44:38 +02:00
|
|
|
assert.equal(opts, "data-user-id");
|
|
|
|
row_attribute_fetched += 1;
|
|
|
|
return "5";
|
2021-04-17 07:22:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let unmute_user_called = false;
|
2023-10-01 21:48:06 +02:00
|
|
|
channel.del = (payload) => {
|
|
|
|
assert.equal(payload.url, "/json/users/me/muted_users/5");
|
2021-04-17 07:22:25 +02:00
|
|
|
unmute_user_called = true;
|
2023-10-01 21:48:06 +02:00
|
|
|
return {abort() {}};
|
2021-04-17 07:22:25 +02:00
|
|
|
};
|
|
|
|
|
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);
|
2023-10-01 21:48:06 +02:00
|
|
|
|
|
|
|
let mute_user_called = false;
|
|
|
|
channel.post = (payload) => {
|
|
|
|
assert.equal(payload.url, "/json/users/me/muted_users/5");
|
|
|
|
mute_user_called = true;
|
|
|
|
return {abort() {}};
|
|
|
|
};
|
|
|
|
muted_users.mute_user(5);
|
|
|
|
assert.ok(mute_user_called);
|
2021-04-17 07:22:25 +02:00
|
|
|
});
|