zulip/frontend_tests/node_tests/compose_fade.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

"use strict";
zrequire("stream_data");
2020-08-20 21:24:06 +02:00
const people = zrequire("people");
zrequire("compose_fade");
2017-02-23 23:39:43 +01:00
const me = {
email: "me@example.com",
2017-02-23 23:39:43 +01:00
user_id: 30,
full_name: "Me Myself",
2017-02-23 23:39:43 +01:00
};
const alice = {
email: "alice@example.com",
2017-02-23 23:39:43 +01:00
user_id: 31,
full_name: "Alice",
2017-02-23 23:39:43 +01:00
};
const bob = {
email: "bob@example.com",
2017-02-23 23:39:43 +01:00
user_id: 32,
full_name: "Bob",
2017-02-23 23:39:43 +01:00
};
people.add_active_user(me);
2017-02-23 23:39:43 +01:00
people.initialize_current_user(me.user_id);
people.add_active_user(alice);
people.add_active_user(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",
2017-02-23 23:39:43 +01:00
subscribed: true,
can_access_subscribers: true,
2017-02-23 23:39:43 +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) {
case "#stream_message_recipient_stream":
return {
val() {
return "social";
},
};
case "#stream_message_recipient_topic":
return {
val() {
return "lunch";
},
};
2017-02-23 23:39:43 +01:00
}
};
compose_fade.set_focused_recipient("stream");
2017-02-23 23:39:43 +01:00
assert.equal(compose_fade.would_receive_message(me.user_id), true);
assert.equal(compose_fade.would_receive_message(alice.user_id), true);
assert.equal(compose_fade.would_receive_message(bob.user_id), false);
const good_msg = {
type: "stream",
stream_id: 101,
topic: "lunch",
};
const bad_msg = {
type: "stream",
stream_id: 999,
topic: "lunch",
};
assert(!compose_fade.should_fade_message(good_msg));
assert(compose_fade.should_fade_message(bad_msg));
});