2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
2020-12-01 00:02:16 +01: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
|
|
|
const {rewiremock, set_global, zrequire} = require("../zjsunit/namespace");
|
2021-02-13 03:46:14 +01:00
|
|
|
const {make_stub} = require("../zjsunit/stub");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 23:03:05 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2021-02-21 15:38:51 +01:00
|
|
|
|
2013-08-06 21:30:31 +02:00
|
|
|
// These unit tests for static/js/message_list.js emphasize the model-ish
|
|
|
|
// aspects of the MessageList class. We have to stub out a few functions
|
|
|
|
// related to views and events to get the tests working.
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2017-06-07 05:04:13 +02:00
|
|
|
|
2021-02-28 00:45:40 +01:00
|
|
|
rewiremock("../../static/js/filter").with({
|
|
|
|
Filter: noop,
|
|
|
|
});
|
2021-02-21 23:03:05 +01:00
|
|
|
set_global("document", {
|
|
|
|
to_$() {
|
|
|
|
return {
|
|
|
|
trigger() {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
const narrow_state = rewiremock("../../static/js/narrow_state").with({});
|
|
|
|
const stream_data = rewiremock("../../static/js/stream_data").with({});
|
2016-07-30 20:01:15 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const muting = zrequire("muting");
|
2020-08-03 23:57:48 +02:00
|
|
|
const {MessageList} = zrequire("message_list");
|
2013-08-06 21:30:31 +02:00
|
|
|
|
2018-05-13 22:05:41 +02:00
|
|
|
function accept_all_filter() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter = {
|
2020-07-02 01:41:40 +02:00
|
|
|
predicate: () => () => true,
|
2018-05-13 22:05:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
2021-02-21 15:38:51 +01:00
|
|
|
run_test("basics", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter = accept_all_filter();
|
2013-08-06 21:30:31 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({
|
2020-07-20 22:18:43 +02:00
|
|
|
filter,
|
2018-05-14 15:46:25 +02:00
|
|
|
});
|
2013-08-06 21:30:31 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const messages = [
|
2013-08-06 21:30:31 +02:00
|
|
|
{
|
|
|
|
id: 50,
|
2020-07-15 01:29:15 +02:00
|
|
|
content: "fifty",
|
2013-08-06 21:30:31 +02:00
|
|
|
},
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 60,
|
2013-08-06 21:30:31 +02:00
|
|
|
},
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 70,
|
2013-08-06 21:30:31 +02:00
|
|
|
},
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 80,
|
|
|
|
},
|
2013-08-06 21:30:31 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.equal(list.empty(), true);
|
|
|
|
|
|
|
|
list.append(messages, true);
|
|
|
|
|
2017-06-07 04:34:44 +02:00
|
|
|
assert.equal(list.num_items(), 4);
|
2013-08-06 21:30:31 +02:00
|
|
|
assert.equal(list.empty(), false);
|
|
|
|
assert.equal(list.first().id, 50);
|
|
|
|
assert.equal(list.last().id, 80);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(list.get(50).content, "fifty");
|
2013-08-06 21:30:31 +02:00
|
|
|
|
|
|
|
assert.equal(list.closest_id(49), 50);
|
|
|
|
assert.equal(list.closest_id(50), 50);
|
|
|
|
assert.equal(list.closest_id(51), 50);
|
|
|
|
assert.equal(list.closest_id(59), 60);
|
|
|
|
assert.equal(list.closest_id(60), 60);
|
|
|
|
assert.equal(list.closest_id(61), 60);
|
|
|
|
|
2016-04-23 00:56:44 +02:00
|
|
|
assert.deepEqual(list.all_messages(), messages);
|
2013-08-06 21:30:31 +02:00
|
|
|
|
2021-02-21 23:03:05 +01:00
|
|
|
override($, "Event", (ev) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "message_selected.zulip");
|
2021-02-21 15:38:51 +01:00
|
|
|
});
|
2013-08-06 21:30:31 +02:00
|
|
|
list.select_id(50);
|
|
|
|
|
|
|
|
assert.equal(list.selected_id(), 50);
|
2017-06-07 04:34:44 +02:00
|
|
|
assert.equal(list.selected_idx(), 0);
|
2013-08-06 21:30:31 +02:00
|
|
|
|
|
|
|
list.advance_past_messages([60, 80]);
|
|
|
|
assert.equal(list.selected_id(), 60);
|
2017-06-07 04:34:44 +02:00
|
|
|
assert.equal(list.selected_idx(), 1);
|
|
|
|
|
|
|
|
// Make sure not rerendered when reselected
|
2019-11-02 00:06:25 +01:00
|
|
|
let num_renders = 0;
|
2017-06-07 04:34:44 +02:00
|
|
|
list.rerender = function () {
|
|
|
|
num_renders += 1;
|
|
|
|
};
|
|
|
|
list.reselect_selected_id();
|
|
|
|
assert.equal(num_renders, 0);
|
|
|
|
assert.equal(list.selected_id(), 60);
|
2013-08-06 21:30:31 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const old_messages = [
|
2013-08-06 21:30:31 +02:00
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 30,
|
2013-08-06 21:30:31 +02:00
|
|
|
},
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 40,
|
|
|
|
},
|
2013-08-06 21:30:31 +02:00
|
|
|
];
|
2018-05-13 22:46:25 +02:00
|
|
|
list.add_messages(old_messages);
|
2013-08-06 21:30:31 +02:00
|
|
|
assert.equal(list.first().id, 30);
|
|
|
|
assert.equal(list.last().id, 80);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_messages = [
|
2013-08-06 21:30:31 +02:00
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 90,
|
|
|
|
},
|
2013-08-06 21:30:31 +02:00
|
|
|
];
|
|
|
|
list.append(new_messages, true);
|
|
|
|
assert.equal(list.last().id, 90);
|
|
|
|
|
2013-08-16 17:10:22 +02:00
|
|
|
list.view.clear_table = function () {};
|
2013-12-17 20:50:11 +01:00
|
|
|
|
2020-11-12 22:03:45 +01:00
|
|
|
list.remove_and_rerender([60]);
|
2020-07-02 01:45:54 +02:00
|
|
|
const removed = list.all_messages().filter((msg) => msg.id !== 60);
|
2016-04-23 00:56:44 +02:00
|
|
|
assert.deepEqual(list.all_messages(), removed);
|
2013-12-17 20:50:11 +01:00
|
|
|
|
2013-08-06 21:30:31 +02:00
|
|
|
list.clear();
|
2016-04-23 00:56:44 +02:00
|
|
|
assert.deepEqual(list.all_messages(), []);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-08-14 23:04:24 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("prev_next", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
2018-05-26 12:29:38 +02:00
|
|
|
|
2018-05-29 00:18:27 +02:00
|
|
|
assert.equal(list.prev(), undefined);
|
|
|
|
assert.equal(list.next(), undefined);
|
|
|
|
assert.equal(list.is_at_end(), false);
|
|
|
|
|
|
|
|
// try to confuse things with bogus selected id
|
|
|
|
list.data.set_selected_id(33);
|
|
|
|
assert.equal(list.prev(), undefined);
|
|
|
|
assert.equal(list.next(), undefined);
|
|
|
|
assert.equal(list.is_at_end(), false);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
|
2018-05-26 12:29:38 +02:00
|
|
|
list.append(messages, true);
|
|
|
|
assert.equal(list.prev(), undefined);
|
|
|
|
assert.equal(list.next(), undefined);
|
|
|
|
|
|
|
|
// The next case is for defensive code.
|
|
|
|
list.data.set_selected_id(45);
|
|
|
|
assert.equal(list.prev(), undefined);
|
|
|
|
assert.equal(list.next(), undefined);
|
2018-05-29 00:18:27 +02:00
|
|
|
assert.equal(list.is_at_end(), false);
|
2018-05-26 12:29:38 +02:00
|
|
|
|
|
|
|
list.data.set_selected_id(30);
|
|
|
|
assert.equal(list.prev(), undefined);
|
|
|
|
assert.equal(list.next(), 40);
|
|
|
|
|
|
|
|
list.data.set_selected_id(50);
|
|
|
|
assert.equal(list.prev(), 40);
|
|
|
|
assert.equal(list.next(), 60);
|
2018-05-29 00:18:27 +02:00
|
|
|
assert.equal(list.is_at_end(), false);
|
2018-05-26 12:29:38 +02:00
|
|
|
|
|
|
|
list.data.set_selected_id(60);
|
|
|
|
assert.equal(list.prev(), 50);
|
|
|
|
assert.equal(list.next(), undefined);
|
2018-05-29 00:18:27 +02:00
|
|
|
assert.equal(list.is_at_end(), true);
|
2018-05-26 12:29:38 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("message_range", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
2017-06-07 06:30:18 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
|
2017-06-07 06:30:18 +02:00
|
|
|
list.append(messages, true);
|
|
|
|
assert.deepEqual(list.message_range(2, 30), [{id: 30}]);
|
|
|
|
assert.deepEqual(list.message_range(2, 31), [{id: 30}, {id: 40}]);
|
|
|
|
assert.deepEqual(list.message_range(30, 40), [{id: 30}, {id: 40}]);
|
|
|
|
assert.deepEqual(list.message_range(31, 39), [{id: 40}]);
|
|
|
|
assert.deepEqual(list.message_range(31, 1000), [{id: 40}, {id: 50}, {id: 60}]);
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "message_range given a start of -1");
|
2018-05-17 00:11:54 +02:00
|
|
|
assert.deepEqual(list.message_range(-1, 40), [{id: 30}, {id: 40}]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-07 06:30:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("nth_most_recent_id", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
2018-12-18 19:34:45 +01:00
|
|
|
list.append([{id: 10}, {id: 20}, {id: 30}]);
|
2013-08-14 23:04:24 +02:00
|
|
|
assert.equal(list.nth_most_recent_id(1), 30);
|
|
|
|
assert.equal(list.nth_most_recent_id(2), 20);
|
|
|
|
assert.equal(list.nth_most_recent_id(3), 10);
|
|
|
|
assert.equal(list.nth_most_recent_id(4), -1);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-03-11 20:17:14 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("change_message_id", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
2020-07-15 00:34:28 +02:00
|
|
|
list.data._add_to_hash([
|
|
|
|
{id: 10.5, content: "good job"},
|
|
|
|
{id: 20.5, content: "ok!"},
|
|
|
|
]);
|
2018-05-17 00:11:54 +02:00
|
|
|
|
|
|
|
// local to local
|
|
|
|
list.change_message_id(10.5, 11.5);
|
|
|
|
assert.equal(list.get(11.5).content, "good job");
|
|
|
|
|
|
|
|
list.change_message_id(11.5, 11);
|
2017-06-07 08:05:30 +02:00
|
|
|
assert.equal(list.get(11).content, "good job");
|
|
|
|
|
|
|
|
list.change_message_id(20.5, 10);
|
|
|
|
assert.equal(list.get(10).content, "ok!");
|
2018-05-17 00:11:54 +02:00
|
|
|
|
|
|
|
// test nonexistent id
|
|
|
|
assert.equal(list.change_message_id(13, 15), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-03-11 20:17:14 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("last_sent_by_me", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
|
|
|
const items = [
|
2018-05-07 03:30:13 +02:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
sender_id: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
sender_id: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
sender_id: 6,
|
|
|
|
},
|
2017-06-07 08:11:01 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
list.append(items);
|
|
|
|
set_global("page_params", {user_id: 3});
|
|
|
|
// Look for the last message where user_id == 3 (our ID)
|
|
|
|
assert.equal(list.get_last_message_sent_by_me().id, 2);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-07 08:11:01 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("local_echo", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let list = new MessageList({});
|
2020-07-15 00:34:28 +02:00
|
|
|
list.append([
|
|
|
|
{id: 10},
|
|
|
|
{id: 20},
|
|
|
|
{id: 30},
|
|
|
|
{id: 20.02},
|
|
|
|
{id: 20.03},
|
|
|
|
{id: 40},
|
|
|
|
{id: 50},
|
|
|
|
{id: 60},
|
|
|
|
]);
|
2018-12-18 19:34:45 +01:00
|
|
|
list._local_only = {20.02: {id: 20.02}, 20.03: {id: 20.03}};
|
2014-03-11 20:17:14 +01:00
|
|
|
|
|
|
|
assert.equal(list.closest_id(10), 10);
|
|
|
|
assert.equal(list.closest_id(20), 20);
|
|
|
|
assert.equal(list.closest_id(30), 30);
|
|
|
|
assert.equal(list.closest_id(20.02), 20.02);
|
|
|
|
assert.equal(list.closest_id(20.03), 20.03);
|
|
|
|
assert.equal(list.closest_id(29), 30);
|
|
|
|
assert.equal(list.closest_id(40), 40);
|
|
|
|
assert.equal(list.closest_id(50), 50);
|
|
|
|
assert.equal(list.closest_id(60), 60);
|
|
|
|
|
|
|
|
assert.equal(list.closest_id(60), 60);
|
|
|
|
assert.equal(list.closest_id(21), 20);
|
|
|
|
assert.equal(list.closest_id(29), 30);
|
|
|
|
assert.equal(list.closest_id(31), 30);
|
|
|
|
assert.equal(list.closest_id(54), 50);
|
|
|
|
assert.equal(list.closest_id(58), 60);
|
|
|
|
|
2018-05-14 15:46:25 +02:00
|
|
|
list = new MessageList({});
|
2018-05-07 03:30:13 +02:00
|
|
|
list.append([
|
2020-07-15 00:34:28 +02:00
|
|
|
{id: 10},
|
|
|
|
{id: 20},
|
|
|
|
{id: 30},
|
|
|
|
{id: 20.02},
|
|
|
|
{id: 20.03},
|
|
|
|
{id: 40},
|
|
|
|
{id: 50},
|
|
|
|
{id: 50.01},
|
|
|
|
{id: 50.02},
|
|
|
|
{id: 60},
|
|
|
|
]);
|
|
|
|
list._local_only = {
|
|
|
|
20.02: {id: 20.02},
|
|
|
|
20.03: {id: 20.03},
|
|
|
|
50.01: {id: 50.01},
|
|
|
|
50.02: {id: 50.02},
|
|
|
|
};
|
2014-03-11 20:17:14 +01:00
|
|
|
|
|
|
|
assert.equal(list.closest_id(10), 10);
|
|
|
|
assert.equal(list.closest_id(20), 20);
|
|
|
|
assert.equal(list.closest_id(30), 30);
|
|
|
|
assert.equal(list.closest_id(20.02), 20.02);
|
|
|
|
assert.equal(list.closest_id(20.03), 20.03);
|
|
|
|
assert.equal(list.closest_id(40), 40);
|
|
|
|
assert.equal(list.closest_id(50), 50);
|
|
|
|
assert.equal(list.closest_id(60), 60);
|
|
|
|
|
|
|
|
assert.equal(list.closest_id(60), 60);
|
|
|
|
assert.equal(list.closest_id(21), 20);
|
|
|
|
assert.equal(list.closest_id(29), 30);
|
|
|
|
assert.equal(list.closest_id(31), 30);
|
|
|
|
assert.equal(list.closest_id(47), 50);
|
|
|
|
assert.equal(list.closest_id(51), 50.02);
|
|
|
|
assert.equal(list.closest_id(59), 60);
|
|
|
|
assert.equal(list.closest_id(50.01), 50.01);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-07 05:04:13 +02:00
|
|
|
|
2020-07-26 17:35:07 +02:00
|
|
|
run_test("bookend", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new MessageList({});
|
2017-06-07 05:04:13 +02:00
|
|
|
|
2020-07-26 17:35:07 +02:00
|
|
|
let expected = "translated: You subscribed to stream IceCream";
|
|
|
|
list.view.clear_trailing_bookend = noop;
|
|
|
|
list.narrowed = true;
|
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(narrow_state, "stream", () => "IceCream");
|
2020-07-26 17:35:07 +02:00
|
|
|
|
2021-02-11 15:26:25 +01:00
|
|
|
let is_subscribed = true;
|
|
|
|
let invite_only = false;
|
|
|
|
|
|
|
|
override(stream_data, "is_subscribed", () => is_subscribed);
|
|
|
|
override(stream_data, "get_sub", () => ({invite_only}));
|
2020-07-26 17:35:07 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-07-26 17:35:07 +02:00
|
|
|
list.view.render_trailing_bookend = stub.f;
|
|
|
|
list.update_trailing_bookend();
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-26 17:35:07 +02:00
|
|
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
|
|
|
assert.equal(bookend.content, expected);
|
|
|
|
assert.equal(bookend.subscribed, true);
|
|
|
|
assert.equal(bookend.show_button, true);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2020-07-26 17:35:07 +02:00
|
|
|
|
|
|
|
expected = "translated: You unsubscribed from stream IceCream";
|
|
|
|
list.last_message_historical = false;
|
2021-02-11 15:26:25 +01:00
|
|
|
|
|
|
|
is_subscribed = false;
|
2020-07-26 17:35:07 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-07-26 17:35:07 +02:00
|
|
|
list.view.render_trailing_bookend = stub.f;
|
|
|
|
list.update_trailing_bookend();
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-26 17:35:07 +02:00
|
|
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
|
|
|
assert.equal(bookend.content, expected);
|
|
|
|
assert.equal(bookend.subscribed, false);
|
|
|
|
assert.equal(bookend.show_button, true);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2020-07-26 17:35:07 +02:00
|
|
|
|
|
|
|
// Test when the stream is privates (invite only)
|
|
|
|
expected = "translated: You unsubscribed from stream IceCream";
|
|
|
|
|
2021-02-11 15:26:25 +01:00
|
|
|
invite_only = true;
|
2020-07-26 17:35:07 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-07-26 17:35:07 +02:00
|
|
|
list.view.render_trailing_bookend = stub.f;
|
|
|
|
list.update_trailing_bookend();
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-26 17:35:07 +02:00
|
|
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
|
|
|
assert.equal(bookend.content, expected);
|
|
|
|
assert.equal(bookend.subscribed, false);
|
|
|
|
assert.equal(bookend.show_button, false);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2020-07-26 17:35:07 +02:00
|
|
|
|
|
|
|
expected = "translated: You are not subscribed to stream IceCream";
|
|
|
|
list.last_message_historical = true;
|
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-07-26 17:35:07 +02:00
|
|
|
list.view.render_trailing_bookend = stub.f;
|
|
|
|
list.update_trailing_bookend();
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-26 17:35:07 +02:00
|
|
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
|
|
|
assert.equal(bookend.content, expected);
|
|
|
|
assert.equal(bookend.subscribed, false);
|
|
|
|
assert.equal(bookend.show_button, true);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-07 05:54:46 +02:00
|
|
|
|
2021-01-21 12:05:17 +01:00
|
|
|
run_test("filter_muted_topic_messages", () => {
|
2021-01-25 06:54:00 +01:00
|
|
|
const list = new MessageList({
|
|
|
|
excludes_muted_topics: true,
|
|
|
|
});
|
2021-01-21 12:05:17 +01:00
|
|
|
muting.add_muted_topic(1, "muted");
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const unmuted = [
|
2017-06-07 05:54:46 +02:00
|
|
|
{
|
|
|
|
id: 50,
|
2021-01-25 06:54:00 +01:00
|
|
|
type: "stream",
|
2021-01-21 12:05:17 +01:00
|
|
|
stream_id: 1,
|
2018-12-13 22:26:10 +01:00
|
|
|
mentioned: true, // overrides mute
|
2021-01-21 12:05:17 +01:00
|
|
|
topic: "muted",
|
2017-06-07 05:54:46 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 60,
|
2021-01-25 06:54:00 +01:00
|
|
|
type: "stream",
|
2021-01-21 12:05:17 +01:00
|
|
|
stream_id: 1,
|
2017-06-07 05:54:46 +02:00
|
|
|
mentioned: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "whatever",
|
2017-06-07 05:54:46 +02:00
|
|
|
},
|
|
|
|
];
|
2019-11-02 00:06:25 +01:00
|
|
|
const muted = [
|
2017-06-07 05:54:46 +02:00
|
|
|
{
|
|
|
|
id: 70,
|
2021-01-25 06:54:00 +01:00
|
|
|
type: "stream",
|
2021-01-21 12:05:17 +01:00
|
|
|
stream_id: 1,
|
2017-06-07 05:54:46 +02:00
|
|
|
mentioned: false,
|
2021-01-21 12:05:17 +01:00
|
|
|
topic: "muted",
|
2017-06-07 05:54:46 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-07-26 17:35:07 +02:00
|
|
|
// Make sure unmuted_message filters out the "muted" entry,
|
|
|
|
// which we mark as having a muted topic, and not mentioned.
|
|
|
|
const test_unmuted = list.unmuted_messages(unmuted.concat(muted));
|
|
|
|
assert.deepEqual(unmuted, test_unmuted);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-07 06:09:58 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("add_remove_rerender", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter = accept_all_filter();
|
2017-06-07 06:09:58 +02:00
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
const list = new MessageList({filter});
|
2017-06-07 06:09:58 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const messages = [{id: 1}, {id: 2}, {id: 3}];
|
2017-06-07 06:09:58 +02:00
|
|
|
|
2018-05-13 22:05:41 +02:00
|
|
|
list.add_messages(messages);
|
|
|
|
assert.equal(list.num_items(), 3);
|
2017-06-07 06:09:58 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2017-06-07 06:09:58 +02:00
|
|
|
list.rerender = stub.f;
|
2020-11-12 22:03:45 +01:00
|
|
|
const message_ids = messages.map((msg) => msg.id);
|
|
|
|
list.remove_and_rerender(message_ids);
|
2017-06-07 06:09:58 +02:00
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
assert.equal(list.num_items(), 0);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|