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 = {
|
|
|
|
stream_id: 1,
|
|
|
|
name: "Denmark",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
const sweden = {
|
|
|
|
stream_id: 2,
|
|
|
|
name: "Sweden",
|
|
|
|
subscribed: false,
|
|
|
|
};
|
|
|
|
|
2021-01-21 15:55:49 +01:00
|
|
|
peer_data.set_subscribers(denmark.stream_id, [1, 2, 3]);
|
|
|
|
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);
|
|
|
|
});
|