mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 08:33:43 +00:00
We extract compose_fade_users and compose_fade_helper.
This is a pretty verbatim extraction of code, apart from adding a few
exports and changing the callers.
This change makes the buddy_data module no longer sit "above" these
files in the dependency graph (at least not via compose_fade):
* jquery
* lodash (not a big deal)
* compose_state
* floating_recipient_bar
* message_viewport
* rows
The new moules have dependencies that buddy_data already
had directly for other reasons:
* people
* util
And then buddy_data still depends on stream_data indirectly through
the compose-fade logic for stream_data. Even without compose-fade, it
would depend indirectly on stream_data via hash_util.
Note that we could have lifted the calls to compose_fade out of
buddy_data to move some dependencies around, but it's useful to have
buddy_data fully encapsulate what goes into the buddy list without
spreading responsibilities to things like activity.js and
buddy_list.js. We can now unit-test the logic at the level of
buddy_data, which is a lot easier than trying to do it via modules
that delegate drawing or do drawing (such as activity.js and
buddy_list.js).
Note that we still don't have 100% line coverage on the
compose_fade.js module, but all the code that we extracted now is
covered, mostly via buddy_data tests.
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
const {mock_cjs, zrequire} = require("../zjsunit/namespace");
|
|
const {run_test} = require("../zjsunit/test");
|
|
|
|
mock_cjs("jquery", (selector) => {
|
|
switch (selector) {
|
|
case "#stream_message_recipient_stream":
|
|
return {
|
|
val() {
|
|
return "social";
|
|
},
|
|
};
|
|
case "#stream_message_recipient_topic":
|
|
return {
|
|
val() {
|
|
return "lunch";
|
|
},
|
|
};
|
|
default:
|
|
throw new Error(`Unknown selector ${selector}`);
|
|
}
|
|
});
|
|
|
|
const stream_data = zrequire("stream_data");
|
|
const peer_data = zrequire("peer_data");
|
|
const people = zrequire("people");
|
|
const compose_fade = zrequire("compose_fade");
|
|
const compose_fade_helper = zrequire("compose_fade_helper");
|
|
|
|
const me = {
|
|
email: "me@example.com",
|
|
user_id: 30,
|
|
full_name: "Me Myself",
|
|
};
|
|
|
|
const alice = {
|
|
email: "alice@example.com",
|
|
user_id: 31,
|
|
full_name: "Alice",
|
|
};
|
|
|
|
const bob = {
|
|
email: "bob@example.com",
|
|
user_id: 32,
|
|
full_name: "Bob",
|
|
};
|
|
|
|
people.add_active_user(me);
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
people.add_active_user(alice);
|
|
people.add_active_user(bob);
|
|
|
|
run_test("set_focused_recipient", () => {
|
|
const sub = {
|
|
stream_id: 101,
|
|
name: "social",
|
|
subscribed: true,
|
|
can_access_subscribers: true,
|
|
};
|
|
|
|
compose_fade.set_focused_recipient("stream");
|
|
|
|
// If a stream is unknown, then we turn off the compose-fade
|
|
// feature, since a mix won't happen if the message can't be
|
|
// delivered.
|
|
stream_data.clear_subscriptions();
|
|
assert.equal(compose_fade_helper.would_receive_message(bob.user_id), true);
|
|
|
|
stream_data.add_sub(sub);
|
|
peer_data.set_subscribers(sub.stream_id, [me.user_id, alice.user_id]);
|
|
compose_fade.set_focused_recipient("stream");
|
|
|
|
assert.equal(compose_fade_helper.would_receive_message(me.user_id), true);
|
|
assert.equal(compose_fade_helper.would_receive_message(alice.user_id), true);
|
|
assert.equal(compose_fade_helper.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_helper.should_fade_message(good_msg));
|
|
assert(compose_fade_helper.should_fade_message(bad_msg));
|
|
});
|