// Which credits block ends an item, and what skipping each marker does. An item can carry several // credits blocks — mid- and post-credit scenes play between them — and only the last one may move // on to the next item; only the one Plex itself flags as the end may do so on its own. import { describe, it, expect } from "vitest"; import type { PlexMarker } from "./api"; import { markerSkip } from "./plexMarkers"; const credits = (start_s: number, end_s: number, final = false): PlexMarker => ({ type: "credits", start_s, end_s, final, }); const intro: PlexMarker = { type: "intro", start_s: 10, end_s: 60, final: false }; describe("markerSkip", () => { it("an intro jumps to its end, on its own when the viewer wants that", () => { expect(markerSkip(intro, [intro])).toEqual({ leaves: false, auto: true }); }); it("only the credits Plex flags final leave the item, and only they may do it on their own", () => { const first = credits(6811, 6831); const middle = credits(7039, 7507); const end = credits(7549, 7559, true); const all = [intro, first, middle, end]; expect(markerSkip(first, all)).toEqual({ leaves: false, auto: false }); expect(markerSkip(middle, all)).toEqual({ leaves: false, auto: false }); expect(markerSkip(end, all)).toEqual({ leaves: true, auto: true }); }); it("with no credits flagged final the last one is the end, but leaves only when asked", () => { const first = credits(2000, 2100); const last = credits(2900, 2995); // listed out of order on purpose: "last" is by time, not by position in the list expect(markerSkip(last, [last, first])).toEqual({ leaves: true, auto: false }); expect(markerSkip(first, [last, first])).toEqual({ leaves: false, auto: false }); expect(markerSkip(last, [last])).toEqual({ leaves: true, auto: false }); }); it("a final flag on an earlier block wins over a later block", () => { const end = credits(2000, 2100, true); const later = credits(2900, 2995); expect(markerSkip(end, [end, later])).toEqual({ leaves: true, auto: true }); expect(markerSkip(later, [end, later])).toEqual({ leaves: false, auto: false }); }); });