2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/resize", {
|
2022-11-17 23:33:43 +01:00
|
|
|
resize_stream_filters_container() {},
|
2020-11-30 11:07:54 +01:00
|
|
|
});
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2023-05-02 19:25:44 +02:00
|
|
|
const scheduled_messages = mock_esm("../src/scheduled_messages");
|
|
|
|
|
|
|
|
scheduled_messages.get_count = () => 555;
|
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2023-06-15 17:07:10 +02:00
|
|
|
const left_sidebar_navigation_area = zrequire("left_sidebar_navigation_area");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-08-12 23:01:44 +02:00
|
|
|
run_test("narrowing", () => {
|
|
|
|
let filter = new Filter([{operator: "is", operand: "mentioned"}]);
|
2018-10-21 00:04:46 +02:00
|
|
|
|
2022-08-12 23:01:44 +02:00
|
|
|
// activating narrow
|
2020-07-22 13:39:38 +02:00
|
|
|
|
2023-06-15 17:07:10 +02:00
|
|
|
left_sidebar_navigation_area.handle_narrow_activated(filter);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($(".top_left_mentions").hasClass("active-filter"));
|
2019-01-30 18:24:56 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
filter = new Filter([{operator: "is", operand: "starred"}]);
|
2023-06-15 17:07:10 +02:00
|
|
|
left_sidebar_navigation_area.handle_narrow_activated(filter);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($(".top_left_starred_messages").hasClass("active-filter"));
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
filter = new Filter([{operator: "in", operand: "home"}]);
|
2023-06-15 17:07:10 +02:00
|
|
|
left_sidebar_navigation_area.handle_narrow_activated(filter);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($(".top_left_all_messages").hasClass("active-filter"));
|
2018-04-18 08:48:31 +02:00
|
|
|
|
|
|
|
// deactivating narrow
|
|
|
|
|
2023-10-04 02:52:04 +02:00
|
|
|
left_sidebar_navigation_area.handle_narrow_activated(new Filter());
|
2018-04-18 08:48:31 +02:00
|
|
|
|
2023-10-04 02:52:04 +02:00
|
|
|
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_starred_messages").hasClass("active-filter"));
|
2023-09-06 23:55:09 +02:00
|
|
|
assert.ok(!$(".top_left_recent_view").hasClass("active-filter"));
|
2023-08-09 07:23:30 +02:00
|
|
|
assert.ok(!$(".top_left_inbox").hasClass("active-filter"));
|
2020-07-05 12:19:09 +02:00
|
|
|
|
2020-11-30 11:07:54 +01:00
|
|
|
set_global("setTimeout", (f) => {
|
|
|
|
f();
|
|
|
|
});
|
2023-09-08 07:51:34 +02:00
|
|
|
left_sidebar_navigation_area.highlight_recent_view();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_starred_messages").hasClass("active-filter"));
|
2023-08-09 07:23:30 +02:00
|
|
|
assert.ok(!$(".top_left_inbox").hasClass("active-filter"));
|
2023-09-06 23:55:09 +02:00
|
|
|
assert.ok($(".top_left_recent_view").hasClass("active-filter"));
|
2023-08-09 07:23:30 +02:00
|
|
|
|
2023-10-04 02:52:04 +02:00
|
|
|
left_sidebar_navigation_area.handle_narrow_activated(new Filter());
|
2023-08-09 07:23:30 +02:00
|
|
|
left_sidebar_navigation_area.highlight_inbox_view();
|
|
|
|
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_starred_messages").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_recent_view").hasClass("active-filter"));
|
|
|
|
assert.ok($(".top_left_inbox").hasClass("active-filter"));
|
2023-11-09 22:40:56 +01:00
|
|
|
|
|
|
|
left_sidebar_navigation_area.highlight_all_messages_view();
|
|
|
|
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_starred_messages").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_recent_view").hasClass("active-filter"));
|
|
|
|
assert.ok(!$(".top_left_inbox").hasClass("active-filter"));
|
|
|
|
assert.ok($(".top_left_all_messages").hasClass("active-filter"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("update_count_in_dom", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
function make_elem($elem, count_selector) {
|
|
|
|
const $count = $(count_selector);
|
|
|
|
$elem.set_find_results(".unread_count", $count);
|
|
|
|
$count.set_parent($elem);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $elem;
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = {
|
2017-08-12 17:26:12 +02:00
|
|
|
mentioned_message_count: 222,
|
|
|
|
home_unread_messages: 333,
|
2023-11-15 17:17:13 +01:00
|
|
|
stream_unread_messages: 666,
|
2017-08-12 17:26:12 +02:00
|
|
|
};
|
|
|
|
|
2021-04-09 09:20:15 +02:00
|
|
|
make_elem($(".top_left_mentions"), "<mentioned-count>");
|
2020-07-15 00:34:28 +02:00
|
|
|
|
2023-10-03 18:40:44 +02:00
|
|
|
make_elem($(".top_left_inbox"), "<home-count>");
|
2020-07-15 00:34:28 +02:00
|
|
|
|
2023-11-02 20:08:30 +01:00
|
|
|
make_elem($(".selected-home-view"), "<home-count>");
|
|
|
|
|
2021-04-09 09:20:15 +02:00
|
|
|
make_elem($(".top_left_starred_messages"), "<starred-count>");
|
2019-01-30 18:24:56 +01:00
|
|
|
|
2023-05-02 19:25:44 +02:00
|
|
|
make_elem($(".top_left_scheduled_messages"), "<scheduled-count>");
|
|
|
|
|
2023-11-15 17:17:13 +01:00
|
|
|
make_elem($("#streams_header"), "<stream-count>");
|
|
|
|
|
2023-11-20 23:32:51 +01:00
|
|
|
make_elem($("#topics_header"), "<topics-count>");
|
|
|
|
|
2023-06-15 17:07:10 +02:00
|
|
|
left_sidebar_navigation_area.update_dom_with_unread_counts(counts, false);
|
|
|
|
left_sidebar_navigation_area.update_starred_count(444);
|
|
|
|
// Calls left_sidebar_navigation_area.update_scheduled_messages_row
|
|
|
|
left_sidebar_navigation_area.initialize();
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-04-09 09:20:15 +02:00
|
|
|
assert.equal($("<mentioned-count>").text(), "222");
|
|
|
|
assert.equal($("<home-count>").text(), "333");
|
|
|
|
assert.equal($("<starred-count>").text(), "444");
|
2023-05-02 19:25:44 +02:00
|
|
|
assert.equal($("<scheduled-count>").text(), "555");
|
2023-11-15 17:17:13 +01:00
|
|
|
assert.equal($("<stream-count>").text(), "666");
|
2023-11-20 23:32:51 +01:00
|
|
|
assert.equal($("<topics-count>").text(), "666");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2018-04-18 08:48:31 +02:00
|
|
|
counts.mentioned_message_count = 0;
|
2023-05-02 19:25:44 +02:00
|
|
|
scheduled_messages.get_count = () => 0;
|
|
|
|
|
2023-06-15 17:07:10 +02:00
|
|
|
left_sidebar_navigation_area.update_dom_with_unread_counts(counts, false);
|
|
|
|
left_sidebar_navigation_area.update_starred_count(0);
|
|
|
|
left_sidebar_navigation_area.update_scheduled_messages_row();
|
2018-04-18 08:48:31 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("<mentioned-count>").visible());
|
2021-04-09 09:20:15 +02:00
|
|
|
assert.equal($("<mentioned-count>").text(), "");
|
|
|
|
assert.equal($("<starred-count>").text(), "");
|
2023-05-02 19:25:44 +02:00
|
|
|
assert.ok(!$(".top_left_scheduled_messages").visible());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|