Files
siftlode/frontend/src/lib/plexQueue.test.ts
T
peter 2e319be569 refactor(plex): share showEpisodeKeys + honest empty Play-all
Extract the show->ordered-episode-keys flatten into one pure, unit-tested
helper (lib/plexQueue.ts) and use it at all three sites — the collection
Play-all (S4) and the show/season play-through pages in plexViews — so the
season-then-episode queue-order invariant lives in one place instead of three
hand-rolled copies. Behaviour-identical (the helper's ?? [] is a safe superset
of the collection site's previously non-null read).

Also: a show-collection whose shows expand to zero episodes had an enabled
Play-all that silently no-op'd — the same 'does nothing' state S4 removed for
the empty-queue case. Surface an honest info notice (plex.collection.playEmpty,
HU+EN) instead.
2026-08-24 22:09:52 +02:00

33 lines
1.2 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { showEpisodeKeys } from "./plexQueue";
import type { PlexCard, PlexSeasonDetail, PlexShowDetail } from "./api";
const ep = (id: string): PlexCard => ({ id }) as PlexCard;
const season = (episodes: PlexCard[]): PlexSeasonDetail =>
({ episodes }) as unknown as PlexSeasonDetail;
const show = (seasons: PlexSeasonDetail[]): PlexShowDetail =>
({ seasons }) as unknown as PlexShowDetail;
describe("showEpisodeKeys", () => {
it("flattens seasons in order, episodes in order, concatenated across seasons", () => {
const detail = show([
season([ep("s1e1"), ep("s1e2")]),
season([ep("s2e1"), ep("s2e2"), ep("s2e3")]),
]);
expect(showEpisodeKeys(detail)).toEqual(["s1e1", "s1e2", "s2e1", "s2e2", "s2e3"]);
});
it("returns [] for a show with no seasons", () => {
expect(showEpisodeKeys(show([]))).toEqual([]);
});
it("returns [] for a season with no episodes (the enabled-but-empty Play-all case)", () => {
expect(showEpisodeKeys(show([season([])]))).toEqual([]);
});
it("returns [] for null/undefined so an in-flight query's data passes straight through", () => {
expect(showEpisodeKeys(null)).toEqual([]);
expect(showEpisodeKeys(undefined)).toEqual([]);
});
});