// @vitest-environment jsdom // // E30: what a Plex card says, in the reader's language. An episode in a poster rail stands as its show // (the show's poster and name, the episode on the line under it), and a season Plex named generically // ("Season 1", "Specials") is named from its number instead. i18n here echoes the key AND its values, // so an assertion can see which words went into the line. import { describe, it, expect, afterEach, vi } from "vitest"; import { render, screen, cleanup } from "@testing-library/react"; vi.mock("react-i18next", async (importOriginal) => { const actual = await importOriginal(); const t = (key: string, o?: Record) => o ? `${key}(${Object.values(o).join("|")})` : key; return { ...actual, useTranslation: () => ({ t }) }; }); import { PlexPosterCard, SeasonCard } from "./plexCards"; import type { PlexCard, PlexSeasonDetail } from "../lib/api"; afterEach(cleanup); const watchedEpisode: PlexCard = { id: "e5", type: "episode", title: "Visszaszámlálás", thumb: "/api/plex/image/e5", season_number: 2, episode_number: 5, show_title: "A 3-test-probléma", show_id: "s9", }; describe("an episode in a poster rail", () => { it("stands as its show: the show's poster and name, the episode under it", () => { render(); const img = document.querySelector("img"); expect(img?.getAttribute("src")).toBe("/api/plex/image/s9"); expect(screen.getByText("A 3-test-probléma")).toBeTruthy(); expect(screen.getByText("plex.episodeLine(2|5|Visszaszámlálás)")).toBeTruthy(); }); it("keeps its own landscape still where the rail is landscape, or the show is unknown", () => { const { unmount } = render(); expect(document.querySelector("img")?.getAttribute("src")).toBe("/api/plex/image/e5"); unmount(); render(); expect(document.querySelector("img")?.getAttribute("src")).toBe("/api/plex/image/e5"); expect(screen.getByText("Visszaszámlálás")).toBeTruthy(); }); }); const season = (title: string, n: number | null): PlexSeasonDetail => ({ id: "se", season_number: n, title, thumb: "", episode_count: 3, status: "new", episodes: [], }); describe("a season's name", () => { it.each([ ["Season 1", 1, "plex.seasonTitle(1)"], ["Specials", 0, "plex.specials"], ["Book One: Water", 1, "Book One: Water"], ])("Plex's %j (season %s) reads %j", (title, n, shown) => { render(); expect(screen.getByText(shown)).toBeTruthy(); }); });