Files
PacketStation/tests/e2e/tests/send.spec.ts
T

97 lines
5.2 KiB
TypeScript
Raw Normal View History

import { type Page } from "@playwright/test";
import { expect, test } from "./helpers";
import { cardOf, findBar, makeDraft, makeProject, makeUnit, runSuffix, searchBox, type Made } from "./pmhelpers";
import { actor, closeAll, packet, signWithPassword } from "./shophelpers";
import { onePagePdf } from "./whhelpers";
// Phase 10, the old tsend on the new UI. clerk.clara answers "Heat map required?" and attaches the drawing before a
// draft can go anywhere; she sends one straight to a department (skipping the warehouse) with a note, and one straight
// to Q.C. sup.wes finds the first on the Supervisor screen and sends it back to Clerical with a reason.
let RUN = "";
let one: Made;
let two: Made;
async function attachDrawing(page: Page): Promise<void> {
await page.getByLabel("Attach drawing (PDF)").setInputFiles({ name: "send.pdf", mimeType: "application/pdf", buffer: onePagePdf() });
await signWithPassword(page, "clerk.clara");
await expect(page.getByText(/Drawing attached/)).toBeVisible();
}
test.describe.serial("send a draft", () => {
test("tsend: the heat map answer and the drawing come first; straight to a department, straight to Q.C.", async ({
browser,
}, info) => {
RUN = runSuffix(info.project.name);
const clara = await actor(browser, "clerk.clara");
const project = await makeProject(clara, `T${RUN}`);
const unit = await makeUnit(clara, Number(project.id), "001");
one = await makeDraft(clara, unit, `Send dept ${RUN}`);
two = await makeDraft(clara, unit, `Send qc ${RUN}`);
const page = clara.page;
// Nothing can be sent before the heat map question is answered and a drawing is on
await page.goto(`/packets/${one.id}`);
await expect(page.getByTestId("status-pill")).toHaveText("Ready to release");
for (const name of ["Send to warehouse", "Send to a department", "Send to Q.C."]) {
await expect(page.getByRole("button", { name, exact: true })).toBeDisabled();
}
await expect(page.getByText("Say whether this packet needs a heat map.").first()).toBeVisible();
await attachDrawing(page);
const hm = page.getByRole("group", { name: "Heat map required?" });
await hm.getByRole("button", { name: "No" }).click();
await expect(hm.getByRole("button", { name: "No" })).toHaveAttribute("aria-pressed", "true");
await expect(page.getByText("Not required", { exact: true })).toBeVisible();
// Straight to a department, with a note
const toDept = page.getByRole("button", { name: "Send to a department", exact: true });
await expect(toDept).toBeEnabled();
await toDept.click();
const sheet = page.getByRole("dialog", { name: "Send straight to a department" });
await expect(sheet.getByText("Skips the warehouse parts pull.", { exact: false })).toBeVisible();
await sheet.getByLabel("Department").selectOption("03");
await sheet.getByLabel("Note (optional, they will see it)").fill("Parts already staged at the station");
await sheet.getByRole("button", { name: "Send", exact: true }).click();
await expect(page.getByTestId("status-pill")).toHaveText("Ready to assign");
let p = await packet(clara, one.id);
expect(p.status).toBe("ready");
expect(p.dept.code).toBe("03");
expect(p.heat_map).toBe(false);
// Straight to Q.C.
await page.goto(`/packets/${two.id}`);
await attachDrawing(page);
await page.getByRole("group", { name: "Heat map required?" }).getByRole("button", { name: "Yes" }).click();
await page.getByRole("button", { name: "Send to Q.C.", exact: true }).click();
const qc = page.getByRole("dialog", { name: "Send straight to Q.C." });
await expect(qc.getByText("Skips the warehouse and the shop.", { exact: false })).toBeVisible();
await qc.getByLabel("Note (optional, Q.C. will see it)").fill("Inspect the as-received spool");
await qc.getByRole("button", { name: "Send to Q.C." }).click();
await expect(page.getByTestId("status-pill")).toHaveText("Q.C. inspection");
p = await packet(clara, two.id);
expect(p.status).toBe("qc");
expect(p.heat_map).toBe(true);
await closeAll(clara);
});
test("tsend: the department's supervisor sees it and sends it back to Clerical with a reason", async ({ browser }) => {
const wes = await actor(browser, "sup.wes");
const page = wes.page;
await page.goto("/supervisor");
await expect(findBar(page)).toBeVisible();
await searchBox(page).fill(one.title);
await expect(cardOf(page, one)).toBeVisible();
await page.goto(`/packets/${one.id}`);
await page.getByRole("button", { name: "Send back to Clerical", exact: true }).click();
const sheet = page.getByRole("dialog", { name: "Send back to Clerical" });
await sheet.getByLabel("Reason").fill("short");
await sheet.getByRole("button", { name: "Send back to Clerical" }).click();
await expect(sheet.getByRole("alert")).toHaveText("Give a reason of at least 8 characters.");
await sheet.getByLabel("Reason").fill("Wrong department, this is code work");
await sheet.getByRole("button", { name: "Send back to Clerical" }).click();
await expect(page.getByTestId("status-pill")).toHaveText("Ready to release");
expect((await packet(wes, one.id)).status).toBe("draft");
await closeAll(wes);
});
});