2024-03-06 18:34:07 +03:00
|
|
|
import { type Page } from '@playwright/test'
|
|
|
|
import { expect } from './customExpect'
|
2024-02-05 17:20:24 +03:00
|
|
|
import * as locate from './locate'
|
2024-02-06 19:15:00 +03:00
|
|
|
import { graphNodeByBinding } from './locate'
|
2023-11-27 18:48:37 +03:00
|
|
|
|
|
|
|
// =================
|
|
|
|
// === goToGraph ===
|
|
|
|
// =================
|
|
|
|
|
|
|
|
/** Perform a successful login. */
|
|
|
|
export async function goToGraph(page: Page) {
|
|
|
|
await page.goto('/')
|
2024-02-05 17:20:24 +03:00
|
|
|
await expect(page.locator('.App')).toBeVisible()
|
|
|
|
// Wait until nodes are loaded.
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(locate.graphNode(page)).toExist()
|
2024-02-28 16:14:48 +03:00
|
|
|
// Wait for position initialization
|
2024-03-06 18:34:07 +03:00
|
|
|
await expectNodePositionsInitialized(page, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function expectNodePositionsInitialized(page: Page, yPos: number) {
|
2024-03-14 16:43:44 +03:00
|
|
|
// Wait until edges are initialized and displayed correctly.
|
|
|
|
await expect(page.getByTestId('broken-edge')).toHaveCount(0)
|
|
|
|
// Wait until node sizes are initialized.
|
|
|
|
await expect(locate.graphNode(page).first().locator('.bgFill')).toBeVisible()
|
2024-03-06 18:34:07 +03:00
|
|
|
// TODO: The yPos should not need to be a variable. Instead, first automatically positioned nodes
|
|
|
|
// should always have constant known position. This is a bug caused by incorrect layout after
|
|
|
|
// entering a function. To be fixed with #9255
|
2024-02-28 16:14:48 +03:00
|
|
|
await expect(locate.graphNode(page).first()).toHaveCSS(
|
|
|
|
'transform',
|
2024-03-06 18:34:07 +03:00
|
|
|
`matrix(1, 0, 0, 1, -16, ${yPos})`,
|
2024-02-28 16:14:48 +03:00
|
|
|
)
|
2023-11-27 18:48:37 +03:00
|
|
|
}
|
2024-02-06 19:15:00 +03:00
|
|
|
|
2024-03-06 18:34:07 +03:00
|
|
|
export async function exitFunction(page: Page, x = 300, y = 300) {
|
|
|
|
await page.mouse.dblclick(x, y, { delay: 10 })
|
|
|
|
}
|
|
|
|
|
2024-02-06 19:15:00 +03:00
|
|
|
// =================
|
|
|
|
// === Drag Node ===
|
|
|
|
// =================
|
|
|
|
|
|
|
|
/// Move node defined by the given binding by the given x and y.
|
|
|
|
export async function dragNodeByBinding(page: Page, nodeBinding: string, x: number, y: number) {
|
|
|
|
const node = graphNodeByBinding(page, nodeBinding)
|
|
|
|
const grabHandle = await node.locator('.grab-handle')
|
|
|
|
await grabHandle.dragTo(grabHandle, {
|
|
|
|
targetPosition: { x, y },
|
|
|
|
force: true,
|
|
|
|
})
|
|
|
|
}
|