// Project Management drag and drop: a card to another list, a card to a new place in its list, and a list to a new // place on the board. Each drop saves the files. All tasks has no drag and drop (UI-033). // Ports card-placement.spec.ts, card-transfer.spec.ts (drag part), lists.spec.ts, and kanban-cards.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 { cardPath, column, fileText, loadWorkspace, openBoard, pane, roadmap, savedBoards, setTheme, waitForFile } from "../_harness/pmFixture.mjs"; const titles = locator => locator.locator(".pm-card-title").allInnerTexts(); const columnIds = page => pane(page).locator("section.pm-column").evaluateAll(nodes => nodes.map(node => node.dataset.listId)); await runSmoke("features/pmDrag", async ({ page }) => { const output = await outputDir("features/pmDrag"); await loadWorkspace(page); await openBoard(page, "Roadmap"); /** Drag `source` to a point of `target` with the mouse, and take a screenshot before the drop. */ async function drag(source, target, { x = 0.5, y = 0.5, shot }) { const from = await source.boundingBox(), to = await target.boundingBox(); await page.mouse.move(from.x + from.width / 2, from.y + Math.min(12, from.height / 2)); await page.mouse.down(); await page.mouse.move(from.x + from.width / 2 + 20, from.y + 20, { steps: 4 }); await page.mouse.move(to.x + to.width * x, to.y + to.height * y, { steps: 8 }); if (shot) { await pane(page).locator(".pm-drag-preview").waitFor(); await page.screenshot({ path: path.join(output, shot) }); } await page.mouse.up(); } // A card goes to another list. The list status applies, and only that card file changes. await setTheme(page, "dark"); const cardC = await fileText(page, cardPath("card-c")); await drag(pane(page).locator('.pm-card[data-task-id="card-a"]'), column(page, "In progress"), { y: 0.3, shot: "card-drag-dark.png" }); await waitForFile(page, cardPath("card-a"), /listId: doing/); assert.match(await fileText(page, cardPath("card-a")), /status: doing/); assert.deepEqual(await titles(column(page, "In progress")), ["Card A"]); assert.deepEqual(await titles(column(page, "To do")), ["Card B", "Shared card"]); assert.equal(await fileText(page, cardPath("card-c")), cardC, "Other cards stay unchanged"); assert.equal(await pane(page).locator(".pm-drag-preview, .pm-drop-target").count(), 0, "The drop removes the drag preview"); // A card goes above another card of the same list. await drag(pane(page).locator('.pm-card[data-task-id="card-d"]'), pane(page).locator('.pm-card[data-task-id="card-b"]'), { y: 0.2 }); await page.waitForFunction(() => [...document.querySelectorAll('.plugin-editor-pane .pm-column[aria-label="To do"] .pm-card-title')].map(node => node.textContent).join() === "Shared card,Card B"); const order = async id => /\n {6}order: "([^"]+)"/.exec(await fileText(page, cardPath(id)))[1]; assert(await order("card-d") < await order("card-b"), "The saved order puts Shared card first"); // A list goes to a new place: the grip of Done goes to the left half of To do. await setTheme(page, "light"); const grip = column(page, "Done").getByRole("button", { name: "Move list Done", exact: true }); await drag(grip, column(page, "To do"), { x: 0.2, y: 0.2, shot: "list-drag-light.png" }); await page.waitForFunction(() => [...document.querySelectorAll(".plugin-editor-pane .pm-column")].map(node => node.dataset.listId).join() === "done,todo,doing,review"); assert.deepEqual((await savedBoards(page)).find(item => item.value.id === roadmap).value.lists.map(list => list.id), ["done", "todo", "doing", "review"]); assert.deepEqual(await columnIds(page), ["done", "todo", "doing", "review"]); await page.screenshot({ path: path.join(output, "after-drops-light.png") }); // UI-033: All tasks has no drag and drop. Its cards and lists cannot move. await pane(page).locator(".pm-scope").click(); await page.getByRole("menuitemradio", { name: "All tasks", exact: true }).click(); await pane(page).locator(".pm-scope-label", { hasText: /^All tasks$/ }).waitFor(); await pane(page).locator(".pm-card").first().waitFor(); assert.deepEqual([...new Set(await pane(page).locator(".pm-card").evaluateAll(nodes => nodes.map(node => node.draggable)))], [false]); assert.equal(await pane(page).locator(".pm-list-grip").count(), 0); const before = await fileText(page, cardPath("card-b")); await drag(pane(page).locator('.pm-card[data-task-id="card-b"]'), column(page, "Done"), {}); await page.waitForTimeout(300); assert.equal(await fileText(page, cardPath("card-b")), before, "A drag in All tasks changes nothing"); console.log("PASS: card and list drag and drop, and no drag in All tasks"); }, { timeout: 15000 });