Files
PacketStation/frontend/src/screens/qc/ItpPrint.test.tsx
T
spencermandClaude Opus 5.5 70a97398f1
ci / server (pull_request) Successful in 12m48s
ci / frontend (pull_request) Successful in 54s
ci / image (pull_request) Skipped
ci / e2e (pull_request) Successful in 4m38s
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
- C1 (issue 1): over target follows VISUAL ticket hours, not the timer.
- C2 (issue 24): a Q.C. reject always needs a reason; accept needs an NCR number after a reject without one.
- C3 (issue 25): an incomplete unit ITP blocks filing.
- C4 (issue 27): prints open the print dialog on the page, no new tab.
- C5 (issue 31): filing is blocked while VISUAL shows a work order open; the feed sets vclosed on VISUAL packets.
- C6 (issue 8): the data book leaves out the history pages.
- C7 (issue 18): the supervisor approves each received short; accept and filing wait for it.
- C8 (issue 23): per-department checklists, edited by the department supervisor or Admin, frozen at START.
- C9 (issue 32): Q.C. and Clerical may run the stamp check.
- C10 (issue 33): the PM screen and reports are for PS-ProjectMgmt and Admin only.
- C11 (issue 36): the Stall screen lists the packets assigned to the welder, at the supervisor's stall.

Migration 0011. Docs: PLAN (also issue 9 confirmed, issue 4 asked), POLICY, SECURITY, SCHEMA, FEED, README, CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 16:36:49 -06:00

69 lines
2.9 KiB
TypeScript

import { fireEvent, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { printPdf } from "../../lib/printPdf";
import type { Itp } from "../../api/qc";
import { DEPARTMENTS, renderApp } from "../../test/auth";
import { mockFetch } from "../../test/fetchMock";
import { makeItp, makeUnitFolder, QUINN } from "./fixtures";
function base(itp: Itp) {
return {
"/api/auth/me": { body: QUINN },
"/api/departments": { body: DEPARTMENTS },
"/api/units/12/itp": { body: itp },
"/api/qc/folders/units/12": { body: makeUnitFolder() },
};
}
vi.mock("../../lib/printPdf", () => ({ printPdf: vi.fn(() => Promise.resolve()) }));
afterEach(() => {
vi.restoreAllMocks();
vi.mocked(printPdf).mockReset();
vi.mocked(printPdf).mockImplementation(() => Promise.resolve());
});
describe("ItpPage PDF and print", () => {
it("opens the ITP PDF, offers the download, and prints on the page", async () => {
const open = vi.spyOn(window, "open").mockImplementation(() => null);
mockFetch(base(makeItp()));
renderApp("/qc/units/12/itp");
fireEvent.click(await screen.findByRole("button", { name: "ITP (PDF)" }));
expect(open).toHaveBeenLastCalledWith("/api/itps/5/pdf", "_blank", "noopener");
const dl = screen.getByRole("link", { name: "Download" });
expect(dl).toHaveAttribute("href", "/api/itps/5/pdf?download=1");
expect(dl).toHaveAttribute("download");
open.mockClear();
fireEvent.click(screen.getByRole("button", { name: "Print" }));
await waitFor(() => expect(printPdf).toHaveBeenCalledWith("/api/itps/5/print"));
expect(open).not.toHaveBeenCalled();
expect(await screen.findByRole("button", { name: "Print" })).toBeEnabled();
expect(screen.queryByRole("link", { name: "Signed PDF" })).not.toBeInTheDocument();
});
it("says so when the print cannot be prepared", async () => {
vi.mocked(printPdf).mockRejectedValueOnce(new Error("no pdf"));
mockFetch(base(makeItp()));
renderApp("/qc/units/12/itp");
fireEvent.click(await screen.findByRole("button", { name: "Print" }));
expect(await screen.findByRole("alert")).toHaveTextContent("The print could not be prepared.");
});
it("links the signed PDF on a signed-off ITP", async () => {
mockFetch(
base(
makeItp({
status: "complete",
can: { edit: false, sign_off: false, reopen: false },
signoff: { at: "2026-10-17T12:00:00Z", by: { id: "u-quinn", display_name: "Quinn QC" }, asset_id: "a-signed" },
}),
),
);
renderApp("/qc/units/12/itp");
const link = await screen.findByRole("link", { name: "Signed PDF" });
expect(link).toHaveAttribute("href", "/_blob/a-signed");
expect(link).toHaveAttribute("target", "_blank");
expect(screen.getByRole("note")).toHaveTextContent(/a signed PDF copy is filed in this unit's documents\. Signed PDF$/);
});
});