mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 10:23:11 +00:00
- Gate the Revoke action on the approved queue row and the detail modal to admin users; non-admins get a disabled button with a plain 'Only admins can revoke uplifts' tooltip and the dialog cannot open. - Stop nesting an h2 inside DialogTitle in the uplift detail modal (hydration error) by rendering the title text as a non-heading. - Handle work-order detail/uplift query 403s quietly in the detail modal: sections fall back to 'Unavailable' and the queries suppress the global error toast (QueryCache now honors suppressErrorToast). - Extract UpliftDecisionDialogs and openUpliftEvidence from the page to meet the changed-file maintainability gate (complexity 23 -> pass).
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { createAppQueryClient } from "@/lib/query/query-client";
|
|
|
|
const toastMocks = vi.hoisted(() => ({ error: vi.fn() }));
|
|
|
|
vi.mock("react-toastify", () => ({
|
|
toast: { error: toastMocks.error },
|
|
}));
|
|
|
|
describe("createAppQueryClient query cache", () => {
|
|
beforeEach(() => {
|
|
toastMocks.error.mockReset();
|
|
});
|
|
|
|
it("does not toast for queries that suppress the error toast", async () => {
|
|
const queryClient = createAppQueryClient();
|
|
|
|
await expect(
|
|
queryClient.fetchQuery({
|
|
queryKey: ["suppressed-403"],
|
|
queryFn: () =>
|
|
Promise.reject(new Error("You do not have permission to perform this action.")),
|
|
meta: { suppressErrorToast: true },
|
|
}),
|
|
).rejects.toThrow("You do not have permission");
|
|
|
|
expect(toastMocks.error).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("still toasts for queries without suppression", async () => {
|
|
const queryClient = createAppQueryClient();
|
|
|
|
await expect(
|
|
queryClient.fetchQuery({
|
|
queryKey: ["unsuppressed-failure"],
|
|
queryFn: () => Promise.reject(new Error("A server error occurred.")),
|
|
}),
|
|
).rejects.toThrow("A server error occurred.");
|
|
|
|
expect(toastMocks.error).toHaveBeenCalledWith("A server error occurred.");
|
|
});
|
|
});
|