Files
RuneStone/tests/smoke/features/pmViews.smoke.mjs
T
2026-11-16 04:21:21 -07:00

93 lines
6.1 KiB
JavaScript

// Project Management views: All tasks with merged list columns and board dividers (UI-034, UI-035), then Gantt,
// Calendar (month, week, and day), and Kanban, in both themes. Each view keeps its own view state.
// Ports all-tasks.spec.ts, board-scope-alignment.spec.ts, board-view-state.spec.ts, and the Gantt and Calendar parts of
// workflow.spec.ts of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { card, column, loadWorkspace, openBoard, pane, pmFiles, roadmap, setTheme } from "../_harness/pmFixture.mjs";
await runSmoke("features/pmViews", async ({ page }) => {
const output = await outputDir("features/pmViews");
// One more card on the Review list of Roadmap, so that the merged review column has two boards.
await loadWorkspace(page, Object.fromEntries([...Object.entries(pmFiles()), card("card-f", "Review card", { placements: { [roadmap]: "review" }, order: "f" })]));
await openBoard(page);
const view = name => pane(page).getByRole("navigation", { name: "Project Management views", exact: true }).getByRole("button", { name, exact: true });
const shots = async name => {
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `${name}-${theme}.png`) });
}
};
// UI-034: equal list names share one column. Case and outer spaces do not matter ("Review" and "review").
await pane(page).locator(".pm-card").first().waitFor();
assert.equal(await view("Kanban").getAttribute("aria-pressed"), "true");
const labels = await pane(page).locator("section.pm-column").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label")));
assert.deepEqual(labels.map(label => label.toLowerCase()), ["to do", "in progress", "done", "review"]);
// UI-035: each column groups its cards under board names. A shared card shows once, under the names of its boards.
const todo = column(page, "To do");
const headings = locator => locator.locator(".pm-board-group-heading").allInnerTexts();
assert.deepEqual(await headings(todo), ["Bugs · Roadmap", "Roadmap", "No active board"]);
assert.equal(await todo.locator(".pm-card-title", { hasText: /^Shared card$/ }).count(), 1, "A shared card shows once");
assert.deepEqual(await todo.getByRole("region", { name: "Roadmap", exact: true }).locator(".pm-card-title").allInnerTexts(), ["Card A", "Card B"]);
assert.deepEqual(await todo.getByRole("region", { name: "No active board", exact: true }).locator(".pm-card-title").allInnerTexts(), ["Loose card"]);
const review = pane(page).locator('section.pm-column[data-list-id="list:review"]');
assert.deepEqual(await headings(review), ["Bugs", "Roadmap"]);
// A merged column has no board limit. The board keeps its limit (checked below).
assert.equal(await review.locator(".pm-list-limit").count(), 0);
assert.equal(await review.locator(".pm-count").innerText(), "2");
assert.equal(await pane(page).locator(".pm-board-group-heading").evaluateAll(nodes => nodes.every(node => getComputedStyle(node).opacity === "1")), true, "Board names are opaque");
await shots("all-tasks");
// Gantt: a row for each card, a bar for the planned dates, and a deadline marker.
await view("Gantt").click();
assert.equal(await view("Gantt").getAttribute("aria-pressed"), "true");
const timeline = pane(page).getByRole("table", { name: "Task timeline", exact: true });
await timeline.waitFor();
assert.equal(await timeline.locator(".pm-gantt-row").count(), 7, "A heading row and six cards");
const bar = timeline.locator(".pm-gantt-bar", { hasText: "Card B" });
assert.match(await bar.getAttribute("title"), /^Card B: .+ to .+$/);
assert.equal(await timeline.locator(".pm-deadline").count(), 1);
assert.match(await timeline.locator(".pm-deadline").getAttribute("aria-label"), /^Card B, deadline /);
assert.equal(await timeline.getByRole("button", { name: /^Card A/ }).locator("small").innerText(), "Unscheduled");
await pane(page).getByRole("button", { name: "Next", exact: true }).click();
await pane(page).getByRole("button", { name: "Today", exact: true }).click();
await timeline.locator(".pm-gantt-bar").waitFor();
await shots("gantt");
// Calendar: the month shows the deadline. Week and Day show the hours.
await view("Calendar").click();
const period = name => pane(page).locator(".pm-date-nav").getByRole("button", { name, exact: true });
assert.equal(await period("Month").getAttribute("aria-pressed"), "true");
await pane(page).locator(".pm-month").waitFor();
assert.equal(await pane(page).locator(".pm-day-heading").count(), 7);
assert.equal(await pane(page).locator(".pm-month-day").count(), 42);
await pane(page).getByRole("button", { name: "◆ Due: Card B", exact: true }).waitFor();
await shots("calendar-month");
await period("Week").click();
assert.equal(await pane(page).locator(".pm-hour-day").count(), 7);
assert.equal(await period("Week").getAttribute("aria-pressed"), "true");
await shots("calendar-week");
await period("Day").click();
assert.equal(await pane(page).locator(".pm-hour-day").count(), 1);
assert.equal(await pane(page).locator(".pm-hour-day .pm-hour-slot").count(), 24);
await page.waitForFunction(() => {
const state = JSON.parse(localStorage.getItem("runestone.pm.viewStates") ?? "{}").planning;
return state?.view === "calendar" && state?.period === "day";
});
// Kanban again. A board in the same tab has its own view state and shows its limit.
await view("Kanban").click();
await pane(page).locator(".pm-board").waitFor();
await openBoard(page, "Roadmap");
assert.equal(await view("Kanban").getAttribute("aria-pressed"), "true", "A board starts in Kanban");
assert.equal(await column(page, "Review").locator(".pm-count").innerText(), "1/2");
assert.equal(await column(page, "Review").locator(".pm-list-limit").count(), 1);
await view("Calendar").click();
await pane(page).locator(".pm-month").waitFor();
await shots("board-calendar");
console.log("PASS: All tasks columns and dividers, Gantt, Calendar, and Kanban");
}, { timeout: 15000 });