import { fireEvent, screen, waitFor } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { UpliftRequestsSection } from "@/app/v/[token]/dispatch/_components/uplift-requests-section"; import { renderWithProviders } from "@/test/test-utils"; afterEach(() => { vi.restoreAllMocks(); }); describe("UpliftRequestsSection create workflow", () => { it("renders the server denial message when requestUplifts is denied", async () => { const denialMessage = "Your role can't request uplifts on this work order."; const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue( new Response(JSON.stringify({ message: denialMessage }), { status: 403, headers: { "Content-Type": "application/json" }, }), ); renderWithProviders( undefined)} />, { withAuth: false }, ); fireEvent.change(screen.getByLabelText("New total NTE"), { target: { value: "100" } }); fireEvent.click(screen.getByRole("button", { name: "Request uplift" })); await waitFor(() => expect(screen.getByRole("alert")).toHaveTextContent(denialMessage)); expect(fetchMock).toHaveBeenCalledWith( expect.stringMatching(/\/api\/vendor-portal\/dispatches\/7\/uplift-request$/), expect.objectContaining({ method: "POST" }), ); }); });