mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
This cleans up the handoff of page_params data between ui_init and modules that take over ownership of page_params-derived data. Read the long comment in ui_init for a bit more context. Most of this diff is actually test cleanup. And a lot of the diff to "real" code is just glorified `s/page_params/params/` in the `initialize` functions. One little oddity is that we don't actually surrender ownership of `page_params.user_id` to `people.js`. We could plausibly sweep the rest of the codebase to just use `people.my_user_id()` consistently, but it's not a super high priority thing to fix, since the value never changes. The stream_data situation is a bit messy, since we consume `page_params` data in the initialize() function in addition to the `params` data we "own". I added a comment there and intend to follow up. I tried to mostly avoid the "word soup" by extracting three locals at the top. Finally, I don't touch `alert_words` yet, despite it also doing the delete-page-params-data dance. The problem is that `alert_words` doesn't have a proper `initialize()`. We should clean that up and have it use a `Map` internally, too.
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
set_global('blueslip', global.make_zblueslip());
|
|
set_global('channel', {});
|
|
zrequire('user_status');
|
|
|
|
function initialize() {
|
|
const params = {
|
|
user_status: {
|
|
1: {away: true, status_text: 'in a meeting'},
|
|
2: {away: true},
|
|
3: {away: true},
|
|
},
|
|
};
|
|
user_status.initialize(params);
|
|
}
|
|
|
|
run_test('basics', () => {
|
|
initialize();
|
|
assert(user_status.is_away(2));
|
|
assert(!user_status.is_away(99));
|
|
|
|
assert(!user_status.is_away(4));
|
|
user_status.set_away(4);
|
|
assert(user_status.is_away(4));
|
|
user_status.revoke_away(4);
|
|
assert(!user_status.is_away(4));
|
|
|
|
assert.equal(user_status.get_status_text(1), 'in a meeting');
|
|
|
|
user_status.set_status_text({
|
|
user_id: 2,
|
|
status_text: 'out to lunch',
|
|
});
|
|
assert.equal(user_status.get_status_text(2), 'out to lunch');
|
|
|
|
user_status.set_status_text({
|
|
user_id: 2,
|
|
status_text: '',
|
|
});
|
|
assert.equal(user_status.get_status_text(2), undefined);
|
|
});
|
|
|
|
run_test('server', () => {
|
|
initialize();
|
|
|
|
let sent_data;
|
|
let success;
|
|
|
|
channel.post = (opts) => {
|
|
sent_data = opts.data;
|
|
assert.equal(opts.url, '/json/users/me/status');
|
|
success = opts.success;
|
|
};
|
|
|
|
assert.equal(sent_data, undefined);
|
|
|
|
user_status.server_set_away();
|
|
assert.deepEqual(sent_data, {away: true, status_text: undefined});
|
|
|
|
user_status.server_revoke_away();
|
|
assert.deepEqual(sent_data, {away: false, status_text: undefined});
|
|
|
|
let called;
|
|
|
|
user_status.server_update({
|
|
status_text: 'out to lunch',
|
|
success: () => {
|
|
called = true;
|
|
},
|
|
});
|
|
|
|
success();
|
|
assert(called);
|
|
});
|
|
|
|
run_test('defensive checks', () => {
|
|
blueslip.set_test_data('error', 'need ints for user_id');
|
|
user_status.set_away('string');
|
|
user_status.revoke_away('string');
|
|
});
|