2020-07-24 17:44:09 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-01-21 15:55:49 +01:00
|
|
|
const peer_data = zrequire("peer_data");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const stream_pill = zrequire("stream_pill");
|
2020-07-24 17:44:09 +02:00
|
|
|
|
|
|
|
const denmark = {
|
2022-02-22 15:25:13 +01:00
|
|
|
stream_id: 101,
|
2020-07-24 17:44:09 +02:00
|
|
|
name: "Denmark",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
const sweden = {
|
2022-02-22 15:25:13 +01:00
|
|
|
stream_id: 102,
|
2020-07-24 17:44:09 +02:00
|
|
|
name: "Sweden",
|
|
|
|
subscribed: false,
|
|
|
|
};
|
|
|
|
|
2022-02-22 15:25:13 +01:00
|
|
|
peer_data.set_subscribers(denmark.stream_id, [1, 2, 3, 77]);
|
2021-01-21 15:55:49 +01:00
|
|
|
peer_data.set_subscribers(sweden.stream_id, [1, 2, 3, 4, 5]);
|
|
|
|
|
2020-07-24 17:44:09 +02:00
|
|
|
const denmark_pill = {
|
|
|
|
stream_name: denmark.name,
|
|
|
|
stream_id: denmark.stream_id,
|
2021-04-27 16:56:20 +02:00
|
|
|
type: "stream",
|
2021-01-21 15:55:49 +01:00
|
|
|
display_value: "#Denmark: 3 users",
|
2020-07-24 17:44:09 +02:00
|
|
|
};
|
|
|
|
const sweden_pill = {
|
|
|
|
stream_name: sweden.name,
|
|
|
|
stream_id: sweden.stream_id,
|
2021-04-27 16:56:20 +02:00
|
|
|
type: "stream",
|
2021-01-21 15:55:49 +01:00
|
|
|
display_value: "#Sweden: 5 users",
|
2020-07-24 17:44:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const subs = [denmark, sweden];
|
|
|
|
for (const sub of subs) {
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test("create_item", () => {
|
|
|
|
function test_create_item(stream_name, current_items, expected_item) {
|
|
|
|
const item = stream_pill.create_item_from_stream_name(stream_name, current_items);
|
|
|
|
assert.deepEqual(item, expected_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_create_item("sweden", [], undefined);
|
|
|
|
test_create_item("#sweden", [sweden_pill], undefined);
|
|
|
|
test_create_item(" #sweden", [], sweden_pill);
|
|
|
|
test_create_item("#test", [], undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("get_stream_id", () => {
|
|
|
|
assert.equal(stream_pill.get_stream_name_from_item(denmark_pill), denmark.name);
|
|
|
|
});
|
2022-02-22 15:25:13 +01:00
|
|
|
|
|
|
|
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]);
|
|
|
|
});
|