2018-04-11 22:16:30 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
zrequire('narrow_state');
|
|
|
|
zrequire('stream_data');
|
|
|
|
zrequire('Filter', 'js/filter');
|
2018-05-14 17:47:14 +02:00
|
|
|
zrequire('MessageListData', 'js/message_list_data');
|
2018-04-11 22:16:30 +02:00
|
|
|
zrequire('unread');
|
|
|
|
zrequire('narrow');
|
2018-07-14 16:10:00 +02:00
|
|
|
zrequire('search_pill');
|
2018-12-22 15:32:14 +01:00
|
|
|
zrequire('util');
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
set_global('blueslip', {});
|
|
|
|
set_global('channel', {});
|
2018-08-09 05:59:55 +02:00
|
|
|
set_global('compose', {});
|
2018-04-11 22:16:30 +02:00
|
|
|
set_global('compose_actions', {});
|
|
|
|
set_global('current_msg_list', {});
|
|
|
|
set_global('hashchange', {});
|
|
|
|
set_global('home_msg_list', {});
|
|
|
|
set_global('message_fetch', {});
|
2018-08-04 08:30:52 +02:00
|
|
|
set_global('message_list', {
|
|
|
|
set_narrowed: function (value) { this.narrowed = value; },
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
set_global('message_scroll', {});
|
|
|
|
set_global('message_util', {});
|
|
|
|
set_global('notifications', {});
|
|
|
|
set_global('page_params', {});
|
|
|
|
set_global('search', {});
|
|
|
|
set_global('stream_list', {});
|
2018-08-06 18:12:20 +02:00
|
|
|
set_global('tab_bar', {});
|
2018-04-11 22:16:30 +02:00
|
|
|
set_global('top_left_corner', {});
|
2018-08-06 18:09:51 +02:00
|
|
|
set_global('typing_events', {});
|
2018-04-11 22:16:30 +02:00
|
|
|
set_global('ui_util', {});
|
|
|
|
set_global('unread_ops', {});
|
2018-07-14 16:10:00 +02:00
|
|
|
set_global('search_pill_widget', {
|
2018-07-23 02:20:57 +02:00
|
|
|
widget: {
|
2018-07-14 16:10:00 +02:00
|
|
|
clear: function () {return true;},
|
|
|
|
appendValue: function () {return true;},
|
|
|
|
},
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
var noop = () => {};
|
|
|
|
//
|
|
|
|
// We have strange hacks in narrow.activate to sleep 0
|
|
|
|
// seconds.
|
|
|
|
global.patch_builtin('setTimeout', (f, t) => {
|
|
|
|
assert.equal(t, 0);
|
|
|
|
f();
|
|
|
|
});
|
|
|
|
|
2018-05-14 19:57:46 +02:00
|
|
|
set_global('muting', {
|
|
|
|
is_topic_muted: () => false,
|
|
|
|
});
|
|
|
|
|
2018-04-11 22:16:30 +02:00
|
|
|
var denmark = {
|
|
|
|
subscribed: false,
|
|
|
|
color: 'blue',
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 1,
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: true,
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
stream_data.add_sub('Denmark', denmark);
|
|
|
|
|
|
|
|
function test_helper() {
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
function stub(module_name, func_name) {
|
|
|
|
global[module_name][func_name] = () => {
|
|
|
|
events.push(module_name + '.' + func_name);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
stub('compose_actions', 'on_narrow');
|
|
|
|
stub('hashchange', 'save_narrow');
|
|
|
|
stub('message_scroll', 'hide_indicators');
|
2018-08-13 23:17:45 +02:00
|
|
|
stub('message_scroll', 'show_loading_older');
|
2018-04-11 22:16:30 +02:00
|
|
|
stub('notifications', 'clear_compose_notifications');
|
|
|
|
stub('notifications', 'redraw_title');
|
|
|
|
stub('search', 'update_button_visibility');
|
|
|
|
stub('stream_list', 'handle_narrow_activated');
|
2018-08-06 18:12:20 +02:00
|
|
|
stub('tab_bar', 'initialize');
|
2018-04-11 22:16:30 +02:00
|
|
|
stub('top_left_corner', 'handle_narrow_activated');
|
2018-08-06 18:09:51 +02:00
|
|
|
stub('typing_events', 'render_notifications_for_narrow');
|
2018-04-11 22:16:30 +02:00
|
|
|
stub('ui_util', 'change_tab_to');
|
|
|
|
stub('unread_ops', 'process_visible');
|
2019-03-06 23:46:53 +01:00
|
|
|
stub('compose', 'update_closed_compose_buttons_for_stream');
|
|
|
|
stub('compose', 'update_closed_compose_buttons_for_private');
|
2018-10-01 20:27:22 +02:00
|
|
|
stub('notifications', 'hide_history_limit_message');
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
blueslip.debug = noop;
|
|
|
|
|
|
|
|
return {
|
|
|
|
clear: () => {
|
|
|
|
events = [];
|
|
|
|
},
|
|
|
|
push_event: (event) => {
|
|
|
|
events.push(event);
|
|
|
|
},
|
|
|
|
assert_events: (expected_events) => {
|
|
|
|
assert.deepEqual(expected_events, events);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function stub_message_list() {
|
2018-05-14 15:46:25 +02:00
|
|
|
message_list.MessageList = function (opts) {
|
2018-05-03 04:33:06 +02:00
|
|
|
var list = this;
|
2018-05-14 19:57:46 +02:00
|
|
|
this.data = opts.data;
|
2018-05-03 04:33:06 +02:00
|
|
|
this.view = {
|
|
|
|
set_message_offset: function (offset) {
|
|
|
|
list.view.offset = offset;
|
|
|
|
},
|
|
|
|
};
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
message_list.MessageList.prototype = {
|
2018-05-03 04:33:06 +02:00
|
|
|
get: function (msg_id) {
|
2018-05-14 19:57:46 +02:00
|
|
|
return this.data.get(msg_id);
|
2018-04-11 22:16:30 +02:00
|
|
|
},
|
|
|
|
|
2018-05-03 04:33:06 +02:00
|
|
|
empty: function () {
|
2018-05-14 19:57:46 +02:00
|
|
|
return this.data.empty();
|
2018-04-11 22:16:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
select_id: function (msg_id) {
|
|
|
|
this.selected_id = msg_id;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basics', () => {
|
2018-04-11 22:16:30 +02:00
|
|
|
stub_message_list();
|
|
|
|
|
|
|
|
var helper = test_helper();
|
|
|
|
var terms = [
|
|
|
|
{ operator: 'stream', operand: 'Denmark' },
|
|
|
|
];
|
|
|
|
|
|
|
|
var selected_id = 1000;
|
|
|
|
|
|
|
|
var selected_message = {
|
|
|
|
id: selected_id,
|
|
|
|
type: 'stream',
|
|
|
|
stream_id: denmark.stream_id,
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'whatever',
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var messages = [selected_message];
|
|
|
|
|
2018-05-03 04:33:06 +02:00
|
|
|
var row = {
|
|
|
|
length: 1,
|
|
|
|
offset: () => { return {top: 25}; },
|
|
|
|
};
|
|
|
|
|
2018-04-11 22:16:30 +02:00
|
|
|
current_msg_list.selected_id = () => { return -1; };
|
2018-05-03 04:33:06 +02:00
|
|
|
current_msg_list.get_row = () => { return row; };
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
message_list.all = {
|
|
|
|
all_messages: () => {
|
|
|
|
return messages;
|
|
|
|
},
|
|
|
|
get: (msg_id) => {
|
2018-05-03 04:33:06 +02:00
|
|
|
assert.equal(msg_id, selected_id);
|
2018-04-11 22:16:30 +02:00
|
|
|
return selected_message;
|
|
|
|
},
|
2018-06-01 01:07:45 +02:00
|
|
|
fetch_status: {
|
|
|
|
has_found_newest: () => true,
|
|
|
|
},
|
|
|
|
empty: () => false,
|
|
|
|
first: () => {
|
|
|
|
return {id: 900};
|
|
|
|
},
|
|
|
|
last: () => {
|
|
|
|
return {id: 1100};
|
|
|
|
},
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var cont;
|
|
|
|
|
|
|
|
message_fetch.load_messages_for_narrow = (opts) => {
|
|
|
|
cont = opts.cont;
|
|
|
|
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
cont: opts.cont,
|
2018-05-03 04:33:06 +02:00
|
|
|
then_select_id: 1000,
|
|
|
|
use_first_unread_anchor: false,
|
2018-04-11 22:16:30 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-05-03 04:33:06 +02:00
|
|
|
narrow.activate(terms, {
|
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
assert.equal(message_list.narrowed.selected_id, selected_id);
|
2018-05-03 04:33:06 +02:00
|
|
|
assert.equal(message_list.narrowed.view.offset, 25);
|
2018-08-13 23:17:45 +02:00
|
|
|
assert.equal(narrow_state.narrowed_to_pms(), false);
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
helper.assert_events([
|
|
|
|
'notifications.clear_compose_notifications',
|
|
|
|
'notifications.redraw_title',
|
2018-10-01 20:27:22 +02:00
|
|
|
'notifications.hide_history_limit_message',
|
2018-04-11 22:16:30 +02:00
|
|
|
'ui_util.change_tab_to',
|
|
|
|
'message_scroll.hide_indicators',
|
|
|
|
'unread_ops.process_visible',
|
|
|
|
'hashchange.save_narrow',
|
2019-03-06 23:46:53 +01:00
|
|
|
'compose.update_closed_compose_buttons_for_stream',
|
2018-04-11 22:16:30 +02:00
|
|
|
'search.update_button_visibility',
|
|
|
|
'compose_actions.on_narrow',
|
|
|
|
'top_left_corner.handle_narrow_activated',
|
|
|
|
'stream_list.handle_narrow_activated',
|
2018-08-06 18:09:51 +02:00
|
|
|
'typing_events.render_notifications_for_narrow',
|
2018-08-06 18:12:20 +02:00
|
|
|
'tab_bar.initialize',
|
2018-04-11 22:16:30 +02:00
|
|
|
]);
|
|
|
|
|
2018-08-13 23:17:45 +02:00
|
|
|
current_msg_list.selected_id = () => { return -1; };
|
|
|
|
current_msg_list.get_row = () => { return row; };
|
|
|
|
util.sorted_ids = () => { return []; };
|
|
|
|
|
|
|
|
narrow.activate([{ operator: 'is', operand: 'private' }], {
|
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(narrow_state.narrowed_to_pms(), true);
|
|
|
|
|
2018-04-11 22:16:30 +02:00
|
|
|
channel.post = (opts) => {
|
|
|
|
assert.equal(opts.url, '/json/report/narrow_times');
|
|
|
|
helper.push_event('report narrow times');
|
|
|
|
};
|
|
|
|
|
|
|
|
helper.clear();
|
|
|
|
cont();
|
|
|
|
helper.assert_events([
|
|
|
|
'report narrow times',
|
|
|
|
]);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|