`req` opens its blocking dialog for 400/409/422/5xx only. A 403/404/429 was left to the caller and a 502-504 or lost connection got just the self-clearing connection notice, so 34 mutations without a reporting onError and 15 direct api writes with a bare or missing catch failed in silence: a hidden channel that snapped back, a share link that never revoked, a confirmed account delete that ended with nothing said. - lib/queryClient: one MutationCache reporter. react-query awaits it BEFORE the mutation's own onError, so it waits a task and skips a failure the site already reported; the toast title comes from `meta.failTitle`, `meta.errorShownInline` opts out. - notifyActionError: title names WHAT failed, the line under it says WHY (`failureReason`: a structured localized detail, else the status). It marks the error reported (`markReported`), so nothing reports one failure twice; `notifyKnownFailure` for a site's own specific sentence. - Every silent site named (45 new HU/EN titles, 4 reasons). Stale "the global dialog shows it" comments corrected on the job actions, channel block, Plex sync, cookies, download enqueue, account delete and usePref. - Channels passed the tag hook's channel id to the reporter as the error; the tag and priority hooks now report themselves, with the real error. - A contract test keeps every useMutation naming its failure; CLAUDE.md gains the pattern row. - history.dom.test: the "navigates only once the entries are back" assertion raced an async act's macrotask flush (1 in 5 runs); it now asserts from a later popstate listener.
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// A preference save the server refuses is REPORTED (E11 S2b). The local state and the `me` cache
|
|
// already show the new value, so a swallowed failure was invisible until the next load quietly put
|
|
// the old value back — and the comment above the swallow claimed `req` toasted it, which it does not
|
|
// for a 403/404/429 or a lost connection.
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { createElement, type ReactNode } from "react";
|
|
|
|
const { savePrefs, notifyActionError } = vi.hoisted(() => ({
|
|
savePrefs: vi.fn(),
|
|
notifyActionError: vi.fn(),
|
|
}));
|
|
vi.mock("./api", () => ({ api: { savePrefs, me: vi.fn() } }));
|
|
vi.mock("./actionErrors", () => ({ notifyActionError }));
|
|
|
|
import { usePref, useSavePref } from "./usePref";
|
|
import i18n from "../i18n";
|
|
|
|
afterEach(() => {
|
|
savePrefs.mockReset();
|
|
notifyActionError.mockReset();
|
|
});
|
|
|
|
const wrapper = ({ children }: { children: ReactNode }) =>
|
|
createElement(QueryClientProvider, { client: new QueryClient() }, children);
|
|
|
|
describe("a refused preference save", () => {
|
|
it("is reported from the usePref setter", async () => {
|
|
const refusal = new TypeError("Failed to fetch");
|
|
savePrefs.mockRejectedValue(refusal);
|
|
const { result } = renderHook(() => usePref<boolean>("hintsOn", true), { wrapper });
|
|
act(() => result.current[1](false));
|
|
await waitFor(() =>
|
|
expect(notifyActionError).toHaveBeenCalledWith(refusal, i18n.t("errors.writeFailed.prefs")),
|
|
);
|
|
expect(result.current[0]).toBe(false); // the local value stays; the toast says it did not save
|
|
});
|
|
|
|
it("is reported from the raw useSavePref persister", async () => {
|
|
const refusal = new Error("403");
|
|
savePrefs.mockRejectedValue(refusal);
|
|
const { result } = renderHook(() => useSavePref(), { wrapper });
|
|
act(() => result.current({ stripSources: { c1: false } }));
|
|
await waitFor(() =>
|
|
expect(notifyActionError).toHaveBeenCalledWith(refusal, i18n.t("errors.writeFailed.prefs")),
|
|
);
|
|
});
|
|
});
|