mirror of https://github.com/zulip/zulip.git
node tests: Directly test user_group_pill helpers.
We also sort user_ids to be deterministic.
This commit is contained in:
parent
0452f49c97
commit
1bf9a9e84a
|
@ -11,14 +11,14 @@ const user_group_pill = zrequire("user_group_pill");
|
||||||
const admins = {
|
const admins = {
|
||||||
name: "Admins",
|
name: "Admins",
|
||||||
description: "foo",
|
description: "foo",
|
||||||
id: 1,
|
id: 101,
|
||||||
members: [10, 20],
|
members: [10, 20],
|
||||||
};
|
};
|
||||||
const testers = {
|
const testers = {
|
||||||
name: "Testers",
|
name: "Testers",
|
||||||
description: "bar",
|
description: "bar",
|
||||||
id: 2,
|
id: 102,
|
||||||
members: [20, 30, 40],
|
members: [20, 50, 30, 40],
|
||||||
};
|
};
|
||||||
|
|
||||||
const admins_pill = {
|
const admins_pill = {
|
||||||
|
@ -54,3 +54,19 @@ run_test("create_item", () => {
|
||||||
run_test("get_stream_id", () => {
|
run_test("get_stream_id", () => {
|
||||||
assert.equal(user_group_pill.get_group_name_from_item(admins_pill), admins.name);
|
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]);
|
||||||
|
});
|
||||||
|
|
|
@ -44,6 +44,7 @@ export function get_user_ids(pill_widget) {
|
||||||
const items = pill_widget.items();
|
const items = pill_widget.items();
|
||||||
let user_ids = get_user_ids_from_user_groups(items);
|
let user_ids = get_user_ids_from_user_groups(items);
|
||||||
user_ids = Array.from(new Set(user_ids));
|
user_ids = Array.from(new Set(user_ids));
|
||||||
|
user_ids.sort((a, b) => a - b);
|
||||||
|
|
||||||
user_ids = user_ids.filter(Boolean);
|
user_ids = user_ids.filter(Boolean);
|
||||||
return user_ids;
|
return user_ids;
|
||||||
|
|
Loading…
Reference in New Issue