Files
siftlode/frontend/src/components/downloadModals.error.dom.test.tsx
T
peter 132fb56428 fix(downloads): a site the downloader no longer understands says so, and offers a retry
yt-dlp asks for a bug report on an extraction failure it did not expect: the site answered in a way its extractor does not read (measured on a TikTok link: fails on every attempt under yt-dlp 2026.07.04, downloads under 2026.08.19). That failure read as "Something went wrong" with no retry; it is now its own category, site_changed, with a Retry in the failure window. A contract test holds every failure category to its copy in both languages.
2026-10-12 20:54:47 +02:00

40 lines
1.5 KiB
TypeScript

// @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<typeof import("react-i18next")>()),
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(<ErrorModal job={job} onRetry={onRetry} onClose={() => {}} />);
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();
});
});