shoc-frontend-new/src/test/app/v/uplift-requests-section.test.tsx
2026-09-22 23:04:13 -03:00

43 lines
1.5 KiB
TypeScript

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(
<UpliftRequestsSection
token="portal-token"
dispatchId={7}
currentNte={100}
upliftRequests={[]}
locked={false}
onChanged={vi.fn()}
pollDocument={vi.fn(async () => 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" }),
);
});
});