shoc-frontend-new/src/test/app/v/signoff-section.test.tsx
2026-08-10 18:25:57 -03:00

46 lines
1.6 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SignoffSection } from "@/app/v/[token]/dispatch/_components/signoff-section";
function renderSection(overrides: Partial<React.ComponentProps<typeof SignoffSection>> = {}) {
return render(
<SignoffSection
token="portal-token"
dispatchId={9}
existing={[]}
signoffType="customer"
nameLabel="Customer name"
onAdded={vi.fn()}
{...overrides}
/>,
);
}
describe("SignoffSection", () => {
it("shows status-neutral locked copy when submission is locked", () => {
renderSection({ submissionLocked: true });
expect(screen.getByText(/Signoff is unavailable for this dispatch/i)).toBeInTheDocument();
expect(screen.queryByText(/refused/i)).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Submit Signoff" })).not.toBeInTheDocument();
});
it("shows the submission form when unlocked", () => {
renderSection();
expect(screen.getByRole("button", { name: "Submit Signoff" })).toBeInTheDocument();
});
it("shows an existing signoff even while locked", () => {
renderSection({
signoffType: "vendor",
nameLabel: "Your name",
submissionLocked: true,
existing: [{ signoffType: "vendor", name: "Grace Hopper", signatureMethod: "typed" }],
});
expect(screen.getByText("Grace Hopper")).toBeInTheDocument();
expect(screen.queryByText(/Signoff is unavailable/i)).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Submit Signoff" })).not.toBeInTheDocument();
});
});