Files
zulip/frontend_tests/node_tests/compose.js
Steve Howell 70b7d4c00b Extract compose_state.js.
This is mostly just moving methods out of compose.js.

The variable `is_composing_message`, which isn't a boolean, has
been renamed to `message_type`, and there are new functions
set_message_type() and get_message_type() that wrap it.

This commit removes some shims related to the global variable
`compose_state`; now, `compose_state` is a typical global
variable with a 1:1 relationship with the module by the same
name.

The new module has 100% line coverage, most of it coming
via the tests on compose_actions.js.  (The methods here are
super simple, so it's a good thing that the tests are somewhat
integrated with a higher layer.)
2017-04-18 12:26:58 -07:00

93 lines
1.8 KiB
JavaScript

set_global('$', function () {
});
set_global('page_params', {
use_websockets: false,
});
set_global('document', {
location: {
},
});
add_dependencies({
compose_state: 'js/compose_state',
people: 'js/people',
stream_data: 'js/stream_data',
util: 'js/util',
});
var compose = require('js/compose.js');
var me = {
email: 'me@example.com',
user_id: 30,
full_name: 'Me Myself',
};
var alice = {
email: 'alice@example.com',
user_id: 31,
full_name: 'Alice',
};
var bob = {
email: 'bob@example.com',
user_id: 32,
full_name: 'Bob',
};
people.add(me);
people.initialize_current_user(me.user_id);
people.add(alice);
people.add(bob);
(function test_set_focused_recipient() {
var sub = {
stream_id: 101,
name: 'social',
subscribed: true,
};
stream_data.add_sub('social', sub);
var page = {
'#stream': 'social',
'#subject': 'lunch',
'#new_message_content': 'burrito',
'#private_message_recipient': 'alice@example.com, bob@example.com',
};
global.$ = function (selector) {
return {
val: function () {
return page[selector];
},
};
};
global.compose_state.composing = function () {
return 'stream';
};
global.$.trim = function (s) {
return s;
};
var message = compose.create_message_object();
assert.equal(message.to, 'social');
assert.equal(message.subject, 'lunch');
assert.equal(message.content, 'burrito');
global.compose_state.composing = function () {
return 'private';
};
message = compose.create_message_object();
assert.deepEqual(message.to, ['alice@example.com', 'bob@example.com']);
assert.equal(message.to_user_ids, '31,32');
assert.equal(message.content, 'burrito');
}());