cbb703341e
Slice 4b frontend half. Jellyfin-touching pages now select a Jellyfin service instance instead of a machine. - api/client.ts: Jellyfin-backed calls (counts/libraries/activity/users, media status/build/stop/force-stop, queryMedia) send jellyfin_service_id. - hooks/useDashboard, useUsers, useMedia: selector param renamed to jellyfinServiceId. - pages/Media + Applications: list jellyfin service instances and persist jellyfin_service_id in the URL. - Dashboard (widgets) and Users (default instance) need no selector change. - Update Applications + Media tests for the new hook/param. Files/SSH transport keeps machine_id. Verification: frontend lint 0 errors, build success, 70 tests; backend ruff clean, 222 tests.
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { Applications } from "../Applications";
|
|
|
|
// Applications still embeds the MUI Media child (migrated in slice 7). Mock it
|
|
// so this slice-4 test stays focused on the migrated Applications shell and
|
|
// does not pull the still-MUI DataGrid into the jsdom render.
|
|
vi.mock("../Media", () => ({
|
|
Media: () => <div data-testid="media-child">Media</div>,
|
|
}));
|
|
|
|
vi.mock("react-router-dom", () => ({
|
|
useSearchParams: () => [new URLSearchParams(), vi.fn()],
|
|
}));
|
|
|
|
vi.mock("../../hooks/useSettings", () => ({
|
|
useMonitoringSettings: () => ({
|
|
data: [
|
|
{
|
|
id: "m1",
|
|
name: "Main",
|
|
enabled: true,
|
|
services: ["jellyfin"],
|
|
},
|
|
],
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../../hooks/useServices", () => ({
|
|
useServiceInstances: () => ({
|
|
data: [{ id: "jfs1", service_type: "jellyfin", name: "Main", enabled: true }],
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../../hooks/useDashboard", () => ({
|
|
useCounts: () => ({
|
|
data: { movies: 10, series: 5, episodes: 100 },
|
|
}),
|
|
useLibraries: () => ({
|
|
data: [
|
|
{ library: "Movies", total: 10, movies: 10, series: 0 },
|
|
{ library: "Shows", total: 5, movies: 0, series: 5 },
|
|
],
|
|
}),
|
|
}));
|
|
|
|
describe("Applications", () => {
|
|
it("renders the Jellyfin library counts grid and tabs, and keeps the Media child", () => {
|
|
render(<Applications />);
|
|
|
|
// Library stats header.
|
|
expect(screen.getByText("Library stats")).toBeInTheDocument();
|
|
|
|
// Counts: Total = 10 + 5 + 100 = 115, plus the per-type counts.
|
|
expect(screen.getByText("115")).toBeInTheDocument();
|
|
expect(screen.getByText("Episodes")).toBeInTheDocument();
|
|
|
|
// Library rows render their per-library totals (unique strings).
|
|
expect(
|
|
screen.getByText(/Total 10 · Movies 10 · Series 0/),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/Total 5 · Movies 0 · Series 5/),
|
|
).toBeInTheDocument();
|
|
|
|
// Tabs present.
|
|
expect(screen.getByRole("tab", { name: "Jellyfin" })).toBeInTheDocument();
|
|
expect(screen.getByRole("tab", { name: "Nextcloud" })).toBeInTheDocument();
|
|
|
|
// The still-MUI Media child is rendered unchanged inside the Jellyfin tab.
|
|
expect(screen.getByTestId("media-child")).toBeInTheDocument();
|
|
});
|
|
});
|