mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 08:03:13 +00:00
feat(uplifts): refresh work-order views after decisions (SH-214)
This commit is contained in:
parent
111b813e9e
commit
0d95a32071
2 changed files with 51 additions and 0 deletions
|
|
@ -26,6 +26,9 @@ function invalidateUpliftQueries(
|
|||
dispatchId?: string | number,
|
||||
) {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.uplifts.all });
|
||||
// Queue decisions update the same uplift records rendered by Work Order views.
|
||||
// Invalidate that shared cache even when the queue has no dispatch context.
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.workOrders.all });
|
||||
if (dispatchId !== undefined && dispatchId !== "") {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.uplifts.forDispatch(dispatchId) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.workOrders.dispatch(dispatchId) });
|
||||
|
|
|
|||
48
src/test/domain/uplifts/use-uplift-actions.test.tsx
Normal file
48
src/test/domain/uplifts/use-uplift-actions.test.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import type { ReactNode } from "react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const approve = vi.fn();
|
||||
|
||||
vi.mock("@/domain/uplifts/api/uplifts-api", () => ({
|
||||
upliftsApi: {
|
||||
approve: (...args: unknown[]) => approve(...args),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("react-toastify", () => ({
|
||||
toast: { error: vi.fn(), success: vi.fn(), warning: vi.fn() },
|
||||
}));
|
||||
|
||||
import { useApproveUplift } from "@/domain/uplifts/use-cases/use-uplift-actions";
|
||||
import { queryKeys } from "@/infra/query-key/query-key";
|
||||
|
||||
function makeWrapper(client: QueryClient) {
|
||||
return function Wrapper({ children }: { children: ReactNode }) {
|
||||
return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
|
||||
};
|
||||
}
|
||||
|
||||
describe("useApproveUplift", () => {
|
||||
it("refreshes work-order views after a queue decision", async () => {
|
||||
approve.mockResolvedValueOnce(undefined);
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
});
|
||||
const invalidateSpy = vi.spyOn(client, "invalidateQueries");
|
||||
const { result } = renderHook(() => useApproveUplift(), {
|
||||
wrapper: makeWrapper(client),
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.mutate({ id: 17 });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||
|
||||
expect(approve).toHaveBeenCalledWith(17, undefined);
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: queryKeys.uplifts.all });
|
||||
expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: queryKeys.workOrders.all });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue