|
| 1 | +import { test, expect, type Page } from "@playwright/test" |
| 2 | +import { openFixtureInLocalEditor, waitForCanvasReady } from "../helpers/canvas" |
| 3 | + |
| 4 | +/** |
| 5 | + * A selected node shows an edit/delete toolbar floating at its top-right. The |
| 6 | + * toolbar's box is larger than its two icons, so its empty margins (and the gap |
| 7 | + * between the icons) must NOT swallow clicks meant for a node sitting beneath |
| 8 | + * it — otherwise that node becomes unclickable. Only the icons themselves |
| 9 | + * should capture the pointer. |
| 10 | + */ |
| 11 | + |
| 12 | +// Two class nodes: "Beta" covers "Alpha"'s top-right corner, exactly where |
| 13 | +// Alpha's toolbar appears once Alpha is selected. |
| 14 | +const OVERLAP_MODEL = { |
| 15 | + id: "e2e-toolbar-blocking", |
| 16 | + type: "ClassDiagram", |
| 17 | + version: "4.0.0", |
| 18 | + title: "toolbar blocking", |
| 19 | + assessments: {}, |
| 20 | + edges: [], |
| 21 | + nodes: [ |
| 22 | + { |
| 23 | + id: "alpha-0000-0000-0000-000000000001", |
| 24 | + type: "class", |
| 25 | + width: 200, |
| 26 | + height: 100, |
| 27 | + position: { x: 200, y: 400 }, |
| 28 | + measured: { width: 200, height: 100 }, |
| 29 | + data: { name: "Alpha", attributes: [], methods: [] }, |
| 30 | + }, |
| 31 | + { |
| 32 | + id: "beta-0000-0000-0000-0000000000002", |
| 33 | + type: "class", |
| 34 | + width: 300, |
| 35 | + height: 200, |
| 36 | + position: { x: 250, y: 250 }, |
| 37 | + measured: { width: 300, height: 200 }, |
| 38 | + data: { name: "Beta", attributes: [], methods: [] }, |
| 39 | + }, |
| 40 | + ], |
| 41 | +} |
| 42 | + |
| 43 | +const SINGLE_MODEL = { |
| 44 | + id: "e2e-toolbar-buttons", |
| 45 | + type: "ClassDiagram", |
| 46 | + version: "4.0.0", |
| 47 | + title: "toolbar buttons", |
| 48 | + assessments: {}, |
| 49 | + edges: [], |
| 50 | + nodes: [ |
| 51 | + { |
| 52 | + id: "solo-0000-0000-0000-0000000000001", |
| 53 | + type: "class", |
| 54 | + width: 200, |
| 55 | + height: 100, |
| 56 | + position: { x: 300, y: 300 }, |
| 57 | + measured: { width: 200, height: 100 }, |
| 58 | + data: { name: "Solo", attributes: [], methods: [] }, |
| 59 | + }, |
| 60 | + ], |
| 61 | +} |
| 62 | + |
| 63 | +const selectedNames = (page: Page) => |
| 64 | + page.evaluate(() => |
| 65 | + Array.from(document.querySelectorAll(".react-flow__node.selected")).map( |
| 66 | + (n) => (n.textContent || "").replace(/\s+/g, " ").trim().slice(0, 8) |
| 67 | + ) |
| 68 | + ) |
| 69 | + |
| 70 | +test("the toolbar's empty area does not block the node beneath it", async ({ |
| 71 | + page, |
| 72 | +}) => { |
| 73 | + await openFixtureInLocalEditor(page, OVERLAP_MODEL as Record<string, unknown>) |
| 74 | + await waitForCanvasReady(page) |
| 75 | + |
| 76 | + const alpha = page.locator(".react-flow__node").filter({ hasText: "Alpha" }) |
| 77 | + // Select Alpha via its bottom strip, which is clear of Beta. |
| 78 | + const aBox = await alpha.boundingBox() |
| 79 | + await page.mouse.click(aBox!.x + aBox!.width / 2, aBox!.y + aBox!.height - 8) |
| 80 | + await page.waitForTimeout(300) |
| 81 | + expect(await selectedNames(page)).toEqual(["Alpha"]) |
| 82 | + |
| 83 | + // A point inside the toolbar box but on no icon (its left margin), which sits |
| 84 | + // over Beta. Clicking it must reach Beta, not be eaten by the toolbar. |
| 85 | + const target = await page.evaluate(() => { |
| 86 | + const tb = document.querySelector<HTMLElement>(".react-flow__node-toolbar")! |
| 87 | + const r = tb.getBoundingClientRect() |
| 88 | + return { x: Math.round(r.x + 2), y: Math.round(r.y + r.height / 2) } |
| 89 | + }) |
| 90 | + await page.mouse.click(target.x, target.y) |
| 91 | + await page.waitForTimeout(300) |
| 92 | + |
| 93 | + expect(await selectedNames(page)).toEqual(["Beta"]) |
| 94 | +}) |
| 95 | + |
| 96 | +test("the toolbar's edit and delete icons still work", async ({ page }) => { |
| 97 | + await openFixtureInLocalEditor(page, SINGLE_MODEL as Record<string, unknown>) |
| 98 | + await waitForCanvasReady(page) |
| 99 | + |
| 100 | + const solo = page.locator(".react-flow__node").filter({ hasText: "Solo" }) |
| 101 | + await solo.click() |
| 102 | + await page.waitForTimeout(300) |
| 103 | + expect(await selectedNames(page)).toEqual(["Solo"]) |
| 104 | + |
| 105 | + // The toolbar renders two lucide icons (svg): [0] = delete, [1] = edit. |
| 106 | + const icons = page.locator(".react-flow__node-toolbar svg") |
| 107 | + |
| 108 | + // Edit (pencil) opens the popover. |
| 109 | + await icons.nth(1).click() |
| 110 | + await page.waitForTimeout(300) |
| 111 | + await expect(page.locator(".apollon-popover")).toHaveCount(1) |
| 112 | + |
| 113 | + // Dismiss the popover, then delete (trash) removes the node. |
| 114 | + await page.keyboard.press("Escape") |
| 115 | + await page.waitForTimeout(200) |
| 116 | + await solo.click() |
| 117 | + await page.waitForTimeout(200) |
| 118 | + await icons.first().click() |
| 119 | + await page.waitForTimeout(300) |
| 120 | + await expect( |
| 121 | + page.locator(".react-flow__node").filter({ hasText: "Solo" }) |
| 122 | + ).toHaveCount(0) |
| 123 | +}) |
0 commit comments