2018-03-19 05:52:37 +01:00
|
|
|
set_global('blueslip', {});
|
|
|
|
global.blueslip.warn = function () {};
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2017-11-08 16:59:01 +01:00
|
|
|
zrequire('stream_data');
|
|
|
|
zrequire('people');
|
|
|
|
zrequire('compose_fade');
|
2017-02-23 23:39:43 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2017-02-23 23:39:43 +01:00
|
|
|
email: 'me@example.com',
|
|
|
|
user_id: 30,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2017-02-23 23:39:43 +01:00
|
|
|
email: 'alice@example.com',
|
|
|
|
user_id: 31,
|
|
|
|
full_name: 'Alice',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2017-02-23 23:39:43 +01:00
|
|
|
email: 'bob@example.com',
|
|
|
|
user_id: 32,
|
|
|
|
full_name: 'Bob',
|
|
|
|
};
|
|
|
|
|
2020-03-21 20:19:30 +01:00
|
|
|
people.add(me);
|
2017-02-23 23:39:43 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2020-03-21 20:19:30 +01:00
|
|
|
people.add(alice);
|
|
|
|
people.add(bob);
|
2017-02-23 23:39:43 +01:00
|
|
|
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('set_focused_recipient', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = {
|
2017-02-23 23:39:43 +01:00
|
|
|
stream_id: 101,
|
|
|
|
name: 'social',
|
|
|
|
subscribed: true,
|
2018-03-19 05:52:37 +01:00
|
|
|
can_access_subscribers: true,
|
2017-02-23 23:39:43 +01:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(sub);
|
2017-02-23 23:39:43 +01:00
|
|
|
stream_data.set_subscribers(sub, [me.user_id, alice.user_id]);
|
|
|
|
|
|
|
|
global.$ = function (selector) {
|
|
|
|
switch (selector) {
|
2018-11-13 17:16:02 +01:00
|
|
|
case '#stream_message_recipient_stream':
|
2017-02-23 23:39:43 +01:00
|
|
|
return {
|
|
|
|
val: function () {
|
|
|
|
return 'social';
|
|
|
|
},
|
|
|
|
};
|
2018-11-13 17:16:02 +01:00
|
|
|
case '#stream_message_recipient_topic':
|
2017-02-23 23:39:43 +01:00
|
|
|
return {
|
|
|
|
val: function () {
|
|
|
|
return 'lunch';
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
compose_fade.set_focused_recipient('stream');
|
|
|
|
|
2018-04-25 01:05:57 +02:00
|
|
|
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);
|
2017-02-24 01:20:49 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const good_msg = {
|
2017-02-24 01:20:49 +01:00
|
|
|
type: 'stream',
|
2017-02-23 03:53:02 +01:00
|
|
|
stream_id: 101,
|
2020-02-14 13:59:37 +01:00
|
|
|
topic: 'lunch',
|
2017-02-24 01:20:49 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const bad_msg = {
|
2017-02-24 01:20:49 +01:00
|
|
|
type: 'stream',
|
2017-02-23 03:53:02 +01:00
|
|
|
stream_id: 999,
|
2020-02-14 13:59:37 +01:00
|
|
|
topic: 'lunch',
|
2017-02-24 01:20:49 +01:00
|
|
|
};
|
|
|
|
assert(!compose_fade.should_fade_message(good_msg));
|
|
|
|
assert(compose_fade.should_fade_message(bad_msg));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|