node tests: Directly test user_group_pill helpers.

We also sort user_ids to be deterministic.
This commit is contained in:
Steve Howell 2022-02-22 14:54:14 +00:00 committed by Tim Abbott
parent 0452f49c97
commit 1bf9a9e84a
2 changed files with 20 additions and 3 deletions

View File

@ -11,14 +11,14 @@ const user_group_pill = zrequire("user_group_pill");
const admins = {
name: "Admins",
description: "foo",
id: 1,
id: 101,
members: [10, 20],
};
const testers = {
name: "Testers",
description: "bar",
id: 2,
members: [20, 30, 40],
id: 102,
members: [20, 50, 30, 40],
};
const admins_pill = {
@ -54,3 +54,19 @@ run_test("create_item", () => {
run_test("get_stream_id", () => {
assert.equal(user_group_pill.get_group_name_from_item(admins_pill), admins.name);
});
run_test("get_user_ids", () => {
const items = [admins_pill, testers_pill];
const widget = {items: () => items};
const user_ids = user_group_pill.get_user_ids(widget);
assert.deepEqual(user_ids, [10, 20, 30, 40, 50]);
});
run_test("get_group_ids", () => {
const items = [admins_pill, testers_pill];
const widget = {items: () => items};
const group_ids = user_group_pill.get_group_ids(widget);
assert.deepEqual(group_ids, [101, 102]);
});

View File

@ -44,6 +44,7 @@ export function get_user_ids(pill_widget) {
const items = pill_widget.items();
let user_ids = get_user_ids_from_user_groups(items);
user_ids = Array.from(new Set(user_ids));
user_ids.sort((a, b) => a - b);
user_ids = user_ids.filter(Boolean);
return user_ids;