2017-08-09 19:30:10 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2017-08-10 12:58:11 +02:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-08-11 01:23:16 +02:00
|
|
|
set_global('narrow_state', {});
|
2016-11-05 16:36:30 +01:00
|
|
|
set_global('unread', {});
|
2017-08-09 19:30:10 +02:00
|
|
|
set_global('muting', {});
|
2017-08-11 01:23:16 +02:00
|
|
|
set_global('stream_popover', {});
|
2019-03-13 13:47:57 +01:00
|
|
|
set_global('message_list', {});
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
zrequire('hash_util');
|
2018-02-15 21:02:47 +01:00
|
|
|
zrequire('stream_data');
|
2018-05-13 12:17:00 +02:00
|
|
|
zrequire('unread');
|
2017-08-09 19:30:10 +02:00
|
|
|
zrequire('topic_data');
|
|
|
|
zrequire('topic_list');
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const devel = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 555,
|
|
|
|
name: 'devel',
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_data.add_sub('devel', devel);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('topic_list_build_widget', () => {
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
|
|
|
topic_data.add_message({
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: devel.stream_id,
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_name: 'coding',
|
|
|
|
message_id: 400,
|
|
|
|
});
|
|
|
|
|
2017-08-11 01:23:16 +02:00
|
|
|
stream_popover.hide_topic_popover = function () {};
|
|
|
|
|
|
|
|
narrow_state.topic = function () {
|
|
|
|
return 'testing';
|
|
|
|
};
|
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
unread.num_unread_for_topic = function () {
|
|
|
|
return 3;
|
2016-11-05 16:36:30 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let checked_mutes;
|
|
|
|
let rendered;
|
2017-08-09 19:30:10 +02:00
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (name, info) {
|
2017-08-09 19:30:10 +02:00
|
|
|
assert.equal(name, 'topic_list_item');
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected = {
|
2017-08-09 19:30:10 +02:00
|
|
|
topic_name: 'coding',
|
|
|
|
unread: 3,
|
|
|
|
is_zero: false,
|
|
|
|
is_muted: false,
|
2018-12-22 23:04:23 +01:00
|
|
|
url: '#narrow/stream/555-devel/topic/coding',
|
2017-08-09 19:30:10 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(info, expected);
|
|
|
|
rendered = true;
|
|
|
|
return '<topic list item>';
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-08-09 19:30:10 +02:00
|
|
|
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.is_topic_muted = function (stream_id, topic_name) {
|
|
|
|
assert.equal(stream_id, devel.stream_id);
|
2017-08-09 19:30:10 +02:00
|
|
|
assert.equal(topic_name, 'coding');
|
|
|
|
checked_mutes = true;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const ul = $('<ul class="topic-list">');
|
2017-08-09 19:30:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const list_items = [];
|
2017-08-09 19:30:10 +02:00
|
|
|
|
|
|
|
ul.append = function (item) {
|
2017-08-10 12:58:11 +02:00
|
|
|
list_items.push(item);
|
2017-08-09 19:30:10 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const parent_elem = $.create('parent_elem');
|
|
|
|
let attached_to_parent;
|
2017-08-09 19:30:10 +02:00
|
|
|
|
|
|
|
parent_elem.append = function (child) {
|
|
|
|
assert.equal(child, ul);
|
|
|
|
attached_to_parent = true;
|
2017-05-14 18:06:57 +02:00
|
|
|
};
|
2017-05-13 19:26:54 +02:00
|
|
|
|
2017-08-11 00:29:35 +02:00
|
|
|
assert.equal(topic_list.active_stream_id(), undefined);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const widget = topic_list.widget(parent_elem, devel.stream_id);
|
2017-09-21 20:44:31 +02:00
|
|
|
|
|
|
|
widget.build_more_topics_section = function () {
|
|
|
|
return $('<more topics>');
|
|
|
|
};
|
|
|
|
|
|
|
|
widget.build();
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2019-03-09 16:32:41 +01:00
|
|
|
assert(widget.get_stream_id(), devel.stream_id);
|
2016-11-10 20:05:14 +01:00
|
|
|
assert.equal(widget.get_parent(), parent_elem);
|
2016-11-05 16:54:57 +01:00
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
assert(checked_mutes);
|
|
|
|
assert(rendered);
|
2017-08-10 12:58:11 +02:00
|
|
|
assert.equal(list_items[0].html(), '<topic list item>');
|
2017-09-21 20:44:31 +02:00
|
|
|
assert.equal(list_items[1].html(), '<more topics>');
|
2017-08-09 19:30:10 +02:00
|
|
|
assert(attached_to_parent);
|
2017-08-11 00:29:35 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|