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");
|
|
|
|
const {page_params, user_settings} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", "document-stub");
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.realm_users = [];
|
2013-11-26 16:39:58 +01:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
// We use this with override.
|
2022-07-10 01:06:33 +02:00
|
|
|
let num_unread_for_stream;
|
2022-08-05 22:45:20 +02:00
|
|
|
let stream_has_any_unread_mentions;
|
2022-02-20 21:32:14 +01:00
|
|
|
const noop = () => {};
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/narrow_state", {
|
2022-05-07 02:53:53 +02:00
|
|
|
active: () => false,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const topic_list = mock_esm("../src/topic_list");
|
|
|
|
const scroll_util = mock_esm("../src/scroll_util", {
|
2022-07-10 01:06:33 +02:00
|
|
|
scroll_element_into_container() {},
|
2023-04-25 18:01:02 +02:00
|
|
|
get_scroll_element: ($element) => $element,
|
2022-07-10 01:06:33 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/unread", {
|
2023-04-22 18:24:59 +02:00
|
|
|
num_unread_for_stream: () => ({
|
|
|
|
unmuted_count: num_unread_for_stream,
|
|
|
|
stream_is_muted: false,
|
|
|
|
muted_count: 0,
|
|
|
|
}),
|
2022-08-05 22:45:20 +02:00
|
|
|
stream_has_any_unread_mentions: () => stream_has_any_unread_mentions,
|
2023-05-19 22:31:46 +02:00
|
|
|
stream_has_any_unmuted_mentions: () => noop,
|
2022-07-10 01:06:33 +02:00
|
|
|
});
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2020-12-01 23:21:38 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const stream_list = zrequire("stream_list");
|
2023-04-24 07:37:18 +02:00
|
|
|
const stream_list_sort = zrequire("stream_list_sort");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-02-21 13:48:11 +01:00
|
|
|
const devel = {
|
|
|
|
name: "devel",
|
|
|
|
stream_id: 100,
|
|
|
|
color: "blue",
|
|
|
|
subscribed: true,
|
|
|
|
pin_to_top: true,
|
|
|
|
};
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2021-02-21 13:48:11 +01:00
|
|
|
const social = {
|
|
|
|
name: "social",
|
|
|
|
stream_id: 200,
|
|
|
|
color: "green",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
// flag to check if subheader is rendered
|
|
|
|
let pinned_subheader_flag = false;
|
|
|
|
let active_subheader_flag = false;
|
|
|
|
let inactive_subheader_flag = false;
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
function create_devel_sidebar_row({mock_template}) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $devel_count = $.create("devel-count");
|
|
|
|
const $subscription_block = $.create("devel-block");
|
2022-08-05 22:45:20 +02:00
|
|
|
const $devel_unread_mention_info = $.create("devel-unread-mention-info");
|
2017-01-15 17:09:16 +01:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $sidebar_row = $("<devel-sidebar-row-stub>");
|
2021-02-21 13:48:11 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$sidebar_row.set_find_results(".subscription_block", $subscription_block);
|
|
|
|
$subscription_block.set_find_results(".unread_count", $devel_count);
|
2022-08-05 22:45:20 +02:00
|
|
|
$subscription_block.set_find_results(".unread_mention_info", $devel_unread_mention_info);
|
2021-02-21 13:48:11 +01:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("stream_sidebar_row.hbs", false, (data) => {
|
2023-04-09 05:22:23 +02:00
|
|
|
assert.equal(data.url, "#narrow/stream/100-devel");
|
2022-03-17 00:31:13 +01:00
|
|
|
return "<devel-sidebar-row-stub>";
|
2021-02-21 13:48:11 +01:00
|
|
|
});
|
2017-07-08 15:16:19 +02:00
|
|
|
|
2021-02-21 13:48:11 +01:00
|
|
|
num_unread_for_stream = 42;
|
2022-08-05 22:45:20 +02:00
|
|
|
stream_has_any_unread_mentions = false;
|
2021-02-21 13:48:11 +01:00
|
|
|
stream_list.create_sidebar_row(devel);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($devel_count.text(), "42");
|
2022-08-05 22:45:20 +02:00
|
|
|
assert.equal($devel_unread_mention_info.text(), "");
|
2021-02-21 13:48:11 +01:00
|
|
|
}
|
2017-07-08 15:16:19 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
function create_social_sidebar_row({mock_template}) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $social_count = $.create("social-count");
|
|
|
|
const $subscription_block = $.create("social-block");
|
2022-08-05 22:45:20 +02:00
|
|
|
const $social_unread_mention_info = $.create("social-unread-mention-info");
|
2021-04-14 23:46:28 +02:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $sidebar_row = $("<social-sidebar-row-stub>");
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$sidebar_row.set_find_results(".subscription_block", $subscription_block);
|
|
|
|
$subscription_block.set_find_results(".unread_count", $social_count);
|
2022-08-05 22:45:20 +02:00
|
|
|
$subscription_block.set_find_results(".unread_mention_info", $social_unread_mention_info);
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("stream_sidebar_row.hbs", false, (data) => {
|
2023-04-09 05:22:23 +02:00
|
|
|
assert.equal(data.url, "#narrow/stream/200-social");
|
2022-03-17 00:31:13 +01:00
|
|
|
return "<social-sidebar-row-stub>";
|
2021-02-21 13:48:11 +01:00
|
|
|
});
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2021-02-21 13:48:11 +01:00
|
|
|
num_unread_for_stream = 99;
|
2022-08-05 22:45:20 +02:00
|
|
|
stream_has_any_unread_mentions = true;
|
2021-02-21 13:48:11 +01:00
|
|
|
stream_list.create_sidebar_row(social);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($social_count.text(), "99");
|
2022-08-05 22:45:20 +02:00
|
|
|
assert.equal($social_unread_mention_info.text(), "@");
|
2021-02-21 13:48:11 +01:00
|
|
|
}
|
2017-07-08 15:16:19 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
function create_stream_subheader({mock_template}) {
|
|
|
|
mock_template("streams_subheader.hbs", false, (data) => {
|
|
|
|
if (data.subheader_name === "translated: Pinned") {
|
|
|
|
pinned_subheader_flag = true;
|
|
|
|
return "<pinned-subheader-stub>";
|
|
|
|
} else if (data.subheader_name === "translated: Active") {
|
|
|
|
active_subheader_flag = true;
|
|
|
|
return "<active-subheader-stub>";
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.ok(data.subheader_name === "translated: Inactive");
|
|
|
|
inactive_subheader_flag = true;
|
|
|
|
return "<inactive-subheader-stub>";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-21 14:23:59 +01:00
|
|
|
function test_ui(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-02-21 14:23:59 +01:00
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
stream_list.stream_sidebar.rows.clear();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-02-21 14:23:59 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
|
2021-02-21 13:48:11 +01:00
|
|
|
// Make a couple calls to create_sidebar_row() and make sure they
|
|
|
|
// generate the right markup as well as play nice with get_stream_li().
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings.demote_inactive_streams = 1;
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2021-02-21 13:48:11 +01:00
|
|
|
stream_data.add_sub(devel);
|
|
|
|
stream_data.add_sub(social);
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
create_devel_sidebar_row({mock_template});
|
|
|
|
create_social_sidebar_row({mock_template});
|
2022-02-20 21:32:14 +01:00
|
|
|
create_stream_subheader({mock_template});
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
const $pinned_subheader = $("<pinned-subheader-stub>");
|
|
|
|
const $active_subheader = $("<active-subheader-stub>");
|
2022-03-17 00:31:13 +01:00
|
|
|
const $devel_sidebar = $("<devel-sidebar-row-stub>");
|
|
|
|
const $social_sidebar = $("<social-sidebar-row-stub>");
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended_elems;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#stream_filters").append = (elems) => {
|
2017-06-02 00:33:39 +02:00
|
|
|
appended_elems = elems;
|
|
|
|
};
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2020-04-06 19:16:01 +02:00
|
|
|
let topic_list_cleared;
|
|
|
|
topic_list.clear = () => {
|
|
|
|
topic_list_cleared = true;
|
|
|
|
};
|
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
stream_list.build_stream_list();
|
2016-11-11 02:39:22 +01:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(topic_list_cleared);
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_elems = [
|
2022-02-20 21:32:14 +01:00
|
|
|
$pinned_subheader.html(), // separator
|
2022-01-25 11:36:19 +01:00
|
|
|
$devel_sidebar, // pinned
|
2022-02-20 21:32:14 +01:00
|
|
|
$active_subheader.html(), // separator
|
2022-01-25 11:36:19 +01:00
|
|
|
$social_sidebar, // not pinned
|
2017-06-02 00:33:39 +02:00
|
|
|
];
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
2022-02-20 21:32:14 +01:00
|
|
|
assert.ok(pinned_subheader_flag);
|
|
|
|
assert.ok(active_subheader_flag);
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $social_li = $("<social-sidebar-row-stub>");
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = social.stream_id;
|
2017-06-14 16:06:21 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$social_li.length = 0;
|
2019-04-18 21:11:30 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $privacy_elem = $.create("privacy-stub");
|
|
|
|
$social_li.set_find_results(".stream-privacy", $privacy_elem);
|
2017-06-14 16:33:30 +02:00
|
|
|
|
|
|
|
social.invite_only = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
social.color = "#222222";
|
2021-06-14 17:21:38 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("stream_privacy.hbs", false, (data) => {
|
2017-06-14 16:33:30 +02:00
|
|
|
assert.equal(data.invite_only, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
return "<div>privacy-html";
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-14 16:33:30 +02:00
|
|
|
stream_list.redraw_stream_privacy(social);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($privacy_elem.html(), "<div>privacy-html");
|
2017-06-14 16:33:30 +02:00
|
|
|
|
2017-06-14 16:06:21 +02:00
|
|
|
stream_list.set_in_home_view(stream_id, false);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($social_li.hasClass("out_of_home_view"));
|
2017-06-14 16:06:21 +02:00
|
|
|
|
|
|
|
stream_list.set_in_home_view(stream_id, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$social_li.hasClass("out_of_home_view"));
|
2017-06-14 16:06:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = stream_list.stream_sidebar.get_row(stream_id);
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => true);
|
2017-06-14 16:06:21 +02:00
|
|
|
row.update_whether_active();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$social_li.hasClass("inactive_stream"));
|
2017-06-14 16:06:21 +02:00
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => false);
|
2017-06-14 16:06:21 +02:00
|
|
|
row.update_whether_active();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($social_li.hasClass("inactive_stream"));
|
2017-06-14 16:06:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let removed;
|
2022-01-25 11:36:19 +01:00
|
|
|
$social_li.remove = () => {
|
2017-06-14 16:06:21 +02:00
|
|
|
removed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
row.remove();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(removed);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
|
2021-02-21 13:48:11 +01:00
|
|
|
stream_data.add_sub(devel);
|
2020-12-01 00:57:57 +01:00
|
|
|
stream_data.add_sub(social);
|
2019-04-11 08:25:50 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
create_devel_sidebar_row({mock_template});
|
|
|
|
create_social_sidebar_row({mock_template});
|
2022-02-20 21:32:14 +01:00
|
|
|
create_stream_subheader({mock_template});
|
2019-04-11 08:25:50 +02:00
|
|
|
|
|
|
|
// non-pinned streams can be made inactive
|
2022-03-17 00:31:13 +01:00
|
|
|
const $social_sidebar = $("<social-sidebar-row-stub>");
|
2019-11-02 00:06:25 +01:00
|
|
|
let stream_id = social.stream_id;
|
|
|
|
let row = stream_list.stream_sidebar.get_row(stream_id);
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => false);
|
2019-04-11 08:25:50 +02:00
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($social_sidebar.hasClass("inactive_stream"));
|
2019-04-11 08:25:50 +02:00
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => true);
|
2019-04-11 08:25:50 +02:00
|
|
|
row.update_whether_active();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$social_sidebar.hasClass("inactive_stream"));
|
2019-04-11 08:25:50 +02:00
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => false);
|
2019-04-11 08:25:50 +02:00
|
|
|
row.update_whether_active();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($social_sidebar.hasClass("inactive_stream"));
|
2019-04-11 08:25:50 +02:00
|
|
|
|
|
|
|
// pinned streams can never be made inactive
|
2022-03-17 00:31:13 +01:00
|
|
|
const $devel_sidebar = $("<devel-sidebar-row-stub>");
|
2019-04-11 08:25:50 +02:00
|
|
|
stream_id = devel.stream_id;
|
|
|
|
row = stream_list.stream_sidebar.get_row(stream_id);
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", () => false);
|
2019-04-11 08:25:50 +02:00
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
|
2019-04-11 08:25:50 +02:00
|
|
|
|
|
|
|
row.update_whether_active();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
|
2019-04-11 08:25:50 +02:00
|
|
|
});
|
|
|
|
|
2017-11-13 17:17:34 +01:00
|
|
|
function add_row(sub) {
|
2020-12-01 00:57:57 +01:00
|
|
|
stream_data.add_sub(sub);
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = {
|
2020-07-20 22:18:43 +02:00
|
|
|
update_whether_active() {},
|
|
|
|
get_li() {
|
2022-03-17 00:31:13 +01:00
|
|
|
const html = "<" + sub.name + "-sidebar-row-stub>";
|
2022-01-25 11:36:19 +01:00
|
|
|
const $obj = $(html);
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$obj.length = 1; // bypass blueslip error
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $obj;
|
2017-11-13 17:17:34 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
stream_list.stream_sidebar.set_row(sub.stream_id, row);
|
|
|
|
}
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
function initialize_stream_data() {
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
// pinned streams
|
2019-11-02 00:06:25 +01:00
|
|
|
const develSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "devel",
|
2016-07-01 07:26:09 +02:00
|
|
|
stream_id: 1000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(develSub);
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const RomeSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Rome",
|
2016-07-01 07:26:09 +02:00
|
|
|
stream_id: 2000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2016-07-01 07:26:09 +02:00
|
|
|
pin_to_top: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(RomeSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const testSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "test",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
stream_id: 3000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(testSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
|
|
|
// unpinned streams
|
2019-11-02 00:06:25 +01:00
|
|
|
const announceSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "announce",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
stream_id: 4000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "green",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(announceSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const DenmarkSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Denmark",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
stream_id: 5000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "green",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(DenmarkSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const carSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "cars",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
stream_id: 6000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "green",
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(carSub);
|
2021-02-21 14:23:59 +01:00
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
2017-06-14 14:33:04 +02:00
|
|
|
}
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2018-04-25 13:03:39 +02:00
|
|
|
function elem($obj) {
|
|
|
|
return {to_$: () => $obj};
|
|
|
|
}
|
|
|
|
|
2022-11-02 17:38:38 +01:00
|
|
|
test_ui("zoom_in_and_zoom_out", ({mock_template}) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $label1 = $.create("label1 stub");
|
|
|
|
const $label2 = $.create("label2 stub");
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$label1.show();
|
|
|
|
$label2.show();
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($label1.visible());
|
|
|
|
assert.ok($label2.visible());
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2021-02-08 15:48:50 +01:00
|
|
|
$.create(".stream-filters-label", {
|
2022-01-25 11:36:19 +01:00
|
|
|
children: [elem($label1), elem($label2)],
|
2021-02-08 15:48:50 +01:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
const $splitter = $.create("<active-subheader-stub>");
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$splitter.show();
|
|
|
|
assert.ok($splitter.visible());
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
$.create(".streams_subheader", {
|
2022-01-25 11:36:19 +01:00
|
|
|
children: [elem($splitter)],
|
2021-02-08 15:48:50 +01:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li1 = $.create("stream1 stub");
|
|
|
|
const $stream_li2 = $.create("stream2 stub");
|
2018-04-25 13:03:39 +02:00
|
|
|
|
|
|
|
function make_attr(arg) {
|
|
|
|
return (sel) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(sel, "data-stream-id");
|
2018-04-25 13:03:39 +02:00
|
|
|
return arg;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_li1.attr = make_attr("42");
|
|
|
|
$stream_li1.hide();
|
|
|
|
$stream_li2.attr = make_attr("99");
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2021-02-08 15:48:50 +01:00
|
|
|
$.create("#stream_filters li.narrow-filter", {
|
2022-01-25 11:36:19 +01:00
|
|
|
children: [elem($stream_li1), elem($stream_li2)],
|
2021-02-08 15:48:50 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream-filters-container")[0] = {
|
2019-07-26 00:22:43 +02:00
|
|
|
dataset: {},
|
|
|
|
};
|
2023-06-01 00:43:46 +02:00
|
|
|
stream_list.initialize_stream_cursor();
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-11-02 17:38:38 +01:00
|
|
|
mock_template("filter_topics", false, () => "filter-topics-stub");
|
|
|
|
let filter_topics_appended = false;
|
|
|
|
$stream_li1.children = () => ({
|
2022-11-17 23:33:43 +01:00
|
|
|
append(html) {
|
2022-11-02 17:38:38 +01:00
|
|
|
assert.equal(html, "filter-topics-stub");
|
|
|
|
filter_topics_appended = true;
|
|
|
|
},
|
|
|
|
});
|
2018-09-10 14:52:58 +02:00
|
|
|
stream_list.zoom_in_topics({stream_id: 42});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$label1.visible());
|
|
|
|
assert.ok(!$label2.visible());
|
|
|
|
assert.ok(!$splitter.visible());
|
|
|
|
assert.ok($stream_li1.visible());
|
|
|
|
assert.ok(!$stream_li2.visible());
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#streams_list").hasClass("zoom-in"));
|
2022-11-02 17:38:38 +01:00
|
|
|
assert.ok(filter_topics_appended);
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters li.narrow-filter").show = () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_li1.show();
|
|
|
|
$stream_li2.show();
|
2018-04-25 13:03:39 +02:00
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_li1.length = 1;
|
2022-11-02 17:38:38 +01:00
|
|
|
$(".filter-topics").remove = () => {
|
|
|
|
filter_topics_appended = false;
|
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
stream_list.zoom_out_topics({$stream_li: $stream_li1});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($label1.visible());
|
|
|
|
assert.ok($label2.visible());
|
|
|
|
assert.ok($splitter.visible());
|
|
|
|
assert.ok($stream_li1.visible());
|
|
|
|
assert.ok($stream_li2.visible());
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#streams_list").hasClass("zoom-out"));
|
2022-11-02 17:38:38 +01:00
|
|
|
assert.ok(!filter_topics_appended);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
test_ui("narrowing", ({mock_template}) => {
|
|
|
|
create_stream_subheader({mock_template});
|
2017-06-14 20:17:09 +02:00
|
|
|
initialize_stream_data();
|
|
|
|
|
2017-08-11 00:30:23 +02:00
|
|
|
topic_list.close = noop;
|
2017-06-14 20:17:09 +02:00
|
|
|
topic_list.rebuild = noop;
|
2017-08-11 00:30:23 +02:00
|
|
|
topic_list.active_stream_id = noop;
|
2018-09-10 23:45:31 +02:00
|
|
|
topic_list.get_stream_li = noop;
|
2022-10-05 09:43:57 +02:00
|
|
|
$("#streams_header").outerHeight = () => 0;
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
assert.ok(!$("<devel-sidebar-row-stub>").hasClass("active-filter"));
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let filter;
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
filter = new Filter([{operator: "stream", operand: "devel"}]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2022-03-17 00:31:13 +01:00
|
|
|
assert.ok($("<devel-sidebar-row-stub>").hasClass("active-filter"));
|
2017-06-14 20:17:09 +02:00
|
|
|
|
|
|
|
filter = new Filter([
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "stream", operand: "cars"},
|
|
|
|
{operator: "topic", operand: "sedans"},
|
2017-06-14 20:17:09 +02:00
|
|
|
]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("ul.filters li").hasClass("active-filter"));
|
2022-03-17 00:31:13 +01:00
|
|
|
assert.ok(!$("<cars-sidebar-row-stub>").hasClass("active-filter")); // false because of topic
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
filter = new Filter([{operator: "stream", operand: "cars"}]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("ul.filters li").hasClass("active-filter"));
|
2022-03-17 00:31:13 +01:00
|
|
|
assert.ok($("<cars-sidebar-row-stub>").hasClass("active-filter"));
|
2018-04-25 18:30:07 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let removed_classes;
|
2018-04-25 18:30:07 +02:00
|
|
|
$("ul#stream_filters li").removeClass = (classes) => {
|
|
|
|
removed_classes = classes;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let topics_closed;
|
2018-04-25 18:30:07 +02:00
|
|
|
topic_list.close = () => {
|
|
|
|
topics_closed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.handle_narrow_deactivated();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(removed_classes, "active-filter");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(topics_closed);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2021-02-21 14:23:59 +01:00
|
|
|
test_ui("focusout_user_filter", () => {
|
2023-06-01 00:53:51 +02:00
|
|
|
stream_list.set_event_handlers({narrow_on_stream_click() {}});
|
2020-07-15 00:34:28 +02:00
|
|
|
const e = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
const click_handler = $(".stream-list-filter").get_on_handler("focusout");
|
2018-02-12 22:56:37 +01:00
|
|
|
click_handler(e);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("focus_user_filter", () => {
|
2023-06-01 00:53:51 +02:00
|
|
|
stream_list.set_event_handlers({narrow_on_stream_click() {}});
|
2021-02-21 14:23:59 +01:00
|
|
|
|
|
|
|
initialize_stream_data();
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const e = {
|
2020-07-20 22:18:43 +02:00
|
|
|
stopPropagation() {},
|
2018-02-12 22:56:37 +01:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
const click_handler = $(".stream-list-filter").get_on_handler("click");
|
2018-02-12 22:56:37 +01:00
|
|
|
click_handler(e);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
test_ui("sort_streams", ({override_rewire, mock_template}) => {
|
|
|
|
create_stream_subheader({mock_template});
|
|
|
|
// Set subheader flag to false
|
|
|
|
pinned_subheader_flag = false;
|
|
|
|
active_subheader_flag = false;
|
|
|
|
inactive_subheader_flag = false;
|
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
initialize_stream_data();
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "cars");
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended_elems;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#stream_filters").append = (elems) => {
|
2017-06-02 00:33:39 +02:00
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
2017-04-28 15:37:52 +02:00
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
const $pinned_subheader = $("<pinned-subheader-stub>");
|
|
|
|
const $active_subheader = $("<active-subheader-stub>");
|
|
|
|
const $inactive_subheader = $("<inactive-subheader-stub>");
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_elems = [
|
2022-02-20 21:32:14 +01:00
|
|
|
$pinned_subheader.html(),
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<devel-sidebar-row-stub>"),
|
|
|
|
$("<Rome-sidebar-row-stub>"),
|
|
|
|
$("<test-sidebar-row-stub>"),
|
2022-02-20 21:32:14 +01:00
|
|
|
$active_subheader.html(),
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<announce-sidebar-row-stub>"),
|
|
|
|
$("<Denmark-sidebar-row-stub>"),
|
2022-02-20 21:32:14 +01:00
|
|
|
$inactive_subheader.html(),
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<cars-sidebar-row-stub>"),
|
2017-06-02 00:33:39 +02:00
|
|
|
];
|
2017-07-18 13:30:14 +02:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
2022-02-20 21:32:14 +01:00
|
|
|
assert.ok(pinned_subheader_flag);
|
|
|
|
assert.ok(active_subheader_flag);
|
|
|
|
assert.ok(inactive_subheader_flag);
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
const streams = stream_list_sort.get_streams();
|
2017-04-18 17:08:59 +02:00
|
|
|
|
|
|
|
assert.deepEqual(streams, [
|
2017-04-18 19:59:35 +02:00
|
|
|
// three groups: pinned, normal, dormant
|
2020-07-15 01:29:15 +02:00
|
|
|
"devel",
|
|
|
|
"Rome",
|
|
|
|
"test",
|
2017-04-18 19:59:35 +02:00
|
|
|
//
|
2020-07-15 01:29:15 +02:00
|
|
|
"announce",
|
|
|
|
"Denmark",
|
2017-04-18 19:59:35 +02:00
|
|
|
//
|
2020-07-15 01:29:15 +02:00
|
|
|
"cars",
|
2017-04-18 17:08:59 +02:00
|
|
|
]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const denmark_sub = stream_data.get_sub("Denmark");
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = denmark_sub.stream_id;
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(stream_list.stream_sidebar.has_row_for(stream_id));
|
2017-06-14 14:33:04 +02:00
|
|
|
stream_list.remove_sidebar_row(stream_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!stream_list.stream_sidebar.has_row_for(stream_id));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-14 00:27:06 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template}) => {
|
2017-11-13 17:17:34 +01:00
|
|
|
// Test only pinned and dormant streams
|
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
create_stream_subheader({mock_template});
|
|
|
|
pinned_subheader_flag = false;
|
|
|
|
inactive_subheader_flag = false;
|
|
|
|
|
2017-11-13 17:17:34 +01:00
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
// pinned streams
|
2019-11-02 00:06:25 +01:00
|
|
|
const develSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "devel",
|
2017-11-13 17:17:34 +01:00
|
|
|
stream_id: 1000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(develSub);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const RomeSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Rome",
|
2017-11-13 17:17:34 +01:00
|
|
|
stream_id: 2000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(RomeSub);
|
2020-03-28 01:25:56 +01:00
|
|
|
// dormant stream
|
2019-11-02 00:06:25 +01:00
|
|
|
const DenmarkSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Denmark",
|
2017-11-13 17:17:34 +01:00
|
|
|
stream_id: 3000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(DenmarkSub);
|
|
|
|
|
2023-04-24 07:37:18 +02:00
|
|
|
override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "Denmark");
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended_elems;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#stream_filters").append = (elems) => {
|
2017-11-13 17:17:34 +01:00
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
const $pinned_subheader = $("<pinned-subheader-stub>");
|
|
|
|
const $inactive_subheader = $("<inactive-subheader-stub>");
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_elems = [
|
2022-02-20 21:32:14 +01:00
|
|
|
$pinned_subheader.html(), // pinned
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<devel-sidebar-row-stub>"),
|
|
|
|
$("<Rome-sidebar-row-stub>"),
|
2022-02-20 21:32:14 +01:00
|
|
|
$inactive_subheader.html(), // dormant
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<Denmark-sidebar-row-stub>"),
|
2017-11-13 17:17:34 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
2022-02-20 21:32:14 +01:00
|
|
|
assert.ok(pinned_subheader_flag);
|
|
|
|
assert.ok(inactive_subheader_flag);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2022-09-04 18:37:13 +02:00
|
|
|
test_ui("separators_only_pinned", () => {
|
2017-11-13 17:17:34 +01:00
|
|
|
// Test only pinned streams
|
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
// pinned streams
|
2019-11-02 00:06:25 +01:00
|
|
|
const develSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "devel",
|
2017-11-13 17:17:34 +01:00
|
|
|
stream_id: 1000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(develSub);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const RomeSub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Rome",
|
2017-11-13 17:17:34 +01:00
|
|
|
stream_id: 2000,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(RomeSub);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended_elems;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#stream_filters").append = (elems) => {
|
2017-11-13 17:17:34 +01:00
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_elems = [
|
2022-09-04 18:37:13 +02:00
|
|
|
// no section sub-header since there is only one section
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<devel-sidebar-row-stub>"),
|
|
|
|
$("<Rome-sidebar-row-stub>"),
|
2017-11-13 17:17:34 +01:00
|
|
|
// no separator at the end as no stream follows
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2019-04-11 08:25:50 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("rename_stream", ({mock_template}) => {
|
2022-02-20 21:32:14 +01:00
|
|
|
create_stream_subheader({mock_template});
|
2021-02-21 14:23:59 +01:00
|
|
|
initialize_stream_data();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const sub = stream_data.get_sub_by_name("devel");
|
|
|
|
const new_name = "Development";
|
2018-12-14 19:18:24 +01:00
|
|
|
|
|
|
|
stream_data.rename_sub(sub, new_name);
|
2018-04-25 17:40:49 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li_stub = $.create("li stub");
|
|
|
|
$li_stub.length = 0;
|
2019-04-18 21:11:30 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("stream_sidebar_row.hbs", false, (payload) => {
|
2018-04-25 17:40:49 +02:00
|
|
|
assert.deepEqual(payload, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Development",
|
2018-04-25 17:40:49 +02:00
|
|
|
id: 1000,
|
2023-04-09 05:22:23 +02:00
|
|
|
url: "#narrow/stream/1000-Development",
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: false,
|
2018-04-25 17:40:49 +02:00
|
|
|
invite_only: undefined,
|
2019-04-07 20:29:25 +02:00
|
|
|
is_web_public: undefined,
|
2018-04-25 17:40:49 +02:00
|
|
|
color: payload.color,
|
|
|
|
pin_to_top: true,
|
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
return {to_$: () => $li_stub};
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-04-25 17:40:49 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
const $subscription_block = $.create("development-block");
|
|
|
|
const $unread_count = $.create("development-count");
|
2022-08-05 22:45:20 +02:00
|
|
|
const $unread_mention_info = $.create("development-unread-mention-info");
|
2022-07-10 01:06:33 +02:00
|
|
|
$li_stub.set_find_results(".subscription_block", $subscription_block);
|
|
|
|
$subscription_block.set_find_results(".unread_count", $unread_count);
|
2022-08-05 22:45:20 +02:00
|
|
|
$subscription_block.set_find_results(".unread_mention_info", $unread_mention_info);
|
2018-04-25 17:40:49 +02:00
|
|
|
|
2018-12-14 19:18:24 +01:00
|
|
|
stream_list.rename_stream(sub);
|
2022-07-10 01:06:33 +02:00
|
|
|
assert.equal($unread_count.text(), "99");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 17:40:49 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("refresh_pin", ({override, override_rewire, mock_template}) => {
|
2018-04-25 18:12:16 +02:00
|
|
|
initialize_stream_data();
|
|
|
|
|
|
|
|
const sub = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "maybe_pin",
|
2018-04-25 18:12:16 +02:00
|
|
|
stream_id: 100,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
2018-04-25 18:12:16 +02:00
|
|
|
pin_to_top: false,
|
|
|
|
};
|
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(sub);
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2020-02-09 04:15:38 +01:00
|
|
|
const pinned_sub = {
|
|
|
|
...sub,
|
2018-04-25 18:12:16 +02:00
|
|
|
pin_to_top: true,
|
2020-02-09 04:15:38 +01:00
|
|
|
};
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li_stub = $.create("li stub");
|
2022-07-10 01:06:33 +02:00
|
|
|
$li_stub.length = 1;
|
2019-04-18 21:11:30 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
mock_template("stream_sidebar_row.hbs", false, () => ({to_$: () => $li_stub}));
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_list, "update_count_in_dom", noop);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters").append = noop;
|
2022-10-05 09:43:57 +02:00
|
|
|
$("#streams_header").outerHeight = () => 0;
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let scrolled;
|
2022-07-10 01:06:33 +02:00
|
|
|
override(scroll_util, "scroll_element_into_container", ($li) => {
|
|
|
|
if ($li === $li_stub) {
|
|
|
|
scrolled = true;
|
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
});
|
2018-04-25 18:12:16 +02:00
|
|
|
|
|
|
|
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(scrolled);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test_ui("create_initial_sidebar_rows", ({override, override_rewire, mock_template}) => {
|
2017-06-14 14:33:04 +02:00
|
|
|
initialize_stream_data();
|
|
|
|
|
2020-02-03 09:42:50 +01:00
|
|
|
const html_dict = new Map();
|
2017-06-14 14:33:04 +02:00
|
|
|
|
2021-03-13 20:11:20 +01:00
|
|
|
override(stream_list.stream_sidebar, "has_row_for", () => false);
|
|
|
|
override(stream_list.stream_sidebar, "set_row", (stream_id, widget) => {
|
|
|
|
html_dict.set(stream_id, widget.get_li().html());
|
2021-02-28 21:31:02 +01:00
|
|
|
});
|
2017-06-14 14:33:04 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_list, "update_count_in_dom", noop);
|
2017-06-14 14:33:04 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("stream_sidebar_row.hbs", false, (data) => "<div>stub-html-" + data.name);
|
2017-06-14 14:33:04 +02:00
|
|
|
|
|
|
|
// Test this code with stubs above...
|
|
|
|
stream_list.create_initial_sidebar_rows();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(html_dict.get(1000), "<div>stub-html-devel");
|
|
|
|
assert.equal(html_dict.get(5000), "<div>stub-html-Denmark");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|