Files
sofa/packages/core/test/display-status.test.ts
T
jake 1d67b201a0 chore: extract shared tsconfig, move display-status to core, add i18n tests
- Add `@sofa/tsconfig` package with a shared `base.json` (target, lib, strict, moduleResolution, etc.) and migrate all packages/apps to `"extends": "@sofa/tsconfig/base.json"` to eliminate duplicated compiler options
- Move `display-status.ts` (and its `DisplayStatus` type + `getDisplayStatus` fn) from `@sofa/api` to `@sofa/core`; remove the `./display-status` export from `@sofa/api` and update all import sites in `discovery.ts` and `tracking.ts`
- Add `packages/core/test/display-status.test.ts`: 15 tests covering `ONGOING_TMDB_STATUSES` and all `getDisplayStatus` branches (movie, TV watchlist/in_progress/caught_up/completed, edge cases)
- Add `packages/i18n/vitest.config.ts` and two new test files: `date-buckets.test.ts` and `format.test.ts` covering date bucketing and locale formatting utilities
2026-03-22 14:46:25 -04:00

106 lines
3.7 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { ONGOING_TMDB_STATUSES, getDisplayStatus } from "../src/display-status";
describe("ONGOING_TMDB_STATUSES", () => {
test("contains expected values", () => {
expect(ONGOING_TMDB_STATUSES).toContain("Returning Series");
expect(ONGOING_TMDB_STATUSES).toContain("In Production");
expect(ONGOING_TMDB_STATUSES).toHaveLength(2);
});
});
describe("getDisplayStatus", () => {
// -- Movies --
test("movie with watchlist status returns in_watchlist", () => {
expect(getDisplayStatus("watchlist", "movie", null, null)).toBe("in_watchlist");
});
test("movie with completed status returns completed", () => {
expect(getDisplayStatus("completed", "movie", null, null)).toBe("completed");
});
test("movie with in_progress status returns in_watchlist", () => {
// Movies don't have an "in_progress" concept — falls through to in_watchlist
expect(getDisplayStatus("in_progress", "movie", null, null)).toBe("in_watchlist");
});
// -- TV: watchlist --
test("TV with watchlist status returns in_watchlist", () => {
expect(getDisplayStatus("watchlist", "tv", "Returning Series", null)).toBe("in_watchlist");
});
// -- TV: in_progress, no/partial progress --
test("TV in_progress with no progress data returns watching", () => {
expect(getDisplayStatus("in_progress", "tv", "Returning Series", null)).toBe("watching");
});
test("TV in_progress with partial progress returns watching", () => {
expect(
getDisplayStatus("in_progress", "tv", "Returning Series", { watched: 3, total: 10 }),
).toBe("watching");
});
test("TV in_progress with zero total returns watching", () => {
expect(getDisplayStatus("in_progress", "tv", "Ended", { watched: 0, total: 0 })).toBe(
"watching",
);
});
// -- TV: in_progress, all watched, ongoing --
test("TV in_progress, all watched, Returning Series returns caught_up", () => {
expect(
getDisplayStatus("in_progress", "tv", "Returning Series", { watched: 10, total: 10 }),
).toBe("caught_up");
});
test("TV in_progress, all watched, In Production returns caught_up", () => {
expect(getDisplayStatus("in_progress", "tv", "In Production", { watched: 10, total: 10 })).toBe(
"caught_up",
);
});
// -- TV: in_progress, all watched, ended --
test("TV in_progress, all watched, Ended returns completed", () => {
expect(getDisplayStatus("in_progress", "tv", "Ended", { watched: 10, total: 10 })).toBe(
"completed",
);
});
test("TV in_progress, all watched, Canceled returns completed", () => {
expect(getDisplayStatus("in_progress", "tv", "Canceled", { watched: 5, total: 5 })).toBe(
"completed",
);
});
test("TV in_progress, all watched, null tmdbStatus returns completed", () => {
expect(getDisplayStatus("in_progress", "tv", null, { watched: 10, total: 10 })).toBe(
"completed",
);
});
// -- Edge cases --
test("TV in_progress, watched exceeds total still returns caught_up/completed", () => {
// watched > total shouldn't happen, but if it does, treat as all-watched
expect(
getDisplayStatus("in_progress", "tv", "Returning Series", { watched: 15, total: 10 }),
).toBe("caught_up");
expect(getDisplayStatus("in_progress", "tv", "Ended", { watched: 15, total: 10 })).toBe(
"completed",
);
});
test("TV completed status returns in_watchlist (no special handling)", () => {
// "completed" stored status on TV falls through the movie branch check
// titleType !== "movie" so it doesn't enter that branch, and storedStatus !== "watchlist"
// so it falls to the episode progress check → no progress → "watching"
expect(getDisplayStatus("completed", "tv", "Ended", null)).toBe("watching");
});
});