mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 13:42:09 +00:00
46 lines
1.7 KiB
TypeScript
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);
|
|
});
|
|
});
|