shoc-frontend-new/src/test/app/(protected)/workorders/slide-over-completion-service-gate.test.tsx
Codex Review Integration 9225f2345c fix(work-orders): gate completion document button on service selection (SH-369)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 15:23:17 -03:00

46 lines
1.7 KiB
TypeScript

import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SlideOverCompletionTab } from "@/app/(protected)/workorders/_components/detail/tabs/slide-over-completion-tab";
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
function renderTab(pm: string, onOpenCompletionDoc = vi.fn()) {
const row = { id: "1", type: "PM", pm, docStatus: "No", rowVersion: "1" } as WorkOrderTableRow;
render(
<SlideOverCompletionTab
row={row}
isReadOnly={false}
media={[]}
onOpenCompletionDoc={onOpenCompletionDoc}
/>,
);
return onOpenCompletionDoc;
}
describe("SlideOverCompletionTab service gate", () => {
it("disables the completion document button until a service is selected", () => {
const onOpen = renderTab(" ");
const button = screen.getByRole("button", { name: /select service/i });
expect(button).toBeDisabled();
expect(
screen.getByText("Select a service before opening the completion document."),
).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: /open completion document/i }),
).not.toBeInTheDocument();
fireEvent.click(button);
expect(onOpen).not.toHaveBeenCalled();
});
it("opens the completion document when a service is selected", () => {
const onOpen = renderTab("HVAC Inspection");
const button = screen.getByRole("button", { name: /open completion document/i });
expect(button).toBeEnabled();
expect(screen.queryByText(/select service/i)).not.toBeInTheDocument();
fireEvent.click(button);
expect(onOpen).toHaveBeenCalledTimes(1);
});
});