shoc-frontend-new/src/test/app/(protected)/workorders/slide-over-completion-service-gate.test.tsx

47 lines
1.7 KiB
TypeScript
Raw Normal View History

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);
});
});