The header used to pick its pills by `page === …` and import five module controls, and Plex's Discover/Browse toggle needed a context bridge to reach the sub-view that lives in PlexBrowse. Now the header is an empty band: PageShell hands its root box out as a slot, a page portals its own pills into it (PageHeader), and the palette's Jump-to pill shows where no page does (PageHeaderDefault, rendered inside the page's Suspense so a loading page shows no stand-in). Plex's toggles take the sub-view as a prop; PlexViewBridge and its context are gone, and with them the header's five layer suppressions. No visible change: every header pill's box measured identical against the previous build on eight pages, in Hungarian and English.
88 lines
3.5 KiB
TypeScript
88 lines
3.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// Contract of the header library-scope pill (scopes + browse modes): it renders the
|
|
// three library scopes PLUS the Playlist/Collection browse-mode entries, marks the active one, writes a
|
|
// picked scope to the provider, and drives the playlists/collections views through the `view` it is handed.
|
|
// i18n is key-passthrough and the provider is mocked; SegmentedToggle is a plain
|
|
// button group (no floating-ui), so no observer stubs are needed.
|
|
import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
|
|
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
|
|
|
vi.mock("react-i18next", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react-i18next")>();
|
|
return { ...actual, useTranslation: () => ({ t: (key: string) => key }) };
|
|
});
|
|
|
|
const plexState = { scope: "both" } as { scope: string };
|
|
const setScope = vi.fn();
|
|
vi.mock("./plexContext", () => ({
|
|
usePlex: () => plexState,
|
|
usePlexActions: () => ({ setScope }),
|
|
}));
|
|
|
|
// The sub-view: a controllable current view kind + an open spy.
|
|
const controls = { kind: "discover" as PlexViewControls["kind"], open: vi.fn() };
|
|
|
|
import PlexScopeToggle from "./PlexScopeToggle";
|
|
import type { PlexViewControls } from "./plexSubUrl";
|
|
|
|
beforeEach(() => {
|
|
plexState.scope = "both";
|
|
controls.kind = "discover";
|
|
setScope.mockReset();
|
|
controls.open.mockReset();
|
|
});
|
|
afterEach(cleanup);
|
|
|
|
const buttons = () => [
|
|
...screen.getByRole("group", { name: "plex.filter.scope" }).querySelectorAll("button"),
|
|
];
|
|
const labels = () => buttons().map((b) => b.textContent);
|
|
const pressed = () =>
|
|
buttons()
|
|
.filter((b) => b.getAttribute("aria-pressed") === "true")
|
|
.map((b) => b.textContent);
|
|
|
|
describe("PlexScopeToggle", () => {
|
|
it("renders the three scopes plus the two browse modes, the current scope pressed", () => {
|
|
plexState.scope = "movie";
|
|
render(<PlexScopeToggle view={controls} />);
|
|
expect(labels()).toEqual([
|
|
"plex.filter.scopeOpt.both",
|
|
"plex.filter.scopeOpt.movie",
|
|
"plex.filter.scopeOpt.show",
|
|
"plex.filter.scopeOpt.playlists",
|
|
"plex.filter.scopeOpt.collections",
|
|
]);
|
|
expect(pressed()).toEqual(["plex.filter.scopeOpt.movie"]);
|
|
});
|
|
|
|
it("writes a picked scope back to the provider (no view switch when already on a title view)", () => {
|
|
render(<PlexScopeToggle view={controls} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "plex.filter.scopeOpt.show" }));
|
|
expect(setScope).toHaveBeenCalledWith("show");
|
|
expect(controls.open).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("opens the playlists view (not a scope change) for the Playlist mode", () => {
|
|
render(<PlexScopeToggle view={controls} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "plex.filter.scopeOpt.playlists" }));
|
|
expect(controls.open).toHaveBeenCalledWith({ kind: "playlists" });
|
|
expect(setScope).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("marks the Collection mode active when the current view is collections", () => {
|
|
controls.kind = "collections";
|
|
render(<PlexScopeToggle view={controls} />);
|
|
expect(pressed()).toEqual(["plex.filter.scopeOpt.collections"]);
|
|
});
|
|
|
|
it("returns to the title grid when a scope is picked from a browse mode", () => {
|
|
controls.kind = "playlists";
|
|
render(<PlexScopeToggle view={controls} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "plex.filter.scopeOpt.movie" }));
|
|
expect(setScope).toHaveBeenCalledWith("movie");
|
|
expect(controls.open).toHaveBeenCalledWith({ kind: "grid" });
|
|
});
|
|
});
|