node tests: Clean up subs test.

We start our stream_id sequence at 101, and we
clarify the somewhat strange assertions related
to the "active" class.
This commit is contained in:
Steve Howell 2021-02-04 18:08:19 +00:00 committed by Steve Howell
parent c407293577
commit 9fc1adce60
1 changed files with 19 additions and 11 deletions

View File

@ -15,8 +15,10 @@ zrequire("stream_data");
zrequire("search_util"); zrequire("search_util");
set_global("page_params", {}); set_global("page_params", {});
const denmark_stream_id = 101;
set_global("location", { set_global("location", {
hash: "#streams/1/announce", hash: `#streams/${denmark_stream_id}/announce`,
}); });
zrequire("subs"); zrequire("subs");
@ -45,7 +47,7 @@ run_test("filter_table", () => {
elem: "denmark", elem: "denmark",
subscribed: false, subscribed: false,
name: "Denmark", name: "Denmark",
stream_id: 1, stream_id: denmark_stream_id,
description: "Copenhagen", description: "Copenhagen",
subscribers: [1], subscribers: [1],
stream_weekly_traffic: null, stream_weekly_traffic: null,
@ -55,7 +57,7 @@ run_test("filter_table", () => {
elem: "poland", elem: "poland",
subscribed: true, subscribed: true,
name: "Poland", name: "Poland",
stream_id: 2, stream_id: 102,
description: "monday", description: "monday",
subscribers: [1, 2, 3], subscribers: [1, 2, 3],
stream_weekly_traffic: 13, stream_weekly_traffic: 13,
@ -65,7 +67,7 @@ run_test("filter_table", () => {
elem: "pomona", elem: "pomona",
subscribed: true, subscribed: true,
name: "Pomona", name: "Pomona",
stream_id: 3, stream_id: 103,
description: "college", description: "college",
subscribers: [], subscribers: [],
stream_weekly_traffic: 0, stream_weekly_traffic: 0,
@ -75,7 +77,7 @@ run_test("filter_table", () => {
elem: "cpp", elem: "cpp",
subscribed: true, subscribed: true,
name: "C++", name: "C++",
stream_id: 4, stream_id: 104,
description: "programming lang", description: "programming lang",
subscribers: [1, 2], subscribers: [1, 2],
stream_weekly_traffic: 6, stream_weekly_traffic: 6,
@ -85,7 +87,7 @@ run_test("filter_table", () => {
elem: "zzyzx", elem: "zzyzx",
subscribed: true, subscribed: true,
name: "Zzyzx", name: "Zzyzx",
stream_id: 5, stream_id: 105,
description: "california town", description: "california town",
subscribers: [1, 2], subscribers: [1, 2],
stream_weekly_traffic: 6, stream_weekly_traffic: 6,
@ -145,8 +147,19 @@ run_test("filter_table", () => {
assert.equal(elem, $("#subscription_overlay .streams-list")); assert.equal(elem, $("#subscription_overlay .streams-list"));
}; };
// Filtering has the side effect of setting the "active" class
// on our current stream, even if it doesn't match the filter.
const denmark_row = $(`.stream-row[data-stream-id='${denmark_stream_id}']`);
// sanity check it's not set to active
assert(!denmark_row.hasClass("active"));
// Search with single keyword // Search with single keyword
subs.filter_table({input: "Po", subscribed_only: false}); subs.filter_table({input: "Po", subscribed_only: false});
// The denmark row is active, even though it's not displayed.
assert(denmark_row.hasClass("active"));
// We only display poland and pomona
assert($(".stream-row-denmark").hasClass("notdisplayed")); assert($(".stream-row-denmark").hasClass("notdisplayed"));
assert(!$(".stream-row-poland").hasClass("notdisplayed")); assert(!$(".stream-row-poland").hasClass("notdisplayed"));
assert(!$(".stream-row-pomona").hasClass("notdisplayed")); assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
@ -302,9 +315,4 @@ run_test("filter_table", () => {
assert($(".stream-row-pomona").hasClass("notdisplayed")); assert($(".stream-row-pomona").hasClass("notdisplayed"));
assert($(".stream-row-cpp").hasClass("notdisplayed")); assert($(".stream-row-cpp").hasClass("notdisplayed"));
assert($(".stream-row-zzyzx").hasClass("notdisplayed")); assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
// test selected row set to active
$(".stream-row[data-stream-id='1']").removeClass("active");
subs.filter_table({input: "", subscribed_only: false});
assert($(".stream-row[data-stream-id='1']").hasClass("active"));
}); });