2024-03-06 18:34:07 +03:00
|
|
|
import { test } from '@playwright/test'
|
2024-02-28 16:14:48 +03:00
|
|
|
import assert from 'assert'
|
|
|
|
import * as actions from './actions'
|
2024-03-06 18:34:07 +03:00
|
|
|
import { expect } from './customExpect'
|
2024-02-28 16:14:48 +03:00
|
|
|
import * as locate from './locate'
|
|
|
|
|
|
|
|
test('Selecting nodes by click', async ({ page }) => {
|
|
|
|
await actions.goToGraph(page)
|
|
|
|
const node1 = locate.graphNodeByBinding(page, 'five')
|
2024-03-08 22:00:39 +03:00
|
|
|
const node2 = locate.graphNodeByBinding(page, 'final')
|
2024-04-24 11:56:44 +03:00
|
|
|
const selectionMenu = page.locator('.SelectionMenu')
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).not.toBeSelected()
|
|
|
|
await expect(node2).not.toBeSelected()
|
2024-07-12 13:45:57 +03:00
|
|
|
await expect(selectionMenu).toBeHidden()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
|
|
|
await locate.graphNodeIcon(node1).click()
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).toBeSelected()
|
|
|
|
await expect(node2).not.toBeSelected()
|
2024-07-12 13:45:57 +03:00
|
|
|
await expect(selectionMenu).toBeHidden()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-08 22:00:39 +03:00
|
|
|
// Check that clicking an unselected node deselects replaces the previous selection.
|
2024-02-28 16:14:48 +03:00
|
|
|
await locate.graphNodeIcon(node2).click()
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).not.toBeSelected()
|
|
|
|
await expect(node2).toBeSelected()
|
2024-07-12 13:45:57 +03:00
|
|
|
await expect(selectionMenu).toBeHidden()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-06 18:34:07 +03:00
|
|
|
await page.waitForTimeout(300) // Avoid double clicks
|
2024-02-28 16:14:48 +03:00
|
|
|
await locate.graphNodeIcon(node1).click({ modifiers: ['Shift'] })
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).toBeSelected()
|
|
|
|
await expect(node2).toBeSelected()
|
2024-04-24 11:56:44 +03:00
|
|
|
await expect(selectionMenu).toBeVisible()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-08 22:00:39 +03:00
|
|
|
// Check that when two nodes are selected, clicking a selected node replaces the previous selection.
|
2024-02-28 16:14:48 +03:00
|
|
|
await locate.graphNodeIcon(node2).click()
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).not.toBeSelected()
|
|
|
|
await expect(node2).toBeSelected()
|
2024-07-12 13:45:57 +03:00
|
|
|
await expect(selectionMenu).toBeHidden()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-08 22:00:39 +03:00
|
|
|
// Check that clicking the background deselects all nodes.
|
2024-05-24 16:28:51 +03:00
|
|
|
await locate.graphEditor(page).click({ position: { x: 600, y: 200 } })
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).not.toBeSelected()
|
|
|
|
await expect(node2).not.toBeSelected()
|
2024-07-12 13:45:57 +03:00
|
|
|
await expect(selectionMenu).toBeHidden()
|
2024-02-28 16:14:48 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Selecting nodes by area drag', async ({ page }) => {
|
|
|
|
await actions.goToGraph(page)
|
|
|
|
const node1 = locate.graphNodeByBinding(page, 'five')
|
|
|
|
const node2 = locate.graphNodeByBinding(page, 'ten')
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).not.toBeSelected()
|
|
|
|
await expect(node2).not.toBeSelected()
|
2024-02-28 16:14:48 +03:00
|
|
|
|
2024-03-11 18:40:16 +03:00
|
|
|
const node1Id = await node1.getAttribute('data-node-id')
|
|
|
|
const node1Selection = page.locator(`.GraphNodeSelection[data-node-id="${node1Id}"]`)
|
|
|
|
const node1BBox = await node1Selection.boundingBox()
|
2024-02-28 16:14:48 +03:00
|
|
|
const node2BBox = await node2.boundingBox()
|
|
|
|
assert(node1BBox)
|
|
|
|
assert(node2BBox)
|
|
|
|
await page.mouse.move(node1BBox.x - 50, node1BBox.y - 50)
|
|
|
|
await page.mouse.down()
|
2024-07-25 17:26:29 +03:00
|
|
|
await page.mouse.move(node1BBox.x - 40, node1BBox.y - 40)
|
|
|
|
// await expect(page.locator('.SelectionBrush')).toBeVisible()
|
2024-02-28 16:14:48 +03:00
|
|
|
await page.mouse.move(node2BBox.x + node2BBox.width, node2BBox.y + node2BBox.height)
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).toBeSelected()
|
|
|
|
await expect(node2).toBeSelected()
|
2024-02-28 16:14:48 +03:00
|
|
|
await page.mouse.up()
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(node1).toBeSelected()
|
|
|
|
await expect(node2).toBeSelected()
|
2024-02-28 16:14:48 +03:00
|
|
|
})
|
2024-05-24 17:57:45 +03:00
|
|
|
|
2024-06-06 19:47:02 +03:00
|
|
|
test('Moving selected nodes', async ({ page }) => {
|
|
|
|
await actions.goToGraph(page)
|
|
|
|
const movedNode = locate.graphNodeByBinding(page, 'final')
|
|
|
|
const notMovedNode = locate.graphNodeByBinding(page, 'sum')
|
|
|
|
await locate.graphNodeIcon(movedNode).click()
|
|
|
|
// Selection may affect bounding box: wait until it's actually selected.
|
|
|
|
await expect(movedNode).toBeSelected()
|
|
|
|
const initialBBox = await movedNode.boundingBox()
|
|
|
|
const initialNotMovedBBox = await notMovedNode.boundingBox()
|
|
|
|
assert(initialBBox)
|
|
|
|
assert(initialNotMovedBBox)
|
|
|
|
await page.keyboard.press('ArrowLeft', { delay: 500 })
|
|
|
|
const bbox = await movedNode.boundingBox()
|
|
|
|
const notMovedBBox = await notMovedNode.boundingBox()
|
|
|
|
assert(bbox)
|
|
|
|
assert(notMovedBBox)
|
|
|
|
await expect(bbox.x).not.toBeCloseTo(initialBBox.x)
|
|
|
|
await expect(bbox.y).toBeCloseTo(initialBBox.y)
|
|
|
|
await expect(notMovedBBox.x).toBeCloseTo(initialNotMovedBBox.x)
|
|
|
|
await expect(notMovedBBox.y).toBeCloseTo(initialNotMovedBBox.y)
|
|
|
|
})
|