2021-08-03 17:15:23 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2021-08-03 17:15:23 +02:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test} = require("./lib/test.cjs");
|
|
|
|
const $ = require("./lib/zjquery.cjs");
|
2021-08-03 17:15:23 +02:00
|
|
|
|
2023-12-05 16:06:43 +01:00
|
|
|
const settings_data = mock_esm("../src/settings_data");
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
const {Filter} = zrequire("filter");
|
2024-02-13 03:44:04 +01:00
|
|
|
const message_lists = zrequire("message_lists");
|
2021-08-03 17:15:23 +02:00
|
|
|
const people = zrequire("people");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
2022-07-10 01:06:33 +02:00
|
|
|
const typing_data = zrequire("typing_data");
|
|
|
|
const typing_events = zrequire("typing_events");
|
2021-08-03 17:15:23 +02:00
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
const current_user = {};
|
|
|
|
set_current_user(current_user);
|
|
|
|
set_realm({});
|
|
|
|
|
2021-08-03 17:15:23 +02:00
|
|
|
const anna = {
|
|
|
|
email: "anna@example.com",
|
|
|
|
full_name: "Anna Karenina",
|
|
|
|
user_id: 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
const vronsky = {
|
|
|
|
email: "vronsky@example.com",
|
|
|
|
full_name: "Alexei Vronsky",
|
|
|
|
user_id: 9,
|
|
|
|
};
|
|
|
|
|
|
|
|
const levin = {
|
|
|
|
email: "levin@example.com",
|
|
|
|
full_name: "Konstantin Levin",
|
|
|
|
user_id: 10,
|
|
|
|
};
|
|
|
|
|
|
|
|
const kitty = {
|
|
|
|
email: "kitty@example.com",
|
|
|
|
full_name: "Kitty S",
|
|
|
|
user_id: 11,
|
|
|
|
};
|
|
|
|
|
|
|
|
people.add_active_user(anna);
|
|
|
|
people.add_active_user(vronsky);
|
|
|
|
people.add_active_user(levin);
|
|
|
|
people.add_active_user(kitty);
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test("render_notifications_for_narrow", ({override, mock_template}) => {
|
2024-02-13 02:08:16 +01:00
|
|
|
override(current_user, "user_id", anna.user_id);
|
2023-12-05 16:06:43 +01:00
|
|
|
override(settings_data, "user_can_access_all_other_users", () => true);
|
2022-07-10 01:06:33 +02:00
|
|
|
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
2021-04-05 21:10:11 +02:00
|
|
|
const conversation_key = typing_data.get_direct_message_conversation_key(group);
|
2022-07-10 01:06:33 +02:00
|
|
|
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
|
2024-02-13 03:44:04 +01:00
|
|
|
message_lists.set_current({
|
|
|
|
data: {
|
|
|
|
filter: new Filter([{operator: "dm", operand: group_emails}]),
|
|
|
|
},
|
|
|
|
});
|
2021-08-03 17:15:23 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
const $typing_notifications = $("#typing_notifications");
|
2021-08-03 17:15:23 +02:00
|
|
|
|
2023-06-29 21:59:08 +02:00
|
|
|
mock_template("typing_notifications.hbs", true, (_args, rendered_html) => rendered_html);
|
2021-08-03 17:15:23 +02:00
|
|
|
|
|
|
|
// Having only two(<MAX_USERS_TO_DISPLAY_NAME) typists, both of them
|
|
|
|
// should be rendered but not 'Several people are typing…'
|
2021-04-05 21:10:11 +02:00
|
|
|
typing_data.add_typist(conversation_key, anna.user_id);
|
|
|
|
typing_data.add_typist(conversation_key, vronsky.user_id);
|
2021-08-03 17:15:23 +02:00
|
|
|
typing_events.render_notifications_for_narrow();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($typing_notifications.visible());
|
|
|
|
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
|
|
|
assert.ok($typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
|
|
|
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
|
2021-08-03 17:15:23 +02:00
|
|
|
|
|
|
|
// Having 3(=MAX_USERS_TO_DISPLAY_NAME) typists should also display only names
|
2021-04-05 21:10:11 +02:00
|
|
|
typing_data.add_typist(conversation_key, levin.user_id);
|
2021-08-03 17:15:23 +02:00
|
|
|
typing_events.render_notifications_for_narrow();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($typing_notifications.visible());
|
|
|
|
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
|
|
|
assert.ok($typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
|
|
|
assert.ok($typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
|
|
|
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
|
2021-08-03 17:15:23 +02:00
|
|
|
|
|
|
|
// Having 4(>MAX_USERS_TO_DISPLAY_NAME) typists should display "Several people are typing…"
|
2021-04-05 21:10:11 +02:00
|
|
|
typing_data.add_typist(conversation_key, kitty.user_id);
|
2021-08-03 17:15:23 +02:00
|
|
|
typing_events.render_notifications_for_narrow();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($typing_notifications.visible());
|
|
|
|
assert.ok($typing_notifications.html().includes("Several people are typing…"));
|
|
|
|
assert.ok(!$typing_notifications.html().includes(`${anna.full_name} is typing…`));
|
|
|
|
assert.ok(!$typing_notifications.html().includes(`${vronsky.full_name} is typing…`));
|
|
|
|
assert.ok(!$typing_notifications.html().includes(`${levin.full_name} is typing…`));
|
|
|
|
assert.ok(!$typing_notifications.html().includes(`${kitty.full_name} is typing…`));
|
2021-08-03 17:15:23 +02:00
|
|
|
|
|
|
|
// #typing_notifications should be hidden when there are no typists.
|
2021-04-05 21:10:11 +02:00
|
|
|
typing_data.remove_typist(conversation_key, anna.user_id);
|
|
|
|
typing_data.remove_typist(conversation_key, vronsky.user_id);
|
|
|
|
typing_data.remove_typist(conversation_key, levin.user_id);
|
|
|
|
typing_data.remove_typist(conversation_key, kitty.user_id);
|
2021-08-03 17:15:23 +02:00
|
|
|
typing_events.render_notifications_for_narrow();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$typing_notifications.visible());
|
2023-12-05 16:06:43 +01:00
|
|
|
|
|
|
|
// #typing_notifications should be hidden for inaccessible users.
|
|
|
|
override(settings_data, "user_can_access_all_other_users", () => false);
|
|
|
|
const inaccessible_user = people.add_inaccessible_user(20);
|
|
|
|
typing_data.add_typist(conversation_key, inaccessible_user.user_id);
|
|
|
|
typing_data.add_typist(conversation_key, 21);
|
|
|
|
typing_events.render_notifications_for_narrow();
|
|
|
|
assert.ok(!$typing_notifications.visible());
|
2021-08-03 17:15:23 +02:00
|
|
|
});
|