Files
mangabaka-seeder/test/view-model.test.ts
T

41 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from "bun:test";
import type { ReviewCard } from "../src/core/session";
import { GRANULARITY_LABELS, cardFacts, defaultHost, hostChoices, stageText } from "../src/web/view-model";
import { inspected } from "./helpers/covers";
test("hosts: server first when it has room; hidden without storage; disabled when full", () => {
const ids = (c: ReturnType<typeof hostChoices>) => c.map((h) => `${h.id}${h.disabled ? "(disabled)" : ""}`);
expect(ids(hostChoices({ storage: true, storageFull: false }, {}, { catboxNeedsServer: true }))).toEqual(["server", "litterbox", "catbox", "direct"]);
expect(ids(hostChoices({ storage: false, storageFull: false }, {}, { catboxNeedsServer: true }))).toEqual(["litterbox", "catbox", "direct"]);
const full = hostChoices({ storage: true, storageFull: true }, {}, { catboxNeedsServer: true });
expect(ids(full)).toEqual(["server(disabled)", "litterbox", "catbox", "direct"]);
expect(defaultHost(full)).toBe("litterbox");
expect(ids(hostChoices(null, {}, { catboxNeedsServer: true }))).toEqual(["litterbox", "catbox(disabled)", "direct"]);
expect(ids(hostChoices(null, {}, { catboxNeedsServer: false }))).toEqual(["litterbox", "catbox", "direct"]);
});
test("litterbox carries the review-time warning and its chosen lifetime", () => {
const litterbox = hostChoices(null, { litterboxTime: "24h" }, { catboxNeedsServer: false })[0]!;
expect(litterbox.lifetime).toBe("24 hours");
expect(litterbox.warning).toMatch(/review can take longer/);
});
test("stage text with and without progress", () => {
expect(stageText("history")).toBe("Looking through the Wayback Machine…");
expect(stageText("history", 3, 24)).toBe("Looking through the Wayback Machine… 3/24");
});
test("granularity labels", () => {
expect(GRANULARITY_LABELS).toEqual({ 1: "every month", 3: "every 3 months", 6: "every 6 months", 12: "every year" });
});
test("card facts: size, shape, when seen, archive-only", () => {
const card = (cover: ReturnType<typeof inspected>): ReviewCard =>
({ cover, selected: true, type: cover.type, note: "", contentRating: "safe", hostedUrl: null, error: null });
expect(cardFacts(card(inspected({ bytes: new Uint8Array(352813) })))).toEqual(["480×623", "345 KB", "on the page now"]);
expect(cardFacts(card(inspected({
width: 720, height: 1230, shape: "tall", live: false, bytes: new Uint8Array(2048),
candidate: { current: false, seenAt: "20230401000000", lastSeenAt: "20260301000000" },
})))).toEqual(["720×1230", "2 KB", "landing-page art", "seen 2023-04 – 2026-03", "only on archive.org"]);
});