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', {});
|
2017-08-09 19:30:10 +02:00
|
|
|
set_global('stream_data', {});
|
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', {});
|
2017-08-09 19:30:10 +02:00
|
|
|
set_global('templates', {});
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
zrequire('hash_util');
|
|
|
|
zrequire('narrow');
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('topic_list_build_widget', () => {
|
2017-05-14 15:39:02 +02:00
|
|
|
var stream_id = 555;
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
|
|
|
topic_data.add_message({
|
|
|
|
stream_id: stream_id,
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
stream_data.get_sub_by_id = function (stream_id) {
|
2017-05-14 18:06:57 +02:00
|
|
|
assert.equal(stream_id, 555);
|
2017-08-09 19:30:10 +02:00
|
|
|
return {
|
|
|
|
name: 'devel',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var checked_mutes;
|
|
|
|
var rendered;
|
|
|
|
|
|
|
|
templates.render = function (name, info) {
|
|
|
|
assert.equal(name, 'topic_list_item');
|
|
|
|
var expected = {
|
|
|
|
topic_name: 'coding',
|
|
|
|
unread: 3,
|
|
|
|
is_zero: false,
|
|
|
|
is_muted: false,
|
|
|
|
url: '#narrow/stream/devel/subject/coding',
|
|
|
|
};
|
|
|
|
assert.deepEqual(info, expected);
|
|
|
|
rendered = true;
|
|
|
|
return '<topic list item>';
|
|
|
|
};
|
|
|
|
|
|
|
|
muting.is_topic_muted = function (stream_name, topic_name) {
|
|
|
|
assert.equal(stream_name, 'devel');
|
|
|
|
assert.equal(topic_name, 'coding');
|
|
|
|
checked_mutes = true;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
var ul = $('<ul class="topic-list">');
|
|
|
|
|
2017-08-10 12:58:11 +02:00
|
|
|
var 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
|
|
|
};
|
|
|
|
|
|
|
|
var parent_elem = $.create('parent_elem');
|
|
|
|
var attached_to_parent;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-09-21 20:44:31 +02:00
|
|
|
var widget = topic_list.widget(parent_elem, stream_id);
|
|
|
|
|
|
|
|
widget.build_more_topics_section = function () {
|
|
|
|
return $('<more topics>');
|
|
|
|
};
|
|
|
|
|
|
|
|
widget.build();
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2017-08-09 19:30:10 +02:00
|
|
|
assert(widget.is_for_stream(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
|
|
|
});
|