2016-08-05 21:44:51 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
var _ = global._;
|
|
|
|
|
|
|
|
var noop = function () {};
|
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
set_global('document', 'document-stub');
|
|
|
|
set_global('$', function () {
|
|
|
|
return {
|
|
|
|
trigger: noop,
|
|
|
|
};
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
// These dependencies are closer to the dispatcher, and they
|
|
|
|
// apply to all tests.
|
|
|
|
set_global('home_msg_list', {
|
2017-03-02 07:29:01 +01:00
|
|
|
rerender: noop,
|
2016-08-05 21:44:51 +02:00
|
|
|
select_id: noop,
|
2016-12-03 23:17:57 +01:00
|
|
|
selected_id: function () {return 1;},
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
set_global('echo', {
|
|
|
|
process_from_server: function (messages) {
|
|
|
|
return messages;
|
|
|
|
},
|
2017-05-09 18:01:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
set_global('markdown', {
|
2016-12-03 23:17:57 +01:00
|
|
|
set_realm_filters: noop,
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-07-18 02:58:13 +02:00
|
|
|
set_global('notifications', {
|
|
|
|
redraw_title: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('settings_emoji', {
|
|
|
|
update_custom_emoji_ui: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('settings_org', {
|
|
|
|
reset_realm_default_language: noop,
|
|
|
|
toggle_email_change_display: noop,
|
|
|
|
toggle_name_change_display: noop,
|
|
|
|
update_message_retention_days: noop,
|
2017-07-19 23:45:53 +02:00
|
|
|
update_realm_description: noop,
|
2017-07-18 02:58:13 +02:00
|
|
|
});
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
// page_params is highly coupled to dispatching now
|
|
|
|
set_global('page_params', {test_suite: false});
|
|
|
|
var page_params = global.page_params;
|
|
|
|
|
|
|
|
// alert_words is coupled to dispatching in the sense
|
|
|
|
// that we write directly to alert_words.words
|
|
|
|
add_dependencies({alert_words: 'js/alert_words.js'});
|
|
|
|
|
2017-05-31 08:53:09 +02:00
|
|
|
// contains the main event dispatching function
|
|
|
|
add_dependencies({server_events_dispatch: 'js/server_events_dispatch.js'});
|
|
|
|
|
2017-03-02 07:29:01 +01:00
|
|
|
// We access various msg_list object to rerender them
|
|
|
|
set_global('current_msg_list', {rerender: noop});
|
|
|
|
|
2017-03-11 20:27:54 +01:00
|
|
|
// We use blueslip to print the traceback
|
|
|
|
set_global('blueslip', {
|
|
|
|
error: function (msg, more_info, stack) {
|
|
|
|
console.log("\nFailed to process an event:\n", more_info.event, "\n");
|
|
|
|
var error = new Error();
|
|
|
|
error.stack = stack;
|
|
|
|
throw error;
|
|
|
|
},
|
|
|
|
exception_msg: function (ex) {
|
|
|
|
return ex.message;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
var sed = require('js/server_events_dispatch.js');
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
function dispatch(ev) {
|
2017-07-01 14:21:20 +02:00
|
|
|
sed.dispatch_normal_event(ev);
|
2016-08-05 21:44:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: These events are not guaranteed to be perfectly
|
|
|
|
// representative of what the server sends. For
|
|
|
|
// now we just want very basic test coverage. We
|
|
|
|
// have more mature tests for events on the backend
|
|
|
|
// side in test_events.py, and we may be able to
|
|
|
|
// re-work both sides (js/python) so that we work off
|
|
|
|
// a shared fixture.
|
|
|
|
var event_fixtures = {
|
|
|
|
alert_words: {
|
|
|
|
type: 'alert_words',
|
2016-12-03 23:17:57 +01:00
|
|
|
alert_words: ['fire', 'lunch'],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
default_streams: {
|
|
|
|
type: 'default_streams',
|
|
|
|
default_streams: [
|
|
|
|
{
|
|
|
|
name: 'devel',
|
|
|
|
description: 'devel',
|
|
|
|
invite_only: false,
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 1,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
description: 'test',
|
|
|
|
invite_only: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 1,
|
|
|
|
},
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-05-31 06:34:53 +02:00
|
|
|
hotspots: {
|
|
|
|
type: 'hotspots',
|
|
|
|
hotspots: ['nice', 'chicken'],
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
muted_topics: {
|
|
|
|
type: 'muted_topics',
|
2016-12-03 23:17:57 +01:00
|
|
|
muted_topics: [['devel', 'js'], ['lunch', 'burritos']],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
presence: {
|
|
|
|
type: 'presence',
|
|
|
|
email: 'alice@example.com',
|
|
|
|
presence: {
|
|
|
|
client_name: 'electron',
|
2016-12-03 23:17:57 +01:00
|
|
|
is_mirror_dummy: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
|
|
|
},
|
2016-12-03 23:17:57 +01:00
|
|
|
server_timestamp: 999999,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-05-31 06:37:52 +02:00
|
|
|
reaction__add: {
|
|
|
|
type: 'reaction',
|
|
|
|
op: 'add',
|
|
|
|
message_id: 128,
|
|
|
|
emoji_name: 'anguished_pig',
|
|
|
|
},
|
|
|
|
|
|
|
|
reaction__remove: {
|
|
|
|
type: 'reaction',
|
|
|
|
op: 'remove',
|
|
|
|
message_id: 256,
|
|
|
|
emoji_name: 'angery',
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
// Please keep this next section un-nested, as we want this to partly
|
|
|
|
// be simple documentation on the formats of individual events.
|
|
|
|
realm__update__create_stream_by_admins_only: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'create_stream_by_admins_only',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm__update__invite_by_admins_only: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'invite_by_admins_only',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm__update__invite_required: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'invite_required',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm__update__name: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'name',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: 'new_realm_name',
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm__update__restricted_to_domain: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'restricted_to_domain',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm__update_dict__default: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update_dict',
|
|
|
|
property: 'default',
|
|
|
|
data: {
|
2016-12-03 03:08:47 +01:00
|
|
|
allow_message_editing: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
message_content_edit_limit_seconds: 5,
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_bot__add: {
|
|
|
|
type: 'realm_bot',
|
|
|
|
op: 'add',
|
|
|
|
bot: {
|
|
|
|
email: 'the-bot@example.com',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'The Bot',
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_bot__remove: {
|
|
|
|
type: 'realm_bot',
|
|
|
|
op: 'remove',
|
|
|
|
bot: {
|
|
|
|
email: 'the-bot@example.com',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'The Bot',
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_bot__update: {
|
|
|
|
type: 'realm_bot',
|
|
|
|
op: 'update',
|
|
|
|
bot: {
|
|
|
|
email: 'the-bot@example.com',
|
2017-02-15 00:45:38 +01:00
|
|
|
user_id: 4321,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'The Bot Has A New Name',
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_emoji: {
|
|
|
|
type: 'realm_emoji',
|
|
|
|
realm_emoji: {
|
2016-12-03 03:08:47 +01:00
|
|
|
airplane: {
|
2016-12-03 23:17:57 +01:00
|
|
|
display_url: 'some_url',
|
|
|
|
},
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_filters: {
|
|
|
|
type: 'realm_filters',
|
|
|
|
realm_filters: [
|
2016-12-03 23:17:57 +01:00
|
|
|
['#[123]', 'ticket %(id)s'],
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-05-31 07:02:00 +02:00
|
|
|
realm_domains__add: {
|
|
|
|
type: 'realm_domains',
|
|
|
|
op: 'add',
|
|
|
|
realm_domain: {
|
|
|
|
domain: 'ramen',
|
|
|
|
allow_subdomains: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
realm_domains__change: {
|
|
|
|
type: 'realm_domains',
|
|
|
|
op: 'change',
|
|
|
|
realm_domain: {
|
|
|
|
domain: 'ramen',
|
|
|
|
allow_subdomains: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
realm_domains__remove: {
|
|
|
|
type: 'realm_domains',
|
|
|
|
op: 'remove',
|
|
|
|
domain: 'ramen',
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
realm_user__add: {
|
|
|
|
type: 'realm_user',
|
|
|
|
op: 'add',
|
|
|
|
person: {
|
|
|
|
email: 'alice@example.com',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice User',
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_user__remove: {
|
|
|
|
type: 'realm_user',
|
|
|
|
op: 'remove',
|
|
|
|
person: {
|
|
|
|
email: 'alice@example.com',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice User',
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
realm_user__update: {
|
|
|
|
type: 'realm_user',
|
|
|
|
op: 'update',
|
|
|
|
person: {
|
|
|
|
email: 'alice@example.com',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice NewName',
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
restart: {
|
|
|
|
type: 'restart',
|
2016-12-03 23:17:57 +01:00
|
|
|
immediate: true,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
stream: {
|
|
|
|
type: 'stream',
|
|
|
|
op: 'update',
|
|
|
|
name: 'devel',
|
2017-03-05 02:17:29 +01:00
|
|
|
stream_id: 99,
|
2016-08-05 21:44:51 +02:00
|
|
|
property: 'color',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: 'blue',
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
subscription__add: {
|
|
|
|
type: 'subscription',
|
|
|
|
op: 'add',
|
|
|
|
subscriptions: [
|
|
|
|
{
|
|
|
|
name: 'devel',
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 42,
|
2017-03-05 00:09:48 +01:00
|
|
|
subscribers: ['alice@example.com', 'bob@example.com'],
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
subscription__remove: {
|
|
|
|
type: 'subscription',
|
|
|
|
op: 'remove',
|
|
|
|
subscriptions: [
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 42,
|
|
|
|
},
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
subscription__peer_add: {
|
|
|
|
type: 'subscription',
|
|
|
|
op: 'peer_add',
|
2016-10-31 20:18:32 +01:00
|
|
|
user_id: 555,
|
2016-08-05 21:44:51 +02:00
|
|
|
subscriptions: [
|
|
|
|
{
|
|
|
|
name: 'devel',
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 42,
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
subscription__peer_remove: {
|
|
|
|
type: 'subscription',
|
|
|
|
op: 'peer_remove',
|
2016-11-08 15:04:18 +01:00
|
|
|
user_id: 555,
|
2016-08-05 21:44:51 +02:00
|
|
|
subscriptions: [
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
stream_id: 42,
|
2016-08-05 21:44:51 +02:00
|
|
|
// etc.
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
|
|
|
],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
subscription__update: {
|
|
|
|
type: 'subscription',
|
|
|
|
op: 'update',
|
|
|
|
name: 'devel',
|
2017-03-05 02:17:29 +01:00
|
|
|
stream_id: 43,
|
2016-08-05 21:44:51 +02:00
|
|
|
property: 'color',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: 'black',
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-05-31 07:48:38 +02:00
|
|
|
typing__start: {
|
|
|
|
type: 'typing',
|
|
|
|
sender: {
|
|
|
|
user_id: 4,
|
|
|
|
},
|
|
|
|
op: 'start',
|
|
|
|
},
|
|
|
|
|
|
|
|
typing__stop: {
|
|
|
|
type: 'typing',
|
|
|
|
sender: {
|
|
|
|
user_id: 6,
|
|
|
|
},
|
|
|
|
op: 'stop',
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
update_display_settings__default_language: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'default_language',
|
2016-12-08 21:09:41 +01:00
|
|
|
setting: 'fr',
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update_display_settings__left_side_userlist: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'left_side_userlist',
|
2016-12-08 21:09:41 +01:00
|
|
|
setting: true,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-03-02 08:30:53 +01:00
|
|
|
update_display_settings__emoji_alt_code: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'emoji_alt_code',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
update_display_settings__twenty_four_hour_time: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'twenty_four_hour_time',
|
2016-12-08 21:09:41 +01:00
|
|
|
setting: true,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2017-07-07 18:15:10 +02:00
|
|
|
update_display_settings__high_contrast_mode: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'high_contrast_mode',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
update_global_notifications: {
|
|
|
|
type: 'update_global_notifications',
|
|
|
|
notification_name: 'enable_stream_sounds',
|
2016-12-03 23:17:57 +01:00
|
|
|
setting: true,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update_message_flags__read: {
|
|
|
|
type: 'update_message_flags',
|
|
|
|
operation: 'add',
|
|
|
|
flag: 'read',
|
2017-03-11 19:18:57 +01:00
|
|
|
messages: [999],
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
update_message_flags__starred: {
|
|
|
|
type: 'update_message_flags',
|
|
|
|
operation: 'add',
|
|
|
|
flag: 'starred',
|
2017-03-11 19:18:57 +01:00
|
|
|
messages: [99],
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2017-05-31 07:20:28 +02:00
|
|
|
|
|
|
|
delete_message: {
|
|
|
|
type: 'delete_message',
|
|
|
|
message_id: 1337,
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function assert_same(actual, expected) {
|
|
|
|
// This helper prevents us from getting false positives
|
|
|
|
// where actual and expected are both undefined.
|
|
|
|
assert(expected);
|
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
}
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
var with_overrides = global.with_overrides; // make lint happy
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2017-06-07 21:36:43 +02:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// alert_words
|
2017-06-07 21:36:43 +02:00
|
|
|
override('alert_words_ui.render_alert_words_ui', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
var event = event_fixtures.alert_words;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(global.alert_words.words, ['fire', 'lunch']);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// default_streams
|
|
|
|
var event = event_fixtures.default_streams;
|
2017-04-08 21:02:08 +02:00
|
|
|
override('settings_streams.update_default_streams_table', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_default_streams, event.default_streams);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-05-31 06:34:53 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// hotspots
|
|
|
|
var event = event_fixtures.hotspots;
|
2017-07-14 03:21:30 +02:00
|
|
|
override('hotspots.load_new', noop);
|
2017-05-31 06:34:53 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.hotspots, event.hotspots);
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// muted_topics
|
|
|
|
var event = event_fixtures.muted_topics;
|
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('muting_ui.handle_updates', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('muted_topics');
|
|
|
|
assert_same(args.muted_topics, event.muted_topics);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// presence
|
|
|
|
var event = event_fixtures.presence;
|
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('activity.set_user_status', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('email', 'presence', 'server_time');
|
|
|
|
assert_same(args.email, 'alice@example.com');
|
|
|
|
assert_same(args.presence, event.presence);
|
|
|
|
assert_same(args.server_time, event.server_timestamp);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-05-31 06:37:52 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// reaction
|
|
|
|
var event = event_fixtures.reaction__add;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('reactions.add_reaction', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('event');
|
|
|
|
assert_same(args.event.emoji_name, event.emoji_name);
|
|
|
|
assert_same(args.event.message_id, event.message_id);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.reaction__remove;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('reactions.remove_reaction', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('event');
|
|
|
|
assert_same(args.event.emoji_name, event.emoji_name);
|
|
|
|
assert_same(args.event.message_id, event.message_id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm
|
|
|
|
function test_realm_boolean(event, parameter_name) {
|
|
|
|
page_params[parameter_name] = true;
|
|
|
|
event = _.clone(event);
|
|
|
|
event.value = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], false);
|
|
|
|
event = _.clone(event);
|
|
|
|
event.value = true;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
var event = event_fixtures.realm__update__create_stream_by_admins_only;
|
|
|
|
test_realm_boolean(event, 'realm_create_stream_by_admins_only');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update__invite_by_admins_only;
|
|
|
|
test_realm_boolean(event, 'realm_invite_by_admins_only');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update__invite_required;
|
|
|
|
test_realm_boolean(event, 'realm_invite_required');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update__name;
|
2017-03-11 17:19:19 +01:00
|
|
|
override('notifications.redraw_title', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_name, 'new_realm_name');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update__restricted_to_domain;
|
|
|
|
test_realm_boolean(event, 'realm_restricted_to_domain');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update_dict__default;
|
|
|
|
page_params.realm_allow_message_editing = false;
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 0;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_allow_message_editing, true);
|
|
|
|
assert_same(page_params.realm_message_content_edit_limit_seconds, 5);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm_bot
|
|
|
|
var event = event_fixtures.realm_bot__add;
|
2017-03-10 09:23:59 +01:00
|
|
|
global.with_stub(function (bot_stub) {
|
|
|
|
global.with_stub(function (admin_stub) {
|
|
|
|
override('bot_data.add', bot_stub.f);
|
2017-04-08 20:08:35 +02:00
|
|
|
override('settings_users.update_user_data', admin_stub.f);
|
2017-03-10 09:23:59 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = bot_stub.get_args('bot');
|
|
|
|
assert_same(args.bot, event.bot);
|
|
|
|
|
|
|
|
args = admin_stub.get_args('update_user_id', 'update_bot_data');
|
|
|
|
});
|
2017-03-11 19:18:57 +01:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_bot__remove;
|
2017-03-10 09:23:59 +01:00
|
|
|
global.with_stub(function (bot_stub) {
|
|
|
|
global.with_stub(function (admin_stub) {
|
|
|
|
override('bot_data.deactivate', bot_stub.f);
|
2017-04-08 20:08:35 +02:00
|
|
|
override('settings_users.update_user_data', admin_stub.f);
|
2017-03-10 09:23:59 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = bot_stub.get_args('email');
|
|
|
|
assert_same(args.email, event.bot.email);
|
|
|
|
|
|
|
|
args = admin_stub.get_args('update_user_id', 'update_bot_data');
|
|
|
|
});
|
2017-03-11 19:18:57 +01:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_bot__update;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (bot_stub) {
|
|
|
|
global.with_stub(function (admin_stub) {
|
|
|
|
override('bot_data.update', bot_stub.f);
|
2017-04-08 20:08:35 +02:00
|
|
|
override('settings_users.update_user_data', admin_stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
var args = bot_stub.get_args('email', 'bot');
|
|
|
|
assert_same(args.email, event.bot.email);
|
|
|
|
assert_same(args.bot, event.bot);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
args = admin_stub.get_args('update_user_id', 'update_bot_data');
|
|
|
|
assert_same(args.update_user_id, event.bot.user_id);
|
|
|
|
assert_same(args.update_bot_data, event.bot);
|
|
|
|
});
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm_emoji
|
|
|
|
var event = event_fixtures.realm_emoji;
|
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('emoji.update_emojis', stub.f);
|
2017-04-08 17:24:07 +02:00
|
|
|
override('settings_emoji.populate_emoji', noop);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('realm_emoji');
|
|
|
|
assert_same(args.realm_emoji, event.realm_emoji);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm_filters
|
|
|
|
var event = event_fixtures.realm_filters;
|
|
|
|
page_params.realm_filters = [];
|
2017-04-08 23:24:03 +02:00
|
|
|
override('settings_filters.populate_filters', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_filters, event.realm_filters);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-05-31 07:02:00 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// realm_domains
|
|
|
|
var event = event_fixtures.realm_domains__add;
|
|
|
|
page_params.realm_domains = [];
|
|
|
|
override('settings_org.populate_realm_domains', noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, [event.realm_domain]);
|
|
|
|
|
|
|
|
event = event_fixtures.realm_domains__change;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, [event.realm_domain]);
|
|
|
|
|
|
|
|
event = event_fixtures.realm_domains__remove;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, []);
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm_user
|
|
|
|
var event = event_fixtures.realm_user__add;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('people.add_in_realm', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('person');
|
|
|
|
assert_same(args.person, event.person);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_user__remove;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('people.deactivate', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('person');
|
|
|
|
assert_same(args.person, event.person);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_user__update;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('user_events.update_person', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('person');
|
|
|
|
assert_same(args.person, event.person);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// restart
|
|
|
|
var event = event_fixtures.restart;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('reload.initiate', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('options');
|
|
|
|
assert.equal(args.options.save_pointer, true);
|
|
|
|
assert.equal(args.options.immediate, true);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// stream
|
|
|
|
var event = event_fixtures.stream;
|
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
2017-03-19 16:03:07 +01:00
|
|
|
override('stream_events.update_property', stub.f);
|
2017-04-08 21:02:08 +02:00
|
|
|
override('settings_streams.update_default_streams_table', noop);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('stream_id', 'property', 'value');
|
|
|
|
assert_same(args.stream_id, event.stream_id);
|
|
|
|
assert_same(args.property, event.property);
|
|
|
|
assert_same(args.value, event.value);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// subscription
|
2016-10-31 20:18:32 +01:00
|
|
|
|
|
|
|
// This next section can go away when we start handling
|
|
|
|
// user_ids more directly in some of subscriptions code.
|
2017-03-11 17:19:19 +01:00
|
|
|
override('people.get_person_from_user_id', function (user_id) {
|
2016-10-31 20:18:32 +01:00
|
|
|
assert_same(user_id, 555);
|
2016-11-09 16:05:30 +01:00
|
|
|
return {email: 'this-is-not-really-used-in-the-test'};
|
2016-10-31 20:18:32 +01:00
|
|
|
});
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
var event = event_fixtures.subscription__add;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.get_sub_by_id', function (stream_id) {
|
|
|
|
return {stream_id: stream_id};
|
|
|
|
});
|
2017-03-19 16:47:30 +01:00
|
|
|
override('stream_events.mark_subscribed', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('sub', 'subscribers');
|
|
|
|
assert_same(args.sub.stream_id, event.subscriptions[0].stream_id);
|
|
|
|
assert_same(args.subscribers, event.subscriptions[0].subscribers);
|
2017-03-05 00:09:48 +01:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.subscription__peer_add;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.add_subscriber', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('sub', 'user_id');
|
|
|
|
assert_same(args.sub, event.subscriptions[0]);
|
|
|
|
assert_same(args.user_id, 555);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.subscription__peer_remove;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.remove_subscriber', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('sub', 'user_id');
|
|
|
|
assert_same(args.sub, event.subscriptions[0]);
|
|
|
|
assert_same(args.user_id, 555);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.subscription__remove;
|
|
|
|
var stream_id_looked_up;
|
|
|
|
var sub_stub = 'stub';
|
2017-03-11 17:19:19 +01:00
|
|
|
override('stream_data.get_sub_by_id', function (stream_id) {
|
2016-08-05 21:44:51 +02:00
|
|
|
stream_id_looked_up = stream_id;
|
|
|
|
return sub_stub;
|
|
|
|
});
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
2017-03-19 16:47:30 +01:00
|
|
|
override('stream_events.mark_unsubscribed', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('sub');
|
|
|
|
assert_same(stream_id_looked_up, event.subscriptions[0].stream_id);
|
|
|
|
assert_same(args.sub, sub_stub);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.subscription__update;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
2017-03-19 16:03:07 +01:00
|
|
|
override('stream_events.update_property', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('stream_id', 'property', 'value');
|
|
|
|
assert_same(args.stream_id, event.stream_id);
|
|
|
|
assert_same(args.property, event.property);
|
|
|
|
assert_same(args.value, event.value);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-05-31 07:48:38 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// typing
|
|
|
|
var event = event_fixtures.typing__start;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('typing_events.display_notification', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('event');
|
|
|
|
assert_same(args.event.sender.user_id, 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.typing__stop;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('typing_events.hide_notification', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('event');
|
|
|
|
assert_same(args.event.sender.user_id, 6);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// update_display_settings
|
|
|
|
var event = event_fixtures.update_display_settings__default_language;
|
|
|
|
page_params.default_language = 'en';
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.default_language, 'fr');
|
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__left_side_userlist;
|
|
|
|
page_params.left_side_userlist = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.left_side_userlist, true);
|
|
|
|
|
2017-03-11 17:19:19 +01:00
|
|
|
override('message_list.narrowed', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.update_display_settings__twenty_four_hour_time;
|
|
|
|
page_params.twenty_four_hour_time = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.twenty_four_hour_time, true);
|
|
|
|
|
2017-03-02 08:30:53 +01:00
|
|
|
event = event_fixtures.update_display_settings__emoji_alt_code;
|
|
|
|
page_params.emoji_alt_code = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.emoji_alt_code, true);
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// update_global_notifications
|
|
|
|
var event = event_fixtures.update_global_notifications;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('notifications.handle_global_notification_updates', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('name', 'setting');
|
|
|
|
assert_same(args.name, event.notification_name);
|
|
|
|
assert_same(args.setting, event.setting);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// update_message_flags__read
|
|
|
|
var event = event_fixtures.update_message_flags__read;
|
2017-03-18 01:41:56 +01:00
|
|
|
override('unread_ops.mark_messages_as_read', noop);
|
2017-03-11 19:18:57 +01:00
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('message_store.get', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('message_id');
|
|
|
|
assert_same(args.message_id, 999);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// update_message_flags__starred
|
|
|
|
var event = event_fixtures.update_message_flags__starred;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('ui.update_starred', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('message_id', 'new_value');
|
|
|
|
assert_same(args.message_id, 99);
|
|
|
|
assert_same(args.new_value, true); // for 'add'
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
2017-05-31 07:20:28 +02:00
|
|
|
|
|
|
|
with_overrides(function (override) {
|
|
|
|
// delete_message
|
|
|
|
var event = event_fixtures.delete_message;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('ui.remove_message', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
var args = stub.get_args('message_id');
|
|
|
|
assert_same(args.message_id, 1337);
|
|
|
|
});
|
|
|
|
});
|