mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 06:53:12 +00:00
fix(uplifts): report a failed approvals queue once, inline, without the global toast
This commit is contained in:
parent
a031239259
commit
090c977659
2 changed files with 43 additions and 0 deletions
|
|
@ -10,5 +10,8 @@ export function useUpliftsQueue(
|
|||
queryKey: queryKeys.uplifts.queue(params as Record<string, unknown>),
|
||||
queryFn: () => upliftsApi.list(params),
|
||||
placeholderData: keepPreviousData,
|
||||
// The Uplift Approvals page reports a failed queue inline, so the global toast
|
||||
// would announce the same failure twice.
|
||||
meta: { suppressErrorToast: true },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
40
src/test/domain/uplifts/use-cases/use-uplifts-queue.test.tsx
Normal file
40
src/test/domain/uplifts/use-cases/use-uplifts-queue.test.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderHook, waitFor } from "@testing-library/react";
|
||||
import type { ReactNode } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { upliftsApi } from "@/domain/uplifts/api/uplifts-api";
|
||||
import { useUpliftsQueue } from "@/domain/uplifts/use-cases/use-uplifts-queue";
|
||||
import { createAppQueryClient } from "@/lib/query/query-client";
|
||||
|
||||
const toastMocks = vi.hoisted(() => ({ error: vi.fn() }));
|
||||
|
||||
vi.mock("react-toastify", () => ({
|
||||
toast: { error: toastMocks.error, success: vi.fn() },
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
toastMocks.error.mockReset();
|
||||
});
|
||||
|
||||
describe("useUpliftsQueue", () => {
|
||||
it("does not show the global error toast, since the approvals page reports the failure inline", async () => {
|
||||
vi.spyOn(upliftsApi, "list").mockRejectedValue(new Error("Failed to load uplift queue"));
|
||||
// The real app query client runs the QueryCache's global onError handler, which
|
||||
// toasts unless the query opts out.
|
||||
const queryClient = createAppQueryClient();
|
||||
queryClient.setDefaultOptions({ queries: { retry: false } });
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useUpliftsQueue({ status: "Rejected", page: 1, pageSize: 25 }),
|
||||
{
|
||||
wrapper: ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
await waitFor(() => expect(result.current.error).toBeInstanceOf(Error));
|
||||
expect(toastMocks.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue