|
| 1 | +import { test, expect, Page } from "@playwright/test"; |
| 2 | +import { deckPointerEvent } from "./helpers/deckgl"; |
| 3 | +import { |
| 4 | + openNotebookFresh, |
| 5 | + runFirstNCells, |
| 6 | + executeCellAndWaitForOutput, |
| 7 | +} from "./helpers/notebook"; |
| 8 | +import { validateBounds } from "./helpers/assertions"; |
| 9 | + |
| 10 | +/** |
| 11 | + * Draws a bounding box on the DeckGL canvas by clicking start and end positions. |
| 12 | + */ |
| 13 | +async function drawBbox( |
| 14 | + page: Page, |
| 15 | + start: { x: number; y: number }, |
| 16 | + end: { x: number; y: number }, |
| 17 | +) { |
| 18 | + // Click to set bbox start position |
| 19 | + await deckPointerEvent(page, "click", start.x, start.y); |
| 20 | + await page.waitForTimeout(300); |
| 21 | + |
| 22 | + // Hover to preview bbox size |
| 23 | + await deckPointerEvent(page, "hover", end.x, end.y); |
| 24 | + await page.waitForTimeout(300); |
| 25 | + |
| 26 | + // Click to set bbox end position and complete drawing |
| 27 | + await deckPointerEvent(page, "click", end.x, end.y); |
| 28 | + await page.waitForTimeout(500); |
| 29 | +} |
| 30 | + |
| 31 | +test.describe("BBox selection", () => { |
| 32 | + test("draws bbox and syncs selected_bounds to Python", async ({ page }) => { |
| 33 | + const { notebookRoot } = await openNotebookFresh(page, "simple-map.ipynb", { |
| 34 | + workspaceId: `bbox-${Date.now()}`, |
| 35 | + }); |
| 36 | + await runFirstNCells(page, notebookRoot, 2); |
| 37 | + await page.waitForTimeout(2000); |
| 38 | + |
| 39 | + // Start bbox selection mode |
| 40 | + const bboxButton = page.getByRole("button", { name: "Select BBox" }); |
| 41 | + await expect(bboxButton).toBeVisible({ timeout: 10000 }); |
| 42 | + await bboxButton.click(); |
| 43 | + |
| 44 | + // Verify drawing mode is active |
| 45 | + const cancelButton = page.getByRole("button", { name: "Cancel drawing" }); |
| 46 | + await expect(cancelButton).toBeVisible({ timeout: 5000 }); |
| 47 | + |
| 48 | + // Draw bbox using canvas-relative coordinates (pixels from canvas top-left) |
| 49 | + await drawBbox(page, { x: 200, y: 200 }, { x: 400, y: 400 }); |
| 50 | + |
| 51 | + // Verify bbox was drawn |
| 52 | + const clearButton = page.getByRole("button", { |
| 53 | + name: "Clear bounding box", |
| 54 | + }); |
| 55 | + await expect(clearButton).toBeVisible({ timeout: 2000 }); |
| 56 | + |
| 57 | + // Execute cell to check selected bounds |
| 58 | + const output = await executeCellAndWaitForOutput(notebookRoot, 2); |
| 59 | + |
| 60 | + // Verify bounds are valid geographic coordinates |
| 61 | + const outputText = await output.textContent(); |
| 62 | + validateBounds(outputText); |
| 63 | + }); |
| 64 | +}); |
0 commit comments