Files
modeling-app/e2e/playwright/fixtures/sceneFixture.ts
Kurt Hutten 5112b48324 Should exit sketchMode when creating new file in the file tree pane (#3993)
* fix new file sketch mode issue

* initial extron app fixture

* Add tests for exiting sketch mode on file tree actions

* organise files

* before all after all clean up

* tweak after each

* makes typedKeys as unsafe

* update mask for draft line snapshots

* fix mask

* add fix again
2024-09-30 21:56:04 +00:00

93 lines
2.4 KiB
TypeScript

import type { Page, Locator } from '@playwright/test'
import { expect } from '@playwright/test'
import { uuidv4 } from 'lib/utils'
import {
closeDebugPanel,
doAndWaitForImageDiff,
openAndClearDebugPanel,
sendCustomCmd,
} from '../test-utils'
type mouseParams = {
pixelDiff: number
}
export class SceneFixture {
public page: Page
private exeIndicator!: Locator
constructor(page: Page) {
this.page = page
this.reConstruct(page)
}
reConstruct = (page: Page) => {
this.page = page
this.exeIndicator = page.getByTestId('model-state-indicator-execution-done')
}
makeMouseHelpers = (
x: number,
y: number,
{ steps }: { steps: number } = { steps: 5000 }
) =>
[
(clickParams?: mouseParams) => {
if (clickParams?.pixelDiff) {
return doAndWaitForImageDiff(
this.page,
() => this.page.mouse.click(x, y),
clickParams.pixelDiff
)
}
return this.page.mouse.click(x, y)
},
(moveParams?: mouseParams) => {
if (moveParams?.pixelDiff) {
return doAndWaitForImageDiff(
this.page,
() => this.page.mouse.move(x, y, { steps }),
moveParams.pixelDiff
)
}
return this.page.mouse.move(x, y, { steps })
},
] as const
/** Likely no where, there's a chance it will click something in the scene, depending what you have in the scene.
*
* Expects the viewPort to be 1000x500 */
clickNoWhere = () => this.page.mouse.click(998, 60)
/** Likely no where, there's a chance it will click something in the scene, depending what you have in the scene.
*
* Expects the viewPort to be 1000x500 */
moveNoWhere = (steps?: number) => this.page.mouse.move(998, 60, { steps })
moveCameraTo = async (
pos: { x: number; y: number; z: number },
target: { x: number; y: number; z: number } = { x: 0, y: 0, z: 0 }
) => {
await openAndClearDebugPanel(this.page)
await doAndWaitForImageDiff(
this.page,
() =>
sendCustomCmd(this.page, {
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'default_camera_look_at',
vantage: pos,
center: target,
up: { x: 0, y: 0, z: 1 },
},
}),
300
)
await closeDebugPanel(this.page)
}
waitForExecutionDone = async () => {
await expect(this.exeIndicator).toBeVisible()
}
}