2021-08-03 17:15:23 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
|
|
|
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
|
|
|
|
|
|
|
mock_template("typing_notifications.hbs", true, (args, rendered_html) => rendered_html);
|
|
|
|
|
|
|
|
// Having only two(<MAX_USERS_TO_DISPLAY_NAME) typists, both of them
|
|
|
|
// should be rendered but not 'Several people are typing…'
|
2022-07-10 01:06:33 +02:00
|
|
|
typing_data.add_typist(group, anna.user_id);
|
|
|
|
typing_data.add_typist(group, 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
|
2022-07-10 01:06:33 +02:00
|
|
|
typing_data.add_typist(group, 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…"
|
2022-07-10 01:06:33 +02:00
|
|
|
typing_data.add_typist(group, 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.
|
2022-07-10 01:06:33 +02:00
|
|
|
typing_data.remove_typist(group, anna.user_id);
|
|
|
|
typing_data.remove_typist(group, vronsky.user_id);
|
|
|
|
typing_data.remove_typist(group, levin.user_id);
|
|
|
|
typing_data.remove_typist(group, 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());
|
2021-08-03 17:15:23 +02:00
|
|
|
});
|