2021-08-03 17:15:23 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-12-05 16:06:43 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
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");
|
|
|
|
const narrow_state = zrequire("narrow_state");
|
2021-08-03 17:15:23 +02:00
|
|
|
const people = zrequire("people");
|
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
|
|
|
|
|
|
|
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}) => {
|
|
|
|
override(page_params, "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}`;
|
2023-04-11 21:04:33 +02:00
|
|
|
narrow_state.set_current_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
|
|
|
});
|