import { describe, it, expect } from "vitest"; import { errorAfterLoad, loadErrorMessage } from "./detailLoadError"; /** * TRACES: UR-062 | DR-297 | UT-267 * * Resuming the app after a few minutes in the background replaced a series page * that was on screen with "Failed to load item". The resume reload is a refresh * of content the cache had already answered, yet any throw in it blanked the * page — and no later successful reload of the same item ever cleared it. */ describe("errorAfterLoad", () => { it("clears the error when a load succeeds", () => { expect(errorAfterLoad({ ok: true }, { refreshing: true })).toBeNull(); expect(errorAfterLoad({ ok: true }, { refreshing: false })).toBeNull(); }); it("keeps a page on screen when a refresh of it fails", () => { expect(errorAfterLoad({ ok: false, error: "boom" }, { refreshing: true })).toBeNull(); }); it("reports a failure to open an item that is not on screen yet", () => { expect(errorAfterLoad({ ok: false, error: new Error("Offline") }, { refreshing: false })).toBe( "Offline", ); }); }); describe("loadErrorMessage", () => { it("shows the text of a backend error, which arrives as a plain string", () => { expect(loadErrorMessage("Repository not found")).toBe("Repository not found"); }); it("shows an Error's message", () => { expect(loadErrorMessage(new TypeError("x is undefined"))).toBe("x is undefined"); }); it("falls back to a generic message for anything else", () => { expect(loadErrorMessage(undefined)).toBe("Failed to load item"); expect(loadErrorMessage({})).toBe("Failed to load item"); expect(loadErrorMessage("")).toBe("Failed to load item"); }); });