2026-06-06 08:31:24 +00:00
|
|
|
import { test, expect, type Locator, type Page } from '@playwright/test'
|
2026-05-16 13:19:03 +00:00
|
|
|
|
|
|
|
|
import { CanvasHelper } from '#tests/helpers/canvas'
|
|
|
|
|
|
|
|
|
|
export function useEditorSetup(url = '/') {
|
|
|
|
|
let page: Page
|
|
|
|
|
let canvas: CanvasHelper
|
|
|
|
|
|
|
|
|
|
test.describe.configure({ mode: 'serial' })
|
|
|
|
|
|
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
|
|
|
page = await browser.newPage()
|
|
|
|
|
await page.goto(url)
|
|
|
|
|
canvas = new CanvasHelper(page)
|
|
|
|
|
await canvas.waitForInit()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test.afterAll(async () => {
|
2026-07-20 13:34:16 +00:00
|
|
|
if (page) await page.close()
|
2026-05-16 13:19:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
get page() {
|
|
|
|
|
return page
|
|
|
|
|
},
|
|
|
|
|
get canvas() {
|
|
|
|
|
return canvas
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function useEditorSetupWithClear(url = '/') {
|
|
|
|
|
const ctx = useEditorSetup(url)
|
|
|
|
|
|
|
|
|
|
test.beforeEach(async () => {
|
|
|
|
|
await ctx.canvas.clearCanvas()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 08:31:24 +00:00
|
|
|
export async function expectInViewport(page: Page, locator: Locator) {
|
|
|
|
|
const box = await locator.boundingBox()
|
|
|
|
|
if (!box) throw new Error('Expected visible element to have a bounding box')
|
|
|
|
|
|
|
|
|
|
const viewport = page.viewportSize()
|
|
|
|
|
if (!viewport) throw new Error('Expected page to have a viewport')
|
|
|
|
|
|
|
|
|
|
expect(box.x).toBeGreaterThanOrEqual(0)
|
|
|
|
|
expect(box.y).toBeGreaterThanOrEqual(0)
|
|
|
|
|
expect(box.x + box.width).toBeLessThanOrEqual(viewport.width)
|
|
|
|
|
expect(box.y + box.height).toBeLessThanOrEqual(viewport.height)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 13:19:03 +00:00
|
|
|
export { test, expect }
|