2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2017-07-01 14:21:20 +02:00
|
|
|
set_global('document', 'document-stub');
|
2018-08-18 23:57:34 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-08-19 01:59:34 +02:00
|
|
|
global.patch_builtin('setTimeout', func => func());
|
2018-08-19 01:34:26 +02:00
|
|
|
|
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
|
|
|
});
|
2017-05-09 18:01:43 +02:00
|
|
|
|
|
|
|
set_global('markdown', {
|
2020-02-17 14:43:59 +01:00
|
|
|
update_realm_filter_rules: 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,
|
|
|
|
});
|
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
set_global('settings_account', {
|
|
|
|
update_email_change_display: noop,
|
|
|
|
update_name_change_display: noop,
|
2018-06-10 07:03:22 +02:00
|
|
|
add_custom_profile_fields_to_settings: noop,
|
2018-03-02 21:44:14 +01:00
|
|
|
});
|
2018-03-05 03:32:05 +01:00
|
|
|
set_global('settings_display', {
|
|
|
|
update_page: noop,
|
|
|
|
});
|
2018-03-02 21:44:14 +01:00
|
|
|
|
2018-03-06 20:51:43 +01:00
|
|
|
set_global('settings_notifications', {
|
|
|
|
update_page: noop,
|
|
|
|
});
|
|
|
|
|
2017-07-18 02:58:13 +02:00
|
|
|
set_global('settings_org', {
|
2018-03-25 15:35:10 +02:00
|
|
|
sync_realm_settings: noop,
|
2017-07-18 02:58:13 +02:00
|
|
|
});
|
|
|
|
|
2018-03-05 18:28:37 +01:00
|
|
|
set_global('message_edit', {
|
|
|
|
update_message_topic_editing_pencil: noop,
|
|
|
|
});
|
|
|
|
|
2018-01-29 16:10:54 +01:00
|
|
|
set_global('settings_bots', {
|
|
|
|
update_bot_permissions_ui: noop,
|
|
|
|
});
|
|
|
|
|
2020-04-08 00:23:15 +02:00
|
|
|
set_global('compose', {
|
|
|
|
update_video_chat_button_display: noop,
|
|
|
|
});
|
|
|
|
|
2019-04-09 21:49:07 +02:00
|
|
|
set_global('settings_exports', {
|
|
|
|
populate_exports_table: function (exports) {
|
|
|
|
return exports;
|
|
|
|
},
|
2019-08-23 09:21:16 +02:00
|
|
|
clear_success_banner: noop,
|
2019-04-09 21:49:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
// page_params is highly coupled to dispatching now
|
2020-03-26 22:12:37 +01:00
|
|
|
set_global('page_params', {
|
|
|
|
test_suite: false,
|
|
|
|
is_admin: true,
|
|
|
|
realm_description: 'already set description',
|
|
|
|
});
|
2019-11-02 00:06:25 +01:00
|
|
|
const page_params = global.page_params;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
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', {
|
2020-05-28 22:29:52 +02:00
|
|
|
info: noop,
|
2017-03-11 20:27:54 +01:00
|
|
|
error: function (msg, more_info, stack) {
|
|
|
|
console.log("\nFailed to process an event:\n", more_info.event, "\n");
|
2019-11-02 00:06:25 +01:00
|
|
|
const error = new Error();
|
2017-03-11 20:27:54 +01:00
|
|
|
error.stack = stack;
|
|
|
|
throw error;
|
|
|
|
},
|
|
|
|
exception_msg: function (ex) {
|
|
|
|
return ex.message;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-02-28 03:29:24 +01:00
|
|
|
set_global('overlays', {
|
|
|
|
streams_open: () => true,
|
|
|
|
});
|
|
|
|
|
2020-02-26 23:53:46 +01:00
|
|
|
// For data-oriented modules, just use them, don't stub them.
|
|
|
|
zrequire('alert_words');
|
2019-01-26 01:15:59 +01:00
|
|
|
zrequire('unread');
|
2020-03-22 18:40:05 +01:00
|
|
|
zrequire('stream_topic_history');
|
2019-01-26 01:15:59 +01:00
|
|
|
zrequire('stream_list');
|
2019-01-26 18:49:10 +01:00
|
|
|
zrequire('message_flags');
|
|
|
|
zrequire('message_store');
|
2019-01-25 20:03:10 +01:00
|
|
|
zrequire('people');
|
2019-01-26 19:28:39 +01:00
|
|
|
zrequire('starred_messages');
|
2019-01-26 19:29:06 +01:00
|
|
|
zrequire('user_status');
|
2020-03-08 18:45:44 +01:00
|
|
|
zrequire('subs');
|
|
|
|
zrequire('stream_ui_updates');
|
2020-02-26 23:53:46 +01:00
|
|
|
|
2017-11-08 17:10:09 +01:00
|
|
|
zrequire('server_events_dispatch');
|
2020-03-26 08:15:26 +01:00
|
|
|
zrequire('panels');
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
function dispatch(ev) {
|
2019-01-25 20:03:10 +01:00
|
|
|
server_events_dispatch.dispatch_normal_event(ev);
|
2016-08-05 21:44:51 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const test_user = {
|
2019-01-25 20:03:10 +01:00
|
|
|
email: 'test@example.com',
|
|
|
|
user_id: 101,
|
|
|
|
full_name: 'Test User',
|
|
|
|
};
|
|
|
|
|
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(test_user);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const test_message = {
|
2019-01-26 18:49:10 +01:00
|
|
|
sender_id: test_user.user_id,
|
|
|
|
id: 99,
|
|
|
|
};
|
|
|
|
message_store.add_message_metadata(test_message);
|
|
|
|
|
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.
|
2019-11-02 00:06:25 +01:00
|
|
|
const event_fixtures = {
|
2016-08-05 21:44:51 +02:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
attachment: {
|
|
|
|
type: 'attachment',
|
|
|
|
},
|
|
|
|
|
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'],
|
|
|
|
},
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
invites_changed: {
|
|
|
|
type: 'invites_changed',
|
|
|
|
},
|
|
|
|
|
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',
|
2020-02-03 16:25:13 +01:00
|
|
|
user_id: 42,
|
2016-08-05 21:44:51 +02:00
|
|
|
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',
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: "1",
|
2017-12-19 00:55:40 +01:00
|
|
|
user: {
|
|
|
|
id: "1",
|
|
|
|
},
|
2017-05-31 06:37:52 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
reaction__remove: {
|
|
|
|
type: 'reaction',
|
|
|
|
op: 'remove',
|
|
|
|
message_id: 256,
|
|
|
|
emoji_name: 'angery',
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: "1",
|
2017-12-19 00:55:40 +01:00
|
|
|
user: {
|
|
|
|
id: "1",
|
|
|
|
},
|
2017-05-31 06:37:52 +02:00
|
|
|
},
|
|
|
|
|
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.
|
2019-05-06 16:34:31 +02:00
|
|
|
realm__update__create_stream_policy: {
|
2016-08-05 21:44:51 +02:00
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
2019-05-06 16:34:31 +02:00
|
|
|
property: 'create_stream_policy',
|
|
|
|
value: 2,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2019-04-08 19:23:00 +02:00
|
|
|
realm__update__invite_to_stream_policy: {
|
2016-08-05 21:44:51 +02:00
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
2019-04-08 19:23:00 +02:00
|
|
|
property: 'invite_to_stream_policy',
|
|
|
|
value: 2,
|
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
|
|
|
},
|
|
|
|
|
2018-07-27 23:26:29 +02:00
|
|
|
realm__update__emails_restricted_to_domains: {
|
2016-08-05 21:44:51 +02:00
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
2018-07-27 23:26:29 +02:00
|
|
|
property: 'emails_restricted_to_domains',
|
2016-12-03 23:17:57 +01:00
|
|
|
value: false,
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2018-01-29 16:10:54 +01:00
|
|
|
realm__update__bot_creation_policy: {
|
2017-11-24 16:24:24 +01:00
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
2018-01-29 16:10:54 +01:00
|
|
|
property: 'bot_creation_policy',
|
|
|
|
value: 1,
|
2017-11-24 16:24:24 +01:00
|
|
|
},
|
|
|
|
|
2020-03-08 18:45:44 +01:00
|
|
|
realm__update__email_addresses_visibility: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'email_address_visibility',
|
|
|
|
value: 3,
|
|
|
|
},
|
|
|
|
|
2018-03-05 19:19:19 +01:00
|
|
|
realm__update__disallow_disposable_email_addresses: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'disallow_disposable_email_addresses',
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
|
2018-03-30 22:38:16 +02:00
|
|
|
realm__update_default_twenty_four_hour_time: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'default_twenty_four_hour_time',
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
realm__update_notifications_stream_id: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'notifications_stream_id',
|
|
|
|
value: 42,
|
|
|
|
},
|
|
|
|
|
|
|
|
realm__update_signup_notifications_stream_id: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'signup_notifications_stream_id',
|
|
|
|
value: 41,
|
|
|
|
},
|
|
|
|
|
2020-04-10 09:38:55 +02:00
|
|
|
realm__update_default_code_block_language: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update',
|
|
|
|
property: 'default_code_block_language',
|
|
|
|
value: 'javascript',
|
|
|
|
},
|
|
|
|
|
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,
|
2018-08-19 01:34:26 +02:00
|
|
|
authentication_methods: {
|
|
|
|
Google: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
realm__update_dict__icon: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update_dict',
|
|
|
|
property: 'icon',
|
|
|
|
data: {
|
|
|
|
icon_url: 'icon.png',
|
|
|
|
icon_source: 'U',
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2019-01-25 20:35:55 +01:00
|
|
|
realm__update_dict__logo: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update_dict',
|
|
|
|
property: 'logo',
|
|
|
|
data: {
|
|
|
|
logo_url: 'logo.png',
|
|
|
|
logo_source: 'U',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-01-27 08:25:10 +01:00
|
|
|
realm__update_dict__night_logo: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'update_dict',
|
|
|
|
property: 'night_logo',
|
|
|
|
data: {
|
|
|
|
night_logo_url: 'night_logo.png',
|
|
|
|
night_logo_source: 'U',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
realm__deactivated: {
|
|
|
|
type: 'realm',
|
|
|
|
op: 'deactivated',
|
|
|
|
},
|
|
|
|
|
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',
|
2018-01-22 18:36:53 +01:00
|
|
|
user_id: '42',
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'The Bot',
|
|
|
|
},
|
2016-08-05 21:44:51 +02:00
|
|
|
},
|
|
|
|
|
2018-03-08 16:28:37 +01:00
|
|
|
realm_bot__delete: {
|
|
|
|
type: 'realm_bot',
|
|
|
|
op: 'delete',
|
|
|
|
bot: {
|
|
|
|
email: 'the-bot@example.com',
|
|
|
|
user_id: '42',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
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: {
|
2018-08-10 10:01:17 +02:00
|
|
|
source_url: 'some_url',
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
|
|
|
},
|
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: {
|
2019-01-25 20:03:10 +01:00
|
|
|
email: 'added@example.com',
|
|
|
|
full_name: 'Added Person',
|
|
|
|
user_id: 1001,
|
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: {
|
2019-01-25 20:03:10 +01:00
|
|
|
email: 'added@example.com',
|
|
|
|
user_id: 1001,
|
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
|
|
|
},
|
|
|
|
|
2018-08-18 08:40:49 +02:00
|
|
|
stream__update: {
|
2016-08-05 21:44:51 +02:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2018-08-18 08:56:09 +02:00
|
|
|
stream__create: {
|
|
|
|
type: 'stream',
|
|
|
|
op: 'create',
|
|
|
|
streams: [
|
|
|
|
{stream_id: 42},
|
|
|
|
{stream_id: 99},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2018-08-18 22:50:37 +02:00
|
|
|
stream__delete: {
|
|
|
|
type: 'stream',
|
|
|
|
op: 'delete',
|
|
|
|
streams: [
|
|
|
|
{stream_id: 42},
|
|
|
|
{stream_id: 99},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
submessage: {
|
|
|
|
type: 'submessage',
|
|
|
|
submessage_id: 99,
|
|
|
|
sender_id: 42,
|
|
|
|
msg_type: 'stream',
|
|
|
|
message_id: 56,
|
|
|
|
content: 'test',
|
|
|
|
},
|
|
|
|
|
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'],
|
2018-04-05 19:58:27 +02:00
|
|
|
email_address: 'devel+0138515295f4@zulipdev.com:9991',
|
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',
|
|
|
|
},
|
|
|
|
|
2018-08-18 23:26:21 +02:00
|
|
|
typing__self: {
|
|
|
|
type: 'typing',
|
|
|
|
sender: {
|
|
|
|
user_id: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
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',
|
2018-03-05 03:46:07 +01:00
|
|
|
language_name: 'French',
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
|
2018-08-19 01:59:34 +02:00
|
|
|
update_display_settings__dense_mode: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'dense_mode',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
update_display_settings__night_mode: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'night_mode',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
update_display_settings__night_mode_false: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'night_mode',
|
|
|
|
setting: false,
|
|
|
|
},
|
|
|
|
|
2019-01-25 21:33:02 +01:00
|
|
|
update_display_settings__starred_message_counts: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'starred_message_counts',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
2019-04-16 18:46:17 +02:00
|
|
|
update_display_settings__fluid_layout_width: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'fluid_layout_width',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
2019-03-17 14:48:51 +01:00
|
|
|
update_display_settings__demote_inactive_streams: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'demote_inactive_streams',
|
|
|
|
setting: 2,
|
|
|
|
},
|
|
|
|
|
2018-01-15 19:36:32 +01:00
|
|
|
update_display_settings__translate_emoticons: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'translate_emoticons',
|
|
|
|
setting: true,
|
|
|
|
},
|
|
|
|
|
2018-08-19 01:59:34 +02:00
|
|
|
update_display_settings__emojiset: {
|
|
|
|
type: 'update_display_settings',
|
|
|
|
setting_name: 'emojiset',
|
|
|
|
setting: 'google',
|
|
|
|
},
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
update_global_notifications: {
|
|
|
|
type: 'update_global_notifications',
|
2019-06-11 08:47:49 +02:00
|
|
|
notification_name: 'enable_stream_audible_notifications',
|
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
|
|
|
},
|
|
|
|
|
2019-01-26 19:28:39 +01:00
|
|
|
update_message_flags__starred_add: {
|
2016-08-05 21:44:51 +02:00
|
|
|
type: 'update_message_flags',
|
|
|
|
operation: 'add',
|
|
|
|
flag: 'starred',
|
2019-01-26 18:49:10 +01:00
|
|
|
messages: [test_message.id],
|
2016-12-03 23:17:57 +01:00
|
|
|
},
|
2017-05-31 07:20:28 +02:00
|
|
|
|
2019-01-26 19:28:39 +01:00
|
|
|
update_message_flags__starred_remove: {
|
|
|
|
type: 'update_message_flags',
|
|
|
|
operation: 'remove',
|
|
|
|
flag: 'starred',
|
|
|
|
messages: [test_message.id],
|
|
|
|
},
|
|
|
|
|
2017-05-31 07:20:28 +02:00
|
|
|
delete_message: {
|
|
|
|
type: 'delete_message',
|
|
|
|
message_id: 1337,
|
2018-04-02 00:21:21 +02:00
|
|
|
message_type: "stream",
|
|
|
|
stream_id: 99,
|
|
|
|
topic: 'topic1',
|
2017-05-31 07:20:28 +02:00
|
|
|
},
|
2017-12-14 05:51:45 +01:00
|
|
|
|
|
|
|
custom_profile_fields: {
|
|
|
|
type: 'custom_profile_fields',
|
|
|
|
fields: [
|
|
|
|
{id: 1, name: 'teams', type: 1},
|
|
|
|
{id: 2, name: 'hobbies', type: 1},
|
|
|
|
],
|
|
|
|
},
|
2018-04-15 21:26:58 +02:00
|
|
|
user_group__add: {
|
|
|
|
type: 'user_group',
|
|
|
|
op: 'add',
|
|
|
|
group: {
|
|
|
|
name: 'Mobile',
|
|
|
|
id: '1',
|
|
|
|
members: [1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user_group__add_members: {
|
|
|
|
type: 'user_group',
|
|
|
|
op: 'add_members',
|
|
|
|
group_id: 1,
|
|
|
|
user_ids: [2],
|
|
|
|
},
|
|
|
|
user_group__remove_members: {
|
|
|
|
type: 'user_group',
|
|
|
|
op: 'remove_members',
|
|
|
|
group_id: 3,
|
|
|
|
user_ids: [99, 100],
|
|
|
|
},
|
|
|
|
user_group__update: {
|
|
|
|
type: 'user_group',
|
|
|
|
op: 'update',
|
|
|
|
group_id: 3,
|
|
|
|
data: {
|
|
|
|
name: 'Frontend',
|
|
|
|
description: 'All Frontend people',
|
|
|
|
},
|
|
|
|
},
|
2018-12-19 18:41:47 +01:00
|
|
|
user_status__revoke_away: {
|
|
|
|
type: 'user_status',
|
|
|
|
user_id: 63,
|
|
|
|
away: false,
|
|
|
|
},
|
|
|
|
user_status__set_away: {
|
|
|
|
type: 'user_status',
|
|
|
|
user_id: 55,
|
|
|
|
away: true,
|
|
|
|
},
|
2019-01-26 19:28:39 +01:00
|
|
|
user_status__set_status_text: {
|
|
|
|
type: 'user_status',
|
|
|
|
user_id: test_user.user_id,
|
|
|
|
status_text: 'out to lunch',
|
|
|
|
},
|
2019-04-09 21:49:07 +02:00
|
|
|
realm_export: {
|
|
|
|
type: 'realm_export',
|
|
|
|
exports: {
|
|
|
|
acting_user_id: 55,
|
|
|
|
event_time: 'noon',
|
|
|
|
path: 'some_path',
|
|
|
|
},
|
|
|
|
},
|
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.
|
2019-01-26 19:28:39 +01:00
|
|
|
assert(expected !== undefined);
|
2016-08-05 21:44:51 +02:00
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const 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
|
2020-02-26 23:53:46 +01:00
|
|
|
assert(!alert_words.has_alert_word('fire'));
|
|
|
|
assert(!alert_words.has_alert_word('lunch'));
|
|
|
|
|
2017-06-07 21:36:43 +02:00
|
|
|
override('alert_words_ui.render_alert_words_ui', noop);
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.alert_words;
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
|
2020-02-26 23:53:46 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
alert_words.get_word_list(),
|
|
|
|
['fire', 'lunch']
|
|
|
|
);
|
|
|
|
assert(alert_words.has_alert_word('fire'));
|
|
|
|
assert(alert_words.has_alert_word('lunch'));
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
with_overrides(function (override) {
|
2020-03-28 01:25:56 +01:00
|
|
|
// attachments
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.attachment;
|
2018-08-19 00:02:08 +02:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('attachments_ui.update_attachments', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(stub.get_args('event').event, event);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-15 21:26:58 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// User groups
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.user_group__add;
|
2018-04-15 21:26:58 +02:00
|
|
|
override('settings_user_groups.reload', noop);
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('user_groups.add', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('group');
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group, event.group);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.user_group__add_members;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('user_groups.add_members', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('group_id', 'user_ids');
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group_id, event.group_id);
|
|
|
|
assert_same(args.user_ids, event.user_ids);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.user_group__remove_members;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('user_groups.remove_members', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('group_id', 'user_ids');
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group_id, event.group_id);
|
|
|
|
assert_same(args.user_ids, event.user_ids);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.user_group__update;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('user_groups.update', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('event');
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.event.group_id, event.group_id);
|
|
|
|
assert_same(args.event.data.name, event.data.name);
|
|
|
|
assert_same(args.event.data.description, event.data.description);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-14 05:51:45 +01:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// custom profile fields
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.custom_profile_fields;
|
2017-12-14 05:51:45 +01:00
|
|
|
override('settings_profile_fields.populate_profile_fields', noop);
|
|
|
|
override('settings_profile_fields.report_success', noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(global.page_params.custom_profile_fields, event.fields);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// default_streams
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.default_streams;
|
2017-04-08 21:02:08 +02:00
|
|
|
override('settings_streams.update_default_streams_table', noop);
|
2017-08-22 18:20:00 +02:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.set_realm_default_streams', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('realm_default_streams');
|
2017-08-22 18:20:00 +02:00
|
|
|
assert_same(args.realm_default_streams, event.default_streams);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-05-31 06:34:53 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// hotspots
|
2019-11-02 00:06:25 +01:00
|
|
|
const 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);
|
|
|
|
});
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// invites_changed
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.invites_changed;
|
2018-08-19 00:02:08 +02:00
|
|
|
$('#admin-invites-list').length = 1;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('settings_invites.set_up', stub.f);
|
|
|
|
dispatch(event); // stub automatically checks if stub.f is called once
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// muted_topics
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.muted_topics;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('muting_ui.handle_updates', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('muted_topics');
|
2017-03-11 19:18:57 +01:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.presence;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
2018-12-18 18:19:29 +01:00
|
|
|
override('activity.update_presence_info', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
2020-02-03 16:25:13 +01:00
|
|
|
const args = stub.get_args('user_id', 'presence', 'server_time');
|
|
|
|
assert_same(args.user_id, event.user_id);
|
2017-03-11 19:18:57 +01:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.reaction__add;
|
2017-05-31 06:37:52 +02:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('reactions.add_reaction', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('event');
|
2017-05-31 06:37:52 +02:00
|
|
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('event');
|
2017-05-31 06:37:52 +02:00
|
|
|
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;
|
2020-02-09 04:44:12 +01:00
|
|
|
event = { ...event };
|
2016-08-05 21:44:51 +02:00
|
|
|
event.value = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], false);
|
2020-02-09 04:44:12 +01:00
|
|
|
event = { ...event };
|
2016-08-05 21:44:51 +02:00
|
|
|
event.value = true;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], true);
|
|
|
|
}
|
|
|
|
|
2020-04-01 08:54:56 +02:00
|
|
|
function test_realm_integer(event, parameter_name) {
|
|
|
|
page_params[parameter_name] = 1;
|
|
|
|
event = {...event};
|
|
|
|
event.value = 2;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 2);
|
|
|
|
|
|
|
|
event = {...event};
|
|
|
|
event.value = 3;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 3);
|
|
|
|
|
|
|
|
event = {...event};
|
|
|
|
event.value = 1;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 1);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm__update__create_stream_policy;
|
2020-04-01 08:54:56 +02:00
|
|
|
test_realm_integer(event, 'realm_create_stream_policy');
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2019-04-08 19:23:00 +02:00
|
|
|
event = event_fixtures.realm__update__invite_to_stream_policy;
|
2020-04-01 08:54:56 +02:00
|
|
|
test_realm_integer(event, 'realm_invite_to_stream_policy');
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-04-03 02:31:43 +02:00
|
|
|
event = event_fixtures.realm__update__bot_creation_policy;
|
|
|
|
test_realm_integer(event, 'realm_bot_creation_policy');
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.realm__update__invite_required;
|
|
|
|
test_realm_boolean(event, 'realm_invite_required');
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update__name;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_name, 'new_realm_name');
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let called = false;
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('electron_bridge', {
|
2018-08-19 01:34:26 +02:00
|
|
|
send_event: (key, val) => {
|
|
|
|
assert_same(key, 'realm_name');
|
|
|
|
assert_same(val, 'new_realm_name');
|
|
|
|
called = true;
|
|
|
|
},
|
2019-07-25 09:13:22 +02:00
|
|
|
});
|
2018-08-19 01:34:26 +02:00
|
|
|
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(called, true);
|
|
|
|
|
2018-07-27 23:26:29 +02:00
|
|
|
event = event_fixtures.realm__update__emails_restricted_to_domains;
|
|
|
|
test_realm_boolean(event, 'realm_emails_restricted_to_domains');
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-03-05 19:19:19 +01:00
|
|
|
event = event_fixtures.realm__update__disallow_disposable_email_addresses;
|
|
|
|
test_realm_boolean(event, 'realm_disallow_disposable_email_addresses');
|
|
|
|
|
2020-04-30 21:47:41 +02:00
|
|
|
event = event_fixtures.realm__update_default_twenty_four_hour_time;
|
|
|
|
test_realm_boolean(event, 'realm_default_twenty_four_hour_time');
|
|
|
|
|
2020-03-08 18:45:44 +01:00
|
|
|
event = event_fixtures.realm__update__email_addresses_visibility;
|
|
|
|
override('stream_ui_updates.update_subscribers_list', noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_email_address_visibility, 3);
|
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
event = event_fixtures.realm__update_notifications_stream_id;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_notifications_stream_id, 42);
|
|
|
|
page_params.realm_notifications_stream_id = -1; // make sure to reset for future tests
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update_signup_notifications_stream_id;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_signup_notifications_stream_id, 41);
|
|
|
|
page_params.realm_signup_notifications_stream_id = -1; // make sure to reset for future tests
|
|
|
|
|
2020-04-10 09:38:55 +02:00
|
|
|
event = event_fixtures.realm__update_default_code_block_language;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_default_code_block_language, 'javascript');
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.realm__update_dict__default;
|
|
|
|
page_params.realm_allow_message_editing = false;
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 0;
|
2018-08-19 01:34:26 +02:00
|
|
|
override('settings_org.populate_auth_methods', noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_allow_message_editing, true);
|
|
|
|
assert_same(page_params.realm_message_content_edit_limit_seconds, 5);
|
2018-08-19 01:34:26 +02:00
|
|
|
assert_same(page_params.realm_authentication_methods, {Google: true});
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update_dict__icon;
|
|
|
|
override('realm_icon.rerender', noop);
|
|
|
|
|
|
|
|
called = false;
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('electron_bridge', {
|
2018-08-19 01:34:26 +02:00
|
|
|
send_event: (key, val) => {
|
|
|
|
assert_same(key, 'realm_icon_url');
|
|
|
|
assert_same(val, 'icon.png');
|
|
|
|
called = true;
|
|
|
|
},
|
2019-07-25 09:13:22 +02:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
assert_same(called, true);
|
|
|
|
assert_same(page_params.realm_icon_url, 'icon.png');
|
|
|
|
assert_same(page_params.realm_icon_source, 'U');
|
|
|
|
|
2019-01-25 20:35:55 +01:00
|
|
|
event = event_fixtures.realm__update_dict__logo;
|
|
|
|
override('realm_logo.rerender', noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_logo_url, 'logo.png');
|
|
|
|
assert_same(page_params.realm_logo_source, 'U');
|
|
|
|
|
2019-01-27 08:25:10 +01:00
|
|
|
event = event_fixtures.realm__update_dict__night_logo;
|
|
|
|
override('realm_logo.rerender', noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_night_logo_url, 'night_logo.png');
|
|
|
|
assert_same(page_params.realm_night_logo_source, 'U');
|
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
event = event_fixtures.realm__deactivated;
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('location', {});
|
2018-08-19 01:34:26 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(window.location.href, "/accounts/deactivated/");
|
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_bot
|
2019-11-02 00:06:25 +01:00
|
|
|
let 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);
|
2020-05-20 00:32:34 +02:00
|
|
|
override('settings_users.update_bot_data', admin_stub.f);
|
2017-03-10 09:23:59 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = bot_stub.get_args('bot');
|
2017-03-10 09:23:59 +01:00
|
|
|
assert_same(args.bot, event.bot);
|
|
|
|
|
2017-08-23 08:32:52 +02:00
|
|
|
admin_stub.get_args('update_user_id', 'update_bot_data');
|
2017-03-10 09:23:59 +01:00
|
|
|
});
|
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);
|
2020-05-20 00:32:34 +02:00
|
|
|
override('settings_users.update_bot_data', admin_stub.f);
|
2017-03-10 09:23:59 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = bot_stub.get_args('user_id');
|
2018-01-22 18:36:53 +01:00
|
|
|
assert_same(args.user_id, event.bot.user_id);
|
2017-03-10 09:23:59 +01:00
|
|
|
|
2018-03-08 16:28:37 +01:00
|
|
|
admin_stub.get_args('update_user_id', 'update_bot_data');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.realm_bot__delete;
|
2020-05-28 22:29:52 +02:00
|
|
|
// We don't handle live updates for delete events, this is a noop.
|
|
|
|
dispatch(event);
|
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);
|
2020-05-20 00:32:34 +02:00
|
|
|
override('settings_users.update_bot_data', admin_stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
|
|
|
|
dispatch(event);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let args = bot_stub.get_args('user_id', 'bot');
|
2018-01-22 18:36:53 +01:00
|
|
|
assert_same(args.user_id, event.bot.user_id);
|
2017-03-11 19:18:57 +01:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.realm_emoji;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
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-07-19 00:28:56 +02:00
|
|
|
override('emoji_picker.generate_emoji_picker_data', noop);
|
2018-12-15 13:13:06 +01:00
|
|
|
override('composebox_typeahead.update_emoji_data', noop);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('realm_emoji');
|
2017-03-11 19:18:57 +01:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.realm_filters;
|
2016-08-05 21:44:51 +02:00
|
|
|
page_params.realm_filters = [];
|
2018-12-17 21:28:25 +01:00
|
|
|
override('settings_linkifiers.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
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm_domains__add;
|
2017-05-31 07:02:00 +02:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm_user__add;
|
2019-01-25 20:03:10 +01:00
|
|
|
dispatch(event);
|
2020-02-05 14:30:59 +01:00
|
|
|
const added_person = people.get_by_user_id(event.person.user_id);
|
2019-01-25 20:03:10 +01:00
|
|
|
assert.equal(added_person.full_name, 'Added Person');
|
|
|
|
assert(people.is_active_user_for_popover(event.person.user_id));
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_user__remove;
|
2019-01-25 20:03:10 +01:00
|
|
|
override('stream_events.remove_deactivated_user_from_all_streams', noop);
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
// We don't actually remove the person, we just deactivate them.
|
2020-02-05 14:30:59 +01:00
|
|
|
const removed_person = people.get_by_user_id(event.person.user_id);
|
2019-01-25 20:03:10 +01:00
|
|
|
assert.equal(removed_person.full_name, 'Added Person');
|
|
|
|
assert(!people.is_active_user_for_popover(event.person.user_id));
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('person');
|
2017-03-11 19:18:57 +01:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.restart;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('reload.initiate', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('options');
|
2017-03-11 19:18:57 +01:00
|
|
|
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) {
|
2018-08-18 08:40:49 +02:00
|
|
|
// stream update
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.stream__update;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('stream_id', 'property', 'value');
|
2017-03-11 19:18:57 +01:00
|
|
|
assert_same(args.stream_id, event.stream_id);
|
|
|
|
assert_same(args.property, event.property);
|
|
|
|
assert_same(args.value, event.value);
|
|
|
|
});
|
2018-08-18 08:56:09 +02:00
|
|
|
|
|
|
|
// stream create
|
|
|
|
event = event_fixtures.stream__create;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.create_streams', stub.f);
|
|
|
|
override('stream_data.get_sub_by_id', noop);
|
|
|
|
override('stream_data.update_calculated_fields', noop);
|
|
|
|
override('subs.add_sub_to_table', noop);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('streams');
|
2020-02-09 04:39:08 +01:00
|
|
|
assert_same(args.streams.map(stream => stream.stream_id), [42, 99]);
|
2018-08-18 08:56:09 +02:00
|
|
|
});
|
2018-08-18 22:50:37 +02:00
|
|
|
|
|
|
|
// stream delete
|
|
|
|
event = event_fixtures.stream__delete;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('subs.remove_stream', noop);
|
|
|
|
override('stream_data.delete_sub', noop);
|
2020-03-22 14:38:19 +01:00
|
|
|
override('settings_streams.update_default_streams_table', noop);
|
2018-08-18 22:50:37 +02:00
|
|
|
override('stream_data.remove_default_stream', noop);
|
|
|
|
|
|
|
|
override('stream_data.get_sub_by_id', function (id) {
|
|
|
|
return id === 42 ? {subscribed: true} : {subscribed: false};
|
|
|
|
});
|
|
|
|
override('stream_list.remove_sidebar_row', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('stream_id');
|
2018-08-18 22:50:37 +02:00
|
|
|
assert_same(args.stream_id, 42);
|
|
|
|
|
|
|
|
override('stream_list.remove_sidebar_row', noop);
|
|
|
|
page_params.realm_notifications_stream_id = 42;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_notifications_stream_id, -1);
|
|
|
|
|
|
|
|
page_params.realm_signup_notifications_stream_id = 42;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_signup_notifications_stream_id, -1);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2018-08-19 00:02:08 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// submessage
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.submessage;
|
2018-08-19 00:02:08 +02:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('submessage.handle_event', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const submsg = stub.get_args('submsg').submsg;
|
2018-08-19 00:02:08 +02:00
|
|
|
assert_same(submsg, {
|
|
|
|
id: 99,
|
|
|
|
sender_id: 42,
|
|
|
|
msg_type: 'stream',
|
|
|
|
message_id: 56,
|
|
|
|
content: 'test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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.
|
2020-02-05 14:30:59 +01:00
|
|
|
override('people.get_by_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
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.subscription__add;
|
2018-04-05 19:58:27 +02:00
|
|
|
global.with_stub(function (subscription_stub) {
|
|
|
|
global.with_stub(function (stream_email_stub) {
|
|
|
|
override('stream_data.get_sub_by_id', function (stream_id) {
|
|
|
|
return {stream_id: stream_id};
|
|
|
|
});
|
|
|
|
override('stream_events.mark_subscribed', subscription_stub.f);
|
|
|
|
override('stream_data.update_stream_email_address', stream_email_stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
let args = subscription_stub.get_args('sub', 'subscribers');
|
2018-04-05 19:58:27 +02:00
|
|
|
assert_same(args.sub.stream_id, event.subscriptions[0].stream_id);
|
|
|
|
assert_same(args.subscribers, event.subscriptions[0].subscribers);
|
|
|
|
args = stream_email_stub.get_args('sub', 'email_address');
|
|
|
|
assert_same(args.email_address, event.subscriptions[0].email_address);
|
|
|
|
assert_same(args.sub.stream_id, event.subscriptions[0].stream_id);
|
2017-03-11 19:18:57 +01:00
|
|
|
});
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('sub', 'user_id');
|
2017-03-11 19:18:57 +01:00
|
|
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('sub', 'user_id');
|
2017-03-11 19:18:57 +01:00
|
|
|
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;
|
2019-11-02 00:06:25 +01:00
|
|
|
let stream_id_looked_up;
|
|
|
|
const 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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('sub');
|
2017-03-11 19:18:57 +01:00
|
|
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('stream_id', 'property', 'value');
|
2017-03-11 19:18:57 +01:00
|
|
|
assert_same(args.stream_id, event.stream_id);
|
|
|
|
assert_same(args.property, event.property);
|
|
|
|
assert_same(args.value, event.value);
|
|
|
|
});
|
2018-08-18 23:39:04 +02:00
|
|
|
|
|
|
|
// test blueslip errors/warns
|
|
|
|
event = event_fixtures.subscription__add;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.get_sub_by_id', noop);
|
|
|
|
override('blueslip.error', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(stub.get_args('param').param, 'Subscribing to unknown stream with ID 42');
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.subscription__peer_add;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.add_subscriber', noop);
|
|
|
|
override('blueslip.warn', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(stub.get_args('param').param, 'Cannot process peer_add event');
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.subscription__peer_remove;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('stream_data.remove_subscriber', noop);
|
|
|
|
override('blueslip.warn', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(stub.get_args('param').param, 'Cannot process peer_remove event.');
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2017-05-31 07:48:38 +02:00
|
|
|
with_overrides(function (override) {
|
|
|
|
// typing
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.typing__start;
|
2017-05-31 07:48:38 +02:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('typing_events.display_notification', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('event');
|
2017-05-31 07:48:38 +02:00
|
|
|
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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('event');
|
2017-05-31 07:48:38 +02:00
|
|
|
assert_same(args.event.sender.user_id, 6);
|
|
|
|
});
|
2018-08-18 23:26:21 +02:00
|
|
|
|
|
|
|
page_params.user_id = 5;
|
|
|
|
event = event_fixtures.typing__self;
|
|
|
|
dispatch(event); // get line coverage
|
2017-05-31 07:48:38 +02:00
|
|
|
});
|
|
|
|
|
2017-03-11 21:07:24 +01:00
|
|
|
with_overrides(function (override) {
|
2016-08-05 21:44:51 +02:00
|
|
|
// update_display_settings
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.update_display_settings__default_language;
|
2016-08-05 21:44:51 +02:00
|
|
|
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);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let called = false;
|
2018-08-19 01:59:34 +02:00
|
|
|
current_msg_list.rerender = () => {
|
|
|
|
called = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
override('message_list.narrowed', current_msg_list);
|
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);
|
2018-08-19 01:59:34 +02:00
|
|
|
assert_same(called, true);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-01-15 19:36:32 +01:00
|
|
|
event = event_fixtures.update_display_settings__translate_emoticons;
|
|
|
|
page_params.translate_emoticons = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.translate_emoticons, true);
|
2018-08-19 01:59:34 +02:00
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__high_contrast_mode;
|
|
|
|
page_params.high_contrast_mode = false;
|
2019-11-02 00:06:25 +01:00
|
|
|
let toggled = [];
|
2018-08-19 01:59:34 +02:00
|
|
|
$("body").toggleClass = (cls) => {
|
|
|
|
toggled.push(cls);
|
|
|
|
};
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.high_contrast_mode, true);
|
|
|
|
assert_same(toggled, ['high-contrast']);
|
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__dense_mode;
|
|
|
|
page_params.dense_mode = false;
|
|
|
|
toggled = [];
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.dense_mode, true);
|
|
|
|
assert_same(toggled, ['less_dense_mode', 'more_dense_mode']);
|
|
|
|
|
|
|
|
$("body").fadeOut = (secs) => { assert_same(secs, 300); };
|
|
|
|
$("body").fadeIn = (secs) => { assert_same(secs, 300); };
|
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
event = event_fixtures.update_display_settings__night_mode;
|
|
|
|
page_params.night_mode = false;
|
|
|
|
override('night_mode.enable', stub.f); // automatically checks if called
|
2019-01-27 08:25:10 +01:00
|
|
|
override('realm_logo.rerender', noop);
|
2018-08-19 01:59:34 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.night_mode, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
event = event_fixtures.update_display_settings__night_mode_false;
|
|
|
|
page_params.night_mode = true;
|
|
|
|
override('night_mode.disable', stub.f); // automatically checks if called
|
|
|
|
dispatch(event);
|
|
|
|
assert(!page_params.night_mode);
|
|
|
|
});
|
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
event = event_fixtures.update_display_settings__emojiset;
|
|
|
|
called = false;
|
|
|
|
override('settings_display.report_emojiset_change', stub.f);
|
|
|
|
page_params.emojiset = 'text';
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(called, true);
|
|
|
|
assert_same(page_params.emojiset, 'google');
|
|
|
|
});
|
2019-01-25 21:33:02 +01:00
|
|
|
|
|
|
|
override('starred_messages.rerender_ui', noop);
|
|
|
|
event = event_fixtures.update_display_settings__starred_message_counts;
|
|
|
|
page_params.starred_message_counts = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.starred_message_counts, true);
|
2019-04-16 18:46:17 +02:00
|
|
|
|
|
|
|
override('scroll_bar.set_layout_width', noop);
|
|
|
|
event = event_fixtures.update_display_settings__fluid_layout_width;
|
|
|
|
page_params.fluid_layout_width = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.fluid_layout_width, true);
|
2019-03-17 14:48:51 +01:00
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
event = event_fixtures.update_display_settings__demote_inactive_streams;
|
2019-12-27 15:59:42 +01:00
|
|
|
override('stream_data.set_filter_out_inactives', noop);
|
2019-03-17 14:48:51 +01:00
|
|
|
override('stream_list.update_streams_sidebar', stub.f);
|
|
|
|
page_params.demote_inactive_streams = 1;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.demote_inactive_streams, 2);
|
|
|
|
});
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const 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);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('name', 'setting');
|
2017-03-11 19:18:57 +01:00
|
|
|
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
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.update_message_flags__read;
|
2017-03-11 19:18:57 +01:00
|
|
|
|
|
|
|
global.with_stub(function (stub) {
|
2017-08-03 00:28:16 +02:00
|
|
|
override('unread_ops.process_read_messages_event', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('message_ids');
|
2017-08-03 00:28:16 +02:00
|
|
|
assert_same(args.message_ids, [999]);
|
2017-03-11 19:18:57 +01:00
|
|
|
});
|
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
|
2019-01-26 19:28:39 +01:00
|
|
|
|
|
|
|
override('starred_messages.rerender_ui', noop);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.update_message_flags__starred_add;
|
2017-03-11 19:18:57 +01:00
|
|
|
global.with_stub(function (stub) {
|
2018-08-01 19:02:38 +02:00
|
|
|
override('ui.update_starred_view', stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('message_id', 'new_value');
|
2019-01-26 18:49:10 +01:00
|
|
|
assert_same(args.message_id, test_message.id);
|
2017-03-11 19:18:57 +01:00
|
|
|
assert_same(args.new_value, true); // for 'add'
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = message_store.get(test_message.id);
|
2019-01-26 18:49:10 +01:00
|
|
|
assert.equal(msg.starred, true);
|
2017-03-11 19:18:57 +01:00
|
|
|
});
|
2019-01-26 19:28:39 +01:00
|
|
|
|
|
|
|
event = event_fixtures.update_message_flags__starred_remove;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('ui.update_starred_view', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('message_id', 'new_value');
|
2019-01-26 19:28:39 +01:00
|
|
|
assert_same(args.message_id, test_message.id);
|
|
|
|
assert_same(args.new_value, false);
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = message_store.get(test_message.id);
|
2019-01-26 19:28:39 +01:00
|
|
|
assert.equal(msg.starred, false);
|
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
2017-05-31 07:20:28 +02:00
|
|
|
|
|
|
|
with_overrides(function (override) {
|
|
|
|
// delete_message
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.delete_message;
|
2018-02-16 23:41:38 +01:00
|
|
|
|
2018-03-04 21:26:19 +01:00
|
|
|
override('stream_list.update_streams_sidebar', noop);
|
2017-05-31 07:20:28 +02:00
|
|
|
global.with_stub(function (stub) {
|
2019-01-26 01:15:59 +01:00
|
|
|
override('unread_ops.process_read_messages_event', noop);
|
2017-05-31 07:20:28 +02:00
|
|
|
override('ui.remove_message', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('message_id');
|
2017-05-31 07:20:28 +02:00
|
|
|
assert_same(args.message_id, 1337);
|
|
|
|
});
|
2018-02-16 23:41:38 +01:00
|
|
|
global.with_stub(function (stub) {
|
2018-04-01 21:12:45 +02:00
|
|
|
override('unread_ops.process_read_messages_event', stub.f);
|
2018-02-16 23:41:38 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('message_ids');
|
2018-04-01 21:12:45 +02:00
|
|
|
assert_same(args.message_ids, [1337]);
|
2018-02-16 23:41:38 +01:00
|
|
|
});
|
2018-03-04 21:26:19 +01:00
|
|
|
global.with_stub(function (stub) {
|
2020-03-22 18:40:05 +01:00
|
|
|
override('stream_topic_history.remove_message', stub.f);
|
2018-03-04 21:26:19 +01:00
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('opts');
|
2018-03-04 21:26:19 +01:00
|
|
|
assert_same(args.opts.stream_id, 99);
|
|
|
|
assert_same(args.opts.topic_name, 'topic1');
|
|
|
|
});
|
2017-05-31 07:20:28 +02:00
|
|
|
});
|
2018-12-19 18:41:47 +01:00
|
|
|
|
|
|
|
with_overrides(function (override) {
|
2020-03-28 01:25:56 +01:00
|
|
|
// attachments
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.user_status__set_away;
|
2018-12-19 18:41:47 +01:00
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('activity.on_set_away', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('user_id');
|
2018-12-19 18:41:47 +01:00
|
|
|
assert_same(args.user_id, 55);
|
|
|
|
});
|
|
|
|
|
|
|
|
event = event_fixtures.user_status__revoke_away;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('activity.on_revoke_away', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('user_id');
|
2018-12-19 18:41:47 +01:00
|
|
|
assert_same(args.user_id, 63);
|
|
|
|
});
|
2019-01-26 19:29:06 +01:00
|
|
|
|
|
|
|
event = event_fixtures.user_status__set_status_text;
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('activity.redraw_user', stub.f);
|
|
|
|
dispatch(event);
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('user_id');
|
2019-01-26 19:29:06 +01:00
|
|
|
assert_same(args.user_id, test_user.user_id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const status_text = user_status.get_status_text(test_user.user_id);
|
2019-01-26 19:29:06 +01:00
|
|
|
assert.equal(status_text, 'out to lunch');
|
|
|
|
});
|
2018-12-19 18:41:47 +01:00
|
|
|
});
|
2019-04-09 21:49:07 +02:00
|
|
|
|
|
|
|
with_overrides(function (override) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.realm_export;
|
2019-04-09 21:49:07 +02:00
|
|
|
override('settings_exports.populate_exports_table', noop);
|
|
|
|
dispatch(event);
|
|
|
|
global.with_stub(function (stub) {
|
|
|
|
override('settings_exports.populate_exports_table', stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = stub.get_args('exports');
|
2019-04-09 21:49:07 +02:00
|
|
|
assert.equal(args.exports.acting_user_id, 55);
|
|
|
|
assert.equal(args.exports.event_time, 'noon');
|
|
|
|
assert.equal(args.exports.path, 'some_path');
|
|
|
|
});
|
|
|
|
});
|