node tests: Directly test simple stream_pill helpers.

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

View File

@@ -10,17 +10,17 @@ const stream_data = zrequire("stream_data");
const stream_pill = zrequire("stream_pill");
const denmark = {
stream_id: 1,
stream_id: 101,
name: "Denmark",
subscribed: true,
};
const sweden = {
stream_id: 2,
stream_id: 102,
name: "Sweden",
subscribed: false,
};
peer_data.set_subscribers(denmark.stream_id, [1, 2, 3]);
peer_data.set_subscribers(denmark.stream_id, [1, 2, 3, 77]);
peer_data.set_subscribers(sweden.stream_id, [1, 2, 3, 4, 5]);
const denmark_pill = {
@@ -56,3 +56,19 @@ run_test("create_item", () => {
run_test("get_stream_id", () => {
assert.equal(stream_pill.get_stream_name_from_item(denmark_pill), denmark.name);
});
run_test("get_user_ids", () => {
const items = [denmark_pill, sweden_pill];
const widget = {items: () => items};
const user_ids = stream_pill.get_user_ids(widget);
assert.deepEqual(user_ids, [1, 2, 3, 4, 5, 77]);
});
run_test("get_stream_ids", () => {
const items = [denmark_pill, sweden_pill];
const widget = {items: () => items};
const stream_ids = stream_pill.get_stream_ids(widget);
assert.deepEqual(stream_ids, [101, 102]);
});

View File

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