mirror of
https://github.com/zulip/zulip.git
synced 2026-06-30 21:11:04 +08:00
We previously allowed adding pills for inaccessible user by typing the email manually. This commit updates it to handle inaccessible users like we handle invalid emails.
152 lines
4.3 KiB
JavaScript
152 lines
4.3 KiB
JavaScript
"use strict";
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
const {run_test} = require("./lib/test");
|
|
const blueslip = require("./lib/zblueslip");
|
|
const {page_params} = require("./lib/zpage_params");
|
|
|
|
const people = zrequire("people");
|
|
const user_pill = zrequire("user_pill");
|
|
|
|
const settings_data = mock_esm("../src/settings_data");
|
|
|
|
const alice = {
|
|
email: "[email protected]",
|
|
user_id: 99,
|
|
full_name: "Alice Barson",
|
|
};
|
|
|
|
const isaac = {
|
|
email: "[email protected]",
|
|
user_id: 102,
|
|
full_name: "Isaac Newton",
|
|
};
|
|
|
|
const bogus_item = {
|
|
email: "[email protected]",
|
|
type: "user",
|
|
display_value: "[email protected]",
|
|
// status_emoji_info: undefined,
|
|
};
|
|
|
|
const isaac_item = {
|
|
email: "[email protected]",
|
|
display_value: "Isaac Newton",
|
|
type: "user",
|
|
user_id: isaac.user_id,
|
|
deactivated: false,
|
|
img_src: `http://zulip.zulipdev.com/avatar/${isaac.user_id}?s=50`,
|
|
status_emoji_info: undefined,
|
|
should_add_guest_user_indicator: false,
|
|
};
|
|
|
|
const inaccessible_user_id = 103;
|
|
|
|
const inaccessible_user_item = {
|
|
email: "[email protected]",
|
|
display_value: "translated: Unknown user",
|
|
type: "user",
|
|
user_id: inaccessible_user_id,
|
|
deactivated: false,
|
|
img_src: `http://zulip.zulipdev.com/avatar/${inaccessible_user_id}?s=50`,
|
|
status_emoji_info: undefined,
|
|
should_add_guest_user_indicator: false,
|
|
};
|
|
|
|
let pill_widget = {};
|
|
|
|
function test(label, f) {
|
|
run_test(label, ({override}) => {
|
|
people.init();
|
|
people.add_active_user(alice);
|
|
people.add_active_user(isaac);
|
|
pill_widget = {};
|
|
f({override});
|
|
});
|
|
}
|
|
|
|
test("create_item", () => {
|
|
function test_create_item(email, current_items, expected_item, pill_config) {
|
|
const item = user_pill.create_item_from_email(email, current_items, pill_config);
|
|
assert.deepEqual(item, expected_item);
|
|
}
|
|
|
|
page_params.realm_is_zephyr_mirror_realm = true;
|
|
|
|
test_create_item("[email protected]", [], bogus_item);
|
|
test_create_item("[email protected]", [bogus_item], undefined);
|
|
|
|
test_create_item("[email protected]", [], isaac_item);
|
|
test_create_item("[email protected]", [isaac_item], undefined);
|
|
|
|
page_params.realm_is_zephyr_mirror_realm = false;
|
|
|
|
test_create_item("[email protected]", [], undefined);
|
|
test_create_item("[email protected]", [], isaac_item);
|
|
test_create_item("[email protected]", [isaac_item], undefined);
|
|
|
|
settings_data.user_can_access_all_other_users = () => false;
|
|
page_params.realm_bot_domain = "example.com";
|
|
people.add_inaccessible_user(inaccessible_user_id);
|
|
|
|
test_create_item("[email protected]", [], undefined, {exclude_inaccessible_users: true});
|
|
test_create_item("[email protected]", [], inaccessible_user_item, {
|
|
exclude_inaccessible_users: false,
|
|
});
|
|
});
|
|
|
|
test("get_email", () => {
|
|
assert.equal(user_pill.get_email_from_item({email: "[email protected]"}), "[email protected]");
|
|
});
|
|
|
|
test("append", () => {
|
|
let appended;
|
|
let cleared;
|
|
|
|
function fake_append(opts) {
|
|
appended = true;
|
|
assert.equal(opts.email, isaac.email);
|
|
assert.equal(opts.display_value, isaac.full_name);
|
|
assert.equal(opts.user_id, isaac.user_id);
|
|
assert.equal(opts.img_src, isaac_item.img_src);
|
|
}
|
|
|
|
function fake_clear() {
|
|
cleared = true;
|
|
}
|
|
|
|
pill_widget.appendValidatedData = fake_append;
|
|
pill_widget.clear_text = fake_clear;
|
|
|
|
user_pill.append_person({
|
|
person: isaac,
|
|
pill_widget,
|
|
});
|
|
|
|
assert.ok(appended);
|
|
assert.ok(cleared);
|
|
|
|
blueslip.expect("warn", "Undefined user in function append_user");
|
|
user_pill.append_user(undefined, pill_widget);
|
|
});
|
|
|
|
test("get_items", () => {
|
|
const items = [isaac_item, bogus_item];
|
|
pill_widget.items = () => items;
|
|
|
|
assert.deepEqual(user_pill.get_user_ids(pill_widget), [isaac.user_id]);
|
|
});
|
|
|
|
test("typeahead", () => {
|
|
const items = [isaac_item, bogus_item];
|
|
pill_widget.items = () => items;
|
|
|
|
// Both alice and isaac are in our realm, but isaac will be
|
|
// excluded by virtue of already being one of the widget items.
|
|
// And then bogus_item is just a red herring to test robustness.
|
|
const result = user_pill.typeahead_source(pill_widget);
|
|
assert.deepEqual(result, [alice]);
|
|
});
|