2017-04-14 15:06:13 +02:00
|
|
|
var noop = function () {};
|
|
|
|
var return_false = function () { return false; };
|
2017-09-18 21:54:06 +02:00
|
|
|
var return_true = function () { return true; };
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
set_global('document', {
|
|
|
|
location: {
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('page_params', {
|
|
|
|
use_websockets: false,
|
|
|
|
});
|
|
|
|
|
2017-06-20 04:34:04 +02:00
|
|
|
set_global('$', function () {
|
|
|
|
});
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-06-20 04:34:04 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2017-11-08 16:57:05 +01:00
|
|
|
zrequire('people');
|
|
|
|
zrequire('compose_ui');
|
|
|
|
zrequire('compose');
|
|
|
|
zrequire('util');
|
|
|
|
zrequire('compose_state');
|
|
|
|
zrequire('compose_actions');
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-04-14 16:26:00 +02:00
|
|
|
var start = compose_actions.start;
|
|
|
|
var cancel = compose_actions.cancel;
|
|
|
|
var get_focus_area = compose_actions._get_focus_area;
|
2017-04-14 19:27:12 +02:00
|
|
|
var respond_to_message = compose_actions.respond_to_message;
|
|
|
|
var reply_with_mention = compose_actions.reply_with_mention;
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-04-15 01:15:59 +02:00
|
|
|
var compose_state = global.compose_state;
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
set_global('reload', {
|
|
|
|
is_in_progress: return_false,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('notifications', {
|
|
|
|
clear_compose_notifications: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('compose_fade', {
|
|
|
|
clear_compose: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
set_global('drafts', {
|
|
|
|
update_draft: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
set_global('resize', {
|
|
|
|
resize_bottom_whitespace: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('narrow_state', {
|
|
|
|
set_compose_defaults: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
set_global('unread_ops', {
|
|
|
|
mark_message_as_read: noop,
|
|
|
|
});
|
|
|
|
|
2017-06-22 22:08:43 +02:00
|
|
|
set_global('common', {
|
|
|
|
status_classes: 'status_classes',
|
|
|
|
});
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
function stub_selected_message(msg) {
|
|
|
|
set_global('current_msg_list', {
|
|
|
|
selected_message: function () {
|
|
|
|
return msg;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
function assert_visible(sel) {
|
|
|
|
assert($(sel).visible());
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert_hidden(sel) {
|
|
|
|
assert(!$(sel).visible());
|
|
|
|
}
|
|
|
|
|
2017-04-15 01:15:59 +02:00
|
|
|
(function test_initial_state() {
|
|
|
|
assert.equal(compose_state.composing(), false);
|
|
|
|
assert.equal(compose_state.get_message_type(), false);
|
|
|
|
assert.equal(compose_state.has_message_content(), false);
|
|
|
|
}());
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
(function test_start() {
|
2017-04-14 16:26:00 +02:00
|
|
|
compose_actions.autosize_message_content = noop;
|
|
|
|
compose_actions.expand_compose_box = noop;
|
|
|
|
compose_actions.set_focus = noop;
|
|
|
|
compose_actions.complete_starting_tasks = noop;
|
|
|
|
compose_actions.blur_textarea = noop;
|
|
|
|
compose_actions.clear_textarea = noop;
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
// Start stream message
|
2017-12-02 03:13:43 +01:00
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
|
|
|
var opts = {};
|
2017-04-14 15:06:13 +02:00
|
|
|
opts.stream = 'stream1';
|
|
|
|
opts.subject = 'topic1';
|
2017-12-02 03:13:43 +01:00
|
|
|
return opts;
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var opts = {};
|
|
|
|
start('stream', opts);
|
|
|
|
|
|
|
|
assert_visible('#stream-message');
|
|
|
|
assert_hidden('#private-message');
|
|
|
|
|
|
|
|
assert.equal($('#stream').val(), 'stream1');
|
|
|
|
assert.equal($('#subject').val(), 'topic1');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), 'stream');
|
|
|
|
assert(compose_state.composing());
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
// Start PM
|
2017-12-02 03:13:43 +01:00
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
|
|
|
var opts = {};
|
2017-04-14 15:06:13 +02:00
|
|
|
opts.private_message_recipient = 'foo@example.com';
|
2017-12-02 03:13:43 +01:00
|
|
|
return opts;
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
content: 'hello',
|
|
|
|
};
|
2017-06-14 20:28:55 +02:00
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').trigger = noop;
|
2017-04-14 15:06:13 +02:00
|
|
|
start('private', opts);
|
|
|
|
|
|
|
|
assert_hidden('#stream-message');
|
|
|
|
assert_visible('#private-message');
|
|
|
|
|
|
|
|
assert.equal($('#private_message_recipient').val(), 'foo@example.com');
|
2017-11-26 20:37:44 +01:00
|
|
|
assert.equal($('#compose-textarea').val(), 'hello');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), 'private');
|
|
|
|
assert(compose_state.composing());
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
// Cancel compose.
|
|
|
|
assert_hidden('#compose_controls');
|
|
|
|
cancel();
|
|
|
|
assert_visible('#compose_controls');
|
|
|
|
assert_hidden('#private-message');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(!compose_state.composing());
|
2017-04-14 15:06:13 +02:00
|
|
|
}());
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
(function test_respond_to_message() {
|
|
|
|
// Test PM
|
|
|
|
var person = {
|
|
|
|
user_id: 22,
|
|
|
|
email: 'alice@example.com',
|
|
|
|
full_name: 'Alice',
|
|
|
|
};
|
|
|
|
people.add_in_realm(person);
|
|
|
|
|
|
|
|
var msg = {
|
|
|
|
type: 'private',
|
|
|
|
sender_id: person.user_id,
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
reply_type: 'personal',
|
|
|
|
};
|
|
|
|
|
|
|
|
respond_to_message(opts);
|
|
|
|
assert.equal($('#private_message_recipient').val(), 'alice@example.com');
|
|
|
|
|
|
|
|
// Test stream
|
|
|
|
msg = {
|
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
|
|
|
subject: 'python',
|
|
|
|
reply_to: 'bob', // compose.start needs this for dubious reasons
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
};
|
|
|
|
|
|
|
|
respond_to_message(opts);
|
|
|
|
assert.equal($('#stream').val(), 'devel');
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_reply_with_mention() {
|
|
|
|
var msg = {
|
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
|
|
|
subject: 'python',
|
|
|
|
reply_to: 'bob', // compose.start needs this for dubious reasons
|
|
|
|
sender_full_name: 'Bob Roberts',
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
2018-02-26 16:04:40 +01:00
|
|
|
var syntax_to_insert;
|
|
|
|
compose_ui.insert_syntax_and_focus = function (syntax) {
|
|
|
|
syntax_to_insert = syntax;
|
|
|
|
};
|
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
var opts = {
|
|
|
|
};
|
|
|
|
|
|
|
|
reply_with_mention(opts);
|
|
|
|
assert.equal($('#stream').val(), 'devel');
|
2018-02-26 16:04:40 +01:00
|
|
|
assert.equal(syntax_to_insert, '@**Bob Roberts**');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(compose_state.has_message_content());
|
2017-04-14 19:24:43 +02:00
|
|
|
}());
|
2017-04-14 16:26:00 +02:00
|
|
|
|
|
|
|
(function test_get_focus_area() {
|
|
|
|
assert.equal(get_focus_area('private', {}), 'private_message_recipient');
|
|
|
|
assert.equal(get_focus_area('private', {
|
2017-11-26 20:37:44 +01:00
|
|
|
private_message_recipient: 'bob@example.com'}), 'compose-textarea');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('stream', {}), 'stream');
|
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun'}),
|
|
|
|
'subject');
|
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun',
|
|
|
|
subject: 'more'}),
|
2017-11-26 20:37:44 +01:00
|
|
|
'compose-textarea');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun',
|
|
|
|
subject: 'more',
|
|
|
|
trigger: 'new topic button'}),
|
|
|
|
'subject');
|
|
|
|
}());
|
2017-09-18 21:54:06 +02:00
|
|
|
|
|
|
|
(function test_focus_in_empty_compose() {
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').is = function (attr) {
|
2017-09-18 21:54:06 +02:00
|
|
|
assert.equal(attr, ':focus');
|
2017-11-26 20:37:44 +01:00
|
|
|
return $('#compose-textarea').is_focused;
|
2017-09-18 21:54:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
compose_state.composing = return_true;
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').val('');
|
|
|
|
$('#compose-textarea').focus();
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(compose_state.focus_in_empty_compose());
|
|
|
|
|
|
|
|
compose_state.composing = return_false;
|
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').val('foo');
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').blur();
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
}());
|