zulip/frontend_tests/node_tests/compose_fade.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

set_global('blueslip', {});
global.blueslip.warn = function () {};
2017-02-23 23:39:43 +01:00
zrequire('util');
zrequire('stream_data');
zrequire('people');
zrequire('compose_fade');
2017-02-23 23:39:43 +01:00
const me = {
2017-02-23 23:39:43 +01:00
email: 'me@example.com',
user_id: 30,
full_name: 'Me Myself',
};
const alice = {
2017-02-23 23:39:43 +01:00
email: 'alice@example.com',
user_id: 31,
full_name: 'Alice',
};
const bob = {
2017-02-23 23:39:43 +01:00
email: 'bob@example.com',
user_id: 32,
full_name: 'Bob',
};
people.add_in_realm(me);
2017-02-23 23:39:43 +01:00
people.initialize_current_user(me.user_id);
people.add_in_realm(alice);
people.add_in_realm(bob);
2017-02-23 23:39:43 +01:00
run_test('set_focused_recipient', () => {
const sub = {
2017-02-23 23:39:43 +01:00
stream_id: 101,
name: 'social',
subscribed: true,
can_access_subscribers: true,
2017-02-23 23:39:43 +01:00
};
stream_data.add_sub('social', sub);
stream_data.set_subscribers(sub, [me.user_id, alice.user_id]);
global.$ = function (selector) {
switch (selector) {
case '#stream_message_recipient_stream':
2017-02-23 23:39:43 +01:00
return {
val: function () {
return 'social';
},
};
case '#stream_message_recipient_topic':
2017-02-23 23:39:43 +01:00
return {
val: function () {
return 'lunch';
},
};
}
};
compose_fade.set_focused_recipient('stream');
assert.equal(compose_fade.would_receive_message('me@example.com'), true);
assert.equal(compose_fade.would_receive_message('alice@example.com'), true);
assert.equal(compose_fade.would_receive_message('bob@example.com'), false);
assert.equal(compose_fade.would_receive_message('nonrealmuser@example.com'), true);
const good_msg = {
type: 'stream',
stream_id: 101,
subject: 'lunch',
};
const bad_msg = {
type: 'stream',
stream_id: 999,
subject: 'lunch',
};
assert(!compose_fade.should_fade_message(good_msg));
assert(compose_fade.should_fade_message(bad_msg));
});