2021-04-17 07:22:25 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
2021-04-17 07:22:25 +02:00
|
|
|
|
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,
|
|
|
|
});
|
2023-12-01 18:54:39 +01:00
|
|
|
mock_esm("../src/settings_data", {
|
|
|
|
user_can_access_all_other_users: () => false,
|
|
|
|
});
|
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");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
|
|
|
initialize_user_settings({user_settings: {}});
|
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);
|
2023-12-01 18:54:39 +01:00
|
|
|
muted_users.add_muted_user(10, 1577836900);
|
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",
|
2023-12-01 18:54:39 +01:00
|
|
|
can_unmute: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date_muted: 1577836900000,
|
|
|
|
date_muted_str: "Jan 1, 2020",
|
|
|
|
user_id: 10,
|
|
|
|
user_name: "translated: Unknown user",
|
|
|
|
can_unmute: false,
|
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
|
|
|
});
|