|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test.describe("Node Creation", () => { |
| 4 | + test("should create a new node via context menu", async ({ page }) => { |
| 5 | + await page.goto("/"); |
| 6 | + |
| 7 | + // Wait for canvas to load |
| 8 | + await page.locator('[data-node="true"]').first().waitFor(); |
| 9 | + |
| 10 | + // Count initial nodes |
| 11 | + const initialNodeCount = await page.locator('[data-node="true"]').count(); |
| 12 | + |
| 13 | + // Right-click on empty canvas space to open context menu |
| 14 | + const canvas = page.locator(".relative.bg-background").first(); |
| 15 | + await canvas.click({ button: "right", position: { x: 600, y: 400 } }); |
| 16 | + |
| 17 | + // Wait for context menu to appear |
| 18 | + await page.waitForTimeout(200); |
| 19 | + |
| 20 | + // Click "Add Node" in context menu |
| 21 | + const addNodeButton = page.getByText("Add Node"); |
| 22 | + await expect(addNodeButton).toBeVisible(); |
| 23 | + await addNodeButton.click(); |
| 24 | + |
| 25 | + // Wait for new node to be created |
| 26 | + await page.waitForTimeout(500); |
| 27 | + |
| 28 | + // Count nodes after creation |
| 29 | + const newNodeCount = await page.locator('[data-node="true"]').count(); |
| 30 | + |
| 31 | + // Should have one more node |
| 32 | + expect(newNodeCount).toBe(initialNodeCount + 1); |
| 33 | + }); |
| 34 | + |
| 35 | + test("should create a node using add arrow buttons", async ({ page }) => { |
| 36 | + await page.goto("/"); |
| 37 | + |
| 38 | + // Wait for canvas to load |
| 39 | + await page.locator('[data-node="true"]').first().waitFor(); |
| 40 | + |
| 41 | + // Click on a node to select it |
| 42 | + const firstNode = page.locator('[data-node="true"]').first(); |
| 43 | + await firstNode.click(); |
| 44 | + |
| 45 | + // Wait for node to be selected and add arrow buttons to appear |
| 46 | + await page.waitForTimeout(300); |
| 47 | + |
| 48 | + // Count initial nodes |
| 49 | + const initialNodeCount = await page.locator('[data-node="true"]').count(); |
| 50 | + |
| 51 | + // Look for an add arrow button (they should be visible on selected nodes) |
| 52 | + // Try to find one of the directional arrow buttons |
| 53 | + const arrowButton = page |
| 54 | + .locator('button:has(svg[class*="lucide-arrow"])') |
| 55 | + .first(); |
| 56 | + |
| 57 | + if (await arrowButton.isVisible()) { |
| 58 | + // Click and drag the arrow button to create a new connection |
| 59 | + await arrowButton.hover(); |
| 60 | + await page.mouse.down(); |
| 61 | + |
| 62 | + // Drag to a new position |
| 63 | + await page.mouse.move(700, 300); |
| 64 | + await page.mouse.up(); |
| 65 | + |
| 66 | + // Wait for node creation |
| 67 | + await page.waitForTimeout(500); |
| 68 | + |
| 69 | + // Count nodes after creation |
| 70 | + const newNodeCount = await page.locator('[data-node="true"]').count(); |
| 71 | + |
| 72 | + // Should have one more node |
| 73 | + expect(newNodeCount).toBe(initialNodeCount + 1); |
| 74 | + } |
| 75 | + }); |
| 76 | +}); |
0 commit comments