// Project Management board state: list capacity and its warning (UI-033), compact list collapse (UI-036), the separate // collapse state of All tasks, new cards from the list composer, a page reload that keeps the state, the fixed default // board of the workspace (UI-038), and the first board of a workspace without boards. // Ports list-limits.spec.ts, list-collapse-create.spec.ts, kanban-cards.spec.ts, board-view-state.spec.ts, // october-cards.spec.ts (default board and onboarding), and host-board-state.smoke.mjs of RuneStone_Project_Management. import assert from "node:assert/strict"; import path from "node:path"; import { openPage, outputDir, runSmoke } from "../_harness/index.mjs"; import { bugs, catalogPath, column, fileText, loadWorkspace, openBoard, pane, pmFiles, ribbon, roadmap, savedBoards, setTheme, waitForFile } from "../_harness/pmFixture.mjs"; const listOf = async (page, id, listId) => (await savedBoards(page)).find(item => item.value.id === id).value.lists.find(list => list.id === listId); const width = async locator => (await locator.boundingBox()).width; await runSmoke("features/pmBoard", async ({ browser, page }) => { const output = await outputDir("features/pmBoard"); await loadWorkspace(page); const catalog = await fileText(page, catalogPath); // All tasks keeps its collapsed lists in the view state of the tab. The board files stay unchanged. await openBoard(page); const allTodo = column(page, "To do"); await allTodo.getByRole("button", { name: "Collapse To do", exact: true }).click(); await allTodo.getByRole("button", { name: "Expand To do", exact: true }).waitFor(); assert.equal(await focusedLabel(page), "Expand To do", "Focus stays on the collapse control"); assert(await width(allTodo) < 60, "A collapsed list is a narrow strip"); assert.equal(await allTodo.locator(".pm-card").count(), 0, "A collapsed list hides its cards"); assert.equal(await allTodo.locator(".pm-count").innerText(), "4", "The strip keeps the card count"); await page.waitForFunction(() => JSON.parse(localStorage.getItem("runestone.pm.viewStates") ?? "{}").planning?.collapsedLists?.includes("list:to do")); assert.equal(await fileText(page, catalogPath), catalog, "A collapse in All tasks does not write the boards"); // UI-033: All tasks has no list actions and no capacity of a merged list. assert.equal(await pane(page).locator(".pm-list-actions, .pm-list-limit").count(), 0, "All tasks has no list actions and no list limits"); // A board list starts expanded: the board has its own collapse state. await openBoard(page, "Roadmap"); const todo = column(page, "To do"); assert.equal(await todo.locator(".pm-card").count(), 3); // UI-033: a limit below the maximum shows the plain indicator. const review = column(page, "Review"); assert.equal(await review.locator(".pm-count").innerText(), "0/2"); assert.equal(await review.locator(".pm-list-limit").count(), 1); assert.equal(await review.locator(".pm-list-limit-reached").count(), 0); // Set a limit through the list menu. At the maximum, the list shows the warning. await todo.getByRole("button", { name: "List actions for To do", exact: true }).click(); await page.getByRole("menu", { name: "List actions", exact: true }).getByRole("menuitem", { name: "Set list limit", exact: true }).click(); const limitForm = page.getByRole("dialog", { name: "Set list limit", exact: true }); await limitForm.getByLabel("Maximum cards", { exact: true }).fill("3"); await limitForm.getByRole("button", { name: "Save limit", exact: true }).click(); await limitForm.waitFor({ state: "detached" }); await waitForFile(page, catalogPath, /"maxCards": 3/); assert.equal(await todo.locator(".pm-count").innerText(), "3/3"); const warning = todo.locator(".pm-list-limit-reached"); assert.match(await warning.getAttribute("aria-label"), /^Active cards in To do: 3\. The maximum is 3\. The list is at the limit\.$/); // The limit warns but does not block: the composer adds a fourth card. await todo.getByRole("button", { name: "Add a card", exact: true }).click(); const composer = todo.getByRole("textbox", { name: "Card title", exact: true }); await composer.fill("Composer card"); await composer.press("Enter"); await todo.getByRole("button", { name: "Composer card", exact: true }).waitFor(); await page.waitForFunction(() => [...window.__TEST__.files.values()].some(text => /title: Composer card/.test(text))); await page.waitForFunction(() => document.querySelector('.plugin-editor-pane .pm-column[aria-label="To do"] .pm-count')?.textContent === "4/3"); assert.match(await warning.getAttribute("aria-label"), /The list is over the limit\.$/); for (const theme of ["dark", "light"]) { await setTheme(page, theme); await warning.focus(); await page.getByRole("tooltip").filter({ hasText: /over the limit/ }).waitFor(); await page.screenshot({ path: path.join(output, `limit-warning-${theme}.png`) }); } // UI-036: a keyboard collapse saves the board file, keeps the count, and keeps focus on the control. await todo.getByRole("button", { name: "Collapse To do", exact: true }).focus(); await page.keyboard.press("Enter"); await todo.getByRole("button", { name: "Expand To do", exact: true }).waitFor(); assert.equal(await focusedLabel(page), "Expand To do"); await waitForList(page, roadmap, "todo", list => list.collapsed === true); assert(await width(todo) < 60); assert.equal(await todo.locator(".pm-count").innerText(), "4/3", "The strip keeps the count and the limit"); assert.equal(await todo.locator(".pm-list-limit-reached").count(), 1, "The strip keeps the warning"); await column(page, "Done").getByRole("button", { name: "Collapse Done", exact: true }).click(); await waitForList(page, roadmap, "done", list => list.collapsed === true); for (const theme of ["dark", "light"]) { await setTheme(page, theme); await page.screenshot({ path: path.join(output, `collapsed-board-${theme}.png`) }); } // A reload keeps the board state, the limits, and the collapsed lists of All tasks. await page.reload(); await page.locator('[data-tree-rel="note.md"]').waitFor(); await openBoard(page, "Roadmap"); await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).waitFor(); assert.equal(await column(page, "To do").locator(".pm-count").innerText(), "4/3"); await column(page, "Done").getByRole("button", { name: "Expand Done", exact: true }).waitFor(); assert.equal(await column(page, "In progress").getByRole("button", { name: "Collapse In progress", exact: true }).count(), 1); await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).click(); await waitForList(page, roadmap, "todo", list => list.collapsed === false); await column(page, "To do").getByRole("button", { name: "Composer card", exact: true }).waitFor(); // The limit indicator opens the limit form. An empty field removes the limit. await column(page, "To do").locator(".pm-list-limit").click(); await limitForm.getByLabel("Maximum cards", { exact: true }).fill(""); await limitForm.getByRole("button", { name: "Save limit", exact: true }).click(); await waitForList(page, roadmap, "todo", list => list.maxCards === undefined); assert.equal(await column(page, "To do").locator(".pm-list-limit").count(), 0); assert.equal(await column(page, "To do").locator(".pm-count").innerText(), "4"); await pane(page).locator(".pm-scope").click(); await page.getByRole("menuitemradio", { name: "All tasks", exact: true }).click(); await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).waitFor(); // UI-038: the settings save a default board. The ribbon button then opens it. await pane(page).getByRole("button", { name: "More actions", exact: true }).click(); await page.getByRole("menuitem", { name: "Project Management settings", exact: true }).click(); const settings = page.getByRole("dialog", { name: "Project Management settings", exact: true }); const defaultBoard = settings.getByRole("button", { name: "Default board", exact: true }); await page.waitForFunction(() => document.querySelector('.pm-settings-popup [aria-label="Default board"]')?.disabled === false); assert.equal(await defaultBoard.innerText(), "All tasks"); await defaultBoard.click(); await page.getByRole("menuitemradio", { name: "Bugs", exact: true }).click(); await waitForFile(page, catalogPath, new RegExp(`"defaultBoardId": "${bugs}"`)); await page.keyboard.press("Escape"); await settings.waitFor({ state: "detached" }); await ribbon(page).click(); await page.getByRole("tab", { name: "Bugs", exact: true, selected: true }).waitFor(); await pane(page).locator(".pm-card", { hasText: "Card C" }).waitFor(); // An unavailable default opens All tasks. await page.evaluate(rel => { const value = JSON.parse(window.__TEST__.files.get(rel)); window.__TEST__.files.set(rel, JSON.stringify({ ...value, defaultBoardId: "missing-board", defaultBoardPath: "pm-board:missing-board" })); }, catalogPath); await ribbon(page).click(); await page.getByRole("tab", { name: "Project Management", exact: true, selected: true }).waitFor(); await pane(page).locator(".pm-scope-label", { hasText: /^All tasks$/ }).waitFor(); console.log("PASS: list limits, collapse, reload, and the default board"); // UI-038: a workspace without boards shows a visible action that creates the first board. const context = await browser.newContext({ viewport: { width: 1280, height: 860 } }); const empty = await openPage(context); await loadWorkspace(empty, pmFiles({ boards: false })); await openBoard(empty); const welcome = empty.getByRole("region", { name: "Create your first board", exact: true }); await welcome.waitFor(); await welcome.getByRole("button", { name: "Create your first board", exact: true }).click(); await empty.getByRole("textbox", { name: "Board name", exact: true }).fill("First board"); await empty.getByRole("dialog", { name: "Create board", exact: true }).getByRole("button", { name: "Create board", exact: true }).click(); await empty.getByRole("tab", { name: "First board", exact: true, selected: true }).waitFor(); await waitForFile(empty, catalogPath, /"name": "First board"/); await empty.screenshot({ path: path.join(output, "first-board-light.png") }); assert.deepEqual(empty.errors, [], "No page errors in the workspace without boards"); await context.close(); }, { timeout: 15000 }); function focusedLabel(page) { return page.evaluate(() => document.activeElement?.getAttribute("aria-label")); } /** Wait until a list of a saved board matches `test`. */ async function waitForList(page, boardId, listId, test) { for (let attempt = 0; attempt < 50; attempt++) { if (test(await listOf(page, boardId, listId))) return; await page.waitForTimeout(100); } throw new Error(`The list ${listId} of ${boardId} did not change`); }