// @vitest-environment jsdom // // The failure window offers a Retry only where a retry can help: a transient failure, or a site the // downloader did not understand (an update on the server cures it). Never for an unclassified one. import { afterEach, describe, expect, it, vi } from "vitest"; import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import type { DownloadJob } from "../lib/api"; import { ErrorModal } from "./downloadModals"; vi.mock("react-i18next", async (importOriginal) => ({ ...(await importOriginal()), useTranslation: () => ({ i18n: { language: "en" }, t: (key: string | string[]) => (Array.isArray(key) ? key[0] : key), }), })); afterEach(cleanup); function open(error_code: string) { const onRetry = vi.fn(); const job = { id: 1, status: "error", error: "ERROR: x", error_code } as unknown as DownloadJob; render( {}} />); return onRetry; } describe("ErrorModal", () => { it("offers a retry when the site changed under the downloader", () => { const onRetry = open("site_changed"); expect(screen.getByText("downloads.errors.fail.cat.site_changed.short")).toBeTruthy(); fireEvent.click(screen.getByRole("button", { name: "downloads.actions.retry" })); expect(onRetry).toHaveBeenCalledOnce(); }); it("offers none for an unclassified failure", () => { open("unknown"); expect(screen.queryByRole("button", { name: "downloads.actions.retry" })).toBeNull(); }); });