Files
zulip/frontend_tests/node_tests/user_pill.js
YashRE42 fa7c8f8c32 status_emoji: Show status emoji in compose_pm pills.
Previously the emoji_status set by the user would only be seen in a
few places, it was decided that it would be useful to show the
emoji_status in a couple of other additional places as well.

As such this commit uses the status_emoji template to show the status
emoji in the compose_pm pills. Due to the fact that we use the same
pills system to render in the user_group, we need to add a
conditional to prevent rendering there since the user status is not
valuable there.

Status emoji changes do not live update these, but neither do user
renames, so there's bigger problems if that's a concern.
2022-02-11 13:30:08 -08:00

123 lines
3.2 KiB
JavaScript

"use strict";
const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params");
const people = zrequire("people");
const user_pill = zrequire("user_pill");
const alice = {
email: "alice@example.com",
user_id: 99,
full_name: "Alice Barson",
};
const isaac = {
email: "isaac@example.com",
user_id: 102,
full_name: "Isaac Newton",
};
const bogus_item = {
email: "bogus@example.com",
type: "user",
display_value: "bogus@example.com",
// status_emoji_info: undefined,
};
const isaac_item = {
email: "isaac@example.com",
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,
};
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) {
const item = user_pill.create_item_from_email(email, current_items);
assert.deepEqual(item, expected_item);
}
page_params.realm_is_zephyr_mirror_realm = true;
test_create_item("bogus@example.com", [], bogus_item);
test_create_item("bogus@example.com", [bogus_item], undefined);
test_create_item("isaac@example.com", [], isaac_item);
test_create_item("isaac@example.com", [isaac_item], undefined);
page_params.realm_is_zephyr_mirror_realm = false;
test_create_item("bogus@example.com", [], undefined);
test_create_item("isaac@example.com", [], isaac_item);
test_create_item("isaac@example.com", [isaac_item], undefined);
});
test("get_email", () => {
assert.equal(user_pill.get_email_from_item({email: "foo@example.com"}), "foo@example.com");
});
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);
});
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]);
});