// @vitest-environment jsdom // // E28 review J4: the video menu's download row was labelled with the download's STATE ("Downloaded", // "In queue") — a row that reads as a status yet opens the download dialog. It is "Download…" now, // the state riding along as the row's hint. import type { ReactNode } from "react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { cleanup, renderHook, waitFor } from "@testing-library/react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; vi.mock("react-i18next", async (importOriginal) => ({ ...(await importOriginal()), useTranslation: () => ({ t: (k: string) => k }), })); vi.mock("./navigationContext", () => ({ useNavigationActions: () => ({ openChannel: vi.fn() }) })); vi.mock("./comfortPin", () => ({ pinVideo: vi.fn(), useComfortPin: () => ({ item: () => [] }), })); import { api, type Video } from "../lib/api"; import { useVideoActions } from "./useVideoActions"; afterEach(() => { cleanup(); vi.restoreAllMocks(); }); const video = { id: "v1", title: "A video", status: "new", position_seconds: 0 } as Video; function downloadRow(state: string | undefined) { vi.spyOn(api, "downloadIndex").mockResolvedValue( (state ? { v1: state } : {}) as Awaited>, ); const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }); const wrapper = ({ children }: { children: ReactNode }) => ( {children} ); const { result } = renderHook( () => useVideoActions({ onState: vi.fn(), onToggleSave: vi.fn() }, true), { wrapper }, ); return () => result.current.items(video, null).find((i) => i.id === "download")!; } describe("the video menu's download row", () => { it("says what it does, whatever the state, and carries the state as its hint", async () => { const done = downloadRow("done"); await waitFor(() => expect(done().title).toBe("downloads.button.downloaded")); expect(done().label).toBe("downloads.menu.download"); cleanup(); const none = downloadRow(undefined); await waitFor(() => expect(none().label).toBe("downloads.menu.download")); expect(none().title).toBeUndefined(); }); });