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
|
|
|
|
2020-07-24 17:44:09 +02:00
|
|
|
zrequire("stream_data");
|
|
|
|
zrequire("stream_pill");
|
|
|
|
|
|
|
|
const denmark = {
|
|
|
|
stream_id: 1,
|
|
|
|
name: "Denmark",
|
|
|
|
subscribed: true,
|
|
|
|
subscriber_count: 10,
|
|
|
|
};
|
|
|
|
const sweden = {
|
|
|
|
stream_id: 2,
|
|
|
|
name: "Sweden",
|
|
|
|
subscribed: false,
|
|
|
|
subscriber_count: 30,
|
|
|
|
};
|
|
|
|
|
|
|
|
const denmark_pill = {
|
|
|
|
stream_name: denmark.name,
|
|
|
|
stream_id: denmark.stream_id,
|
|
|
|
display_value: "#" + denmark.name + ": " + denmark.subscriber_count + " users",
|
|
|
|
};
|
|
|
|
const sweden_pill = {
|
|
|
|
stream_name: sweden.name,
|
|
|
|
stream_id: sweden.stream_id,
|
|
|
|
display_value: "#" + sweden.name + ": " + sweden.subscriber_count + " users",
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|