The Project Management screen (/pm, view only) with Overview, Projects & units, Bottlenecks & aging, Hours vs target, Quality & issues and Find jobs, the period picker, health per unit and per project, drill down, Excel (CSV) per table and for all, and the PESCO production status report PDF with the controlled-copy stamp; every export logged as "report exported". The find bar on every home screen: the full search set, the dropdowns, quick flags with Mine, the flag kinds, Board and List with sorts, filters saved per browser; every filter applied by the server on the list and the boards, with facets. Presence in packets with role, lock and revoke drop; the motion switch with reduced motion honoured, card glides, glow and count-up; Back restores the scroll spot; sheet placement and the iPad layout pass. The data book compared page by page with the old build and six layout differences fixed. Tests for the PM aggregates, search, filters, presence and exports; Playwright scenarios for the PM screen, the find bar and presence at desktop and iPad viewports. Docs updated; PLAN.md questions 38 to 42. Co-Authored-By: Claude Fable 5.1 <[email protected]>
184 lines
9.1 KiB
TypeScript
184 lines
9.1 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { actor, api, closeAll, packet, stepApi } from "./shophelpers";
|
|
import {
|
|
L,
|
|
catchOpen,
|
|
downloadText,
|
|
isoDay,
|
|
makeDraft,
|
|
makeProject,
|
|
makeUnit,
|
|
personId,
|
|
pickProject,
|
|
pmDataRows,
|
|
pmTab,
|
|
pmTable,
|
|
pullWithHeat,
|
|
runSuffix,
|
|
unpickProject,
|
|
type Made,
|
|
type Unit,
|
|
} from "./pmhelpers";
|
|
|
|
// Phase 8 Project Management on the CI stack, modelled on the old tests/ps tpm. clerk.clara makes a project with
|
|
// two units (one due yesterday, one in four days) and three packets through the API: K1 put on hold by wh.wade,
|
|
// K2 assigned to weld.andy and started (in progress), K3 Ready to assign. pm.paula signs in and lands on /pm: the
|
|
// KPI tiles and the plain-words summary; the projects tab opens the project to its units and a unit drills to Find
|
|
// jobs; the aging, hours and quality tabs have rows; the scope follows the find bar's project pick; Excel (CSV)
|
|
// — all downloads a CSV whose first line names the report; PDF report answers a PDF; a packet shows View only and
|
|
// no enabled write control; the API refuses her a write. Every UI label used here is in L (pmhelpers.ts).
|
|
|
|
let RUN = "";
|
|
let PROJECT = "";
|
|
let units: Unit[] = [];
|
|
const K: Record<"k1" | "k2" | "k3", Made> = {} as Record<"k1" | "k2" | "k3", Made>;
|
|
|
|
test.describe.serial("project management", () => {
|
|
test.setTimeout(240_000);
|
|
|
|
test("clerk.clara, wh.wade and weld.andy make the PM packets", async ({ browser }, info) => {
|
|
RUN = runSuffix(info.project.name);
|
|
PROJECT = `PM${RUN}`;
|
|
const clara = await actor(browser, "clerk.clara");
|
|
const wade = await actor(browser, "wh.wade");
|
|
const wes = await actor(browser, "sup.wes");
|
|
const andy = await actor(browser, "weld.andy");
|
|
const proj = await makeProject(clara, PROJECT, { name: "PM pump skids", customer: "CI Gas", due: isoDay(20) });
|
|
units = [
|
|
await makeUnit(clara, Number(proj.id), "001", isoDay(-1)),
|
|
await makeUnit(clara, Number(proj.id), "002", isoDay(4)),
|
|
];
|
|
const [u1, u2] = units as [Unit, Unit];
|
|
K.k1 = await makeDraft(clara, u1, `PM held ${RUN}`, { send: "warehouse" });
|
|
await api(wade, "post", `/api/packets/${K.k1.id}/wh`, {
|
|
stage: "hold",
|
|
reason: "Waiting on purchasing / PO",
|
|
note: "PO 4471",
|
|
expect_stage: "incoming",
|
|
});
|
|
K.k2 = await makeDraft(clara, u1, `PM running ${RUN}`, { send: "warehouse" });
|
|
await pullWithHeat(wade, K.k2.id, `HP${RUN}-`);
|
|
const andyId = await personId(wes, "weld.andy");
|
|
const stalls = (await api(wes, "get", "/api/shop/stations")) as unknown as Array<Record<string, unknown>>;
|
|
const stall2 = stalls.find((s) => s.dept_code === "03" && s.name === "Stall 2");
|
|
expect(stall2).toBeTruthy();
|
|
await stepApi(wes, K.k2.id, "assign", { station_id: Number(stall2?.id), welder_id: andyId });
|
|
await stepApi(andy, K.k2.id, "start");
|
|
K.k3 = await makeDraft(clara, u2, `PM ready ${RUN}`, { send: "03" });
|
|
expect((await packet(wes, K.k2.id)).status).toBe("in_progress");
|
|
await closeAll(clara, wade, wes, andy);
|
|
});
|
|
|
|
test("tpm: overview, projects, drill down, tabs, scope, exports, view only", async ({ browser }) => {
|
|
const paula = await actor(browser, "pm.paula");
|
|
const page = paula.page;
|
|
|
|
// 1. lands on the PM screen: KPIs and the summary
|
|
await page.goto("/");
|
|
await expect(page).toHaveURL(new RegExp(`${L.homes.pm}$`));
|
|
await expect(page.getByText(L.pm.eyebrow, { exact: true })).toBeVisible();
|
|
await expect(page.getByRole("heading", { level: 1, name: L.pm.head })).toBeVisible();
|
|
for (const label of L.pm.kpis) {
|
|
await expect(page.getByRole("button", { name: label }).first()).toBeVisible();
|
|
}
|
|
const sum = page.locator(".pmsum").or(page.getByTestId("pm-summary")).first();
|
|
await expect(sum.getByRole("heading", { name: L.pm.plainWords })).toBeVisible();
|
|
await expect(sum.getByRole("listitem").first()).toBeVisible();
|
|
await expect(page.getByRole("heading", { name: L.pm.pipeline, exact: true })).toBeVisible();
|
|
await expect(page.getByRole("img", { name: L.pm.bars })).toBeVisible();
|
|
await expect(page.getByRole("heading", { name: L.pm.attention })).toBeVisible();
|
|
await expect(pmTab(page, L.pm.tabs.overview)).toHaveAttribute("aria-selected", "true");
|
|
await expect(page.getByText(L.pm.scope).first()).toBeVisible();
|
|
|
|
// 2. the projects tab: open the project to its units
|
|
await pmTab(page, L.pm.tabs.projects).click();
|
|
const projects = pmTable(page, L.pm.titles.projects);
|
|
await expect(projects).toBeVisible();
|
|
const projRow = projects.getByRole("row").filter({ hasText: PROJECT }).first();
|
|
await expect(projRow).toBeVisible();
|
|
const unit1 = projects.getByRole("row").filter({ hasText: `${PROJECT}001` });
|
|
if (!(await unit1.count())) await projRow.click();
|
|
await expect(unit1.first()).toBeVisible();
|
|
await expect(projects.getByRole("row").filter({ hasText: `${PROJECT}002` }).first()).toBeVisible();
|
|
await expect(unit1.first()).toContainText(L.pm.health.late);
|
|
|
|
// 3. a unit drills to Find jobs, scoped to that unit
|
|
await unit1.first().click();
|
|
await expect(pmTab(page, L.pm.tabs.find)).toHaveAttribute("aria-selected", "true");
|
|
const list = page.getByRole("table", { name: L.find.listHead, exact: true });
|
|
await expect(list.getByRole("row").filter({ hasText: K.k1.title }).first()).toBeVisible();
|
|
await expect(list.getByRole("row").filter({ hasText: K.k2.title }).first()).toBeVisible();
|
|
await expect(list.getByRole("row").filter({ hasText: K.k3.title })).toHaveCount(0);
|
|
await expect(page.getByTestId("pm-scope").or(page.locator(".pmscope")).first()).toContainText(
|
|
`Unit ${PROJECT}001`,
|
|
);
|
|
|
|
// 4. aging, hours and quality have rows
|
|
await unpickProject(page);
|
|
for (const t of [L.pm.tabs.aging, L.pm.tabs.hours, L.pm.tabs.quality]) {
|
|
await pmTab(page, t).click();
|
|
await expect(pmTab(page, t)).toHaveAttribute("aria-selected", "true");
|
|
await expect(page.locator("section.pmt").first()).toBeVisible();
|
|
await expect.poll(() => pmDataRows(page).count(), { message: t }).toBeGreaterThan(0);
|
|
}
|
|
await expect(pmTable(page, L.pm.titles.qualityHolds).getByRole("row").filter({ hasText: PROJECT })).not.toHaveCount(
|
|
0,
|
|
);
|
|
|
|
// 5. the scope follows the find bar
|
|
await pickProject(page, PROJECT);
|
|
await pmTab(page, L.pm.tabs.overview).click();
|
|
const scope = page.getByTestId("pm-scope").or(page.locator(".pmscope")).first();
|
|
await expect(scope).toContainText(`Project ${PROJECT}`);
|
|
await expect(scope).toContainText("view only");
|
|
await expect(page.getByTestId("pm-kpi-holds").or(page.getByRole("button", { name: /Warehouse holds/ })).first()).toContainText("1");
|
|
|
|
// 6. exports: the CSV of every table downloads; the PDF answers a PDF
|
|
const [dl] = await Promise.all([
|
|
page.waitForEvent("download"),
|
|
page.getByRole("button", { name: L.pm.csvAll, exact: true }).click(),
|
|
]);
|
|
expect(dl.suggestedFilename()).toMatch(/^PacketStation_All_reports_\d{4}-\d{2}-\d{2}\.csv$/);
|
|
const text = await downloadText(dl);
|
|
expect(text.split(/\r\n/)[0]).toMatch(L.pm.csvFirst);
|
|
expect(text).toContain(`Project ${PROJECT}`);
|
|
const url = await catchOpen(page, page.getByRole("button", { name: L.pm.pdf, exact: true }));
|
|
expect(url).toContain("/api/pm/report.pdf");
|
|
const r = await page.request.get(url);
|
|
expect(r.status()).toBe(200);
|
|
expect(r.headers()["content-type"]).toContain("application/pdf");
|
|
expect((await r.body()).subarray(0, 4).toString("latin1")).toBe("%PDF");
|
|
|
|
// 7. read only: View only and no enabled write control; the API refuses a write
|
|
await page.goto(`/packets/${K.k2.id}`);
|
|
await expect(page.getByText(L.pm.viewOnly).first()).toBeVisible();
|
|
const writes = page
|
|
.getByRole("button", {
|
|
name: /^(Pause|Resume|Start work|Submit to supervisor|Send to station|Send to Q\.C\.|Mark a weld|Return to station|Pull back to queue)$/,
|
|
})
|
|
.and(page.locator(":enabled"));
|
|
await expect(writes).toHaveCount(0);
|
|
await expect(page.locator("main input:enabled[type=checkbox]")).toHaveCount(0);
|
|
await stepApi(paula, K.k2.id, "submit", {}, 403);
|
|
await api(paula, "post", `/api/pm/overview`, {}, { status: 405 });
|
|
await closeAll(paula);
|
|
});
|
|
|
|
test("tpm: the period changes the history figures", async ({ browser }) => {
|
|
const paula = await actor(browser, "pm.paula");
|
|
const page = paula.page;
|
|
await page.goto(L.homes.pm);
|
|
const period = page.getByLabel(L.pm.period).or(page.getByTitle("Period for history-based figures")).first();
|
|
await period.selectOption({ label: L.pm.periods["365"] });
|
|
await expect(page.getByRole("button", { name: /^Q\.C\. rejects · last 12 months/ }).first()).toBeVisible();
|
|
expect(await page.evaluate(() => window.localStorage.getItem("ps.pmper"))).toBe("365");
|
|
await page.reload();
|
|
await expect(page.getByRole("button", { name: /^Filed · last 12 months/ }).first()).toBeVisible();
|
|
await period.selectOption({ label: L.pm.periods["90"] });
|
|
await pmTab(page, L.pm.tabs.hours).click();
|
|
await page.reload();
|
|
await expect(pmTab(page, L.pm.tabs.hours)).toHaveAttribute("aria-selected", "true"); // ps.pmtab
|
|
await closeAll(paula);
|
|
});
|
|
});
|