Compare commits

...

1 Commits

Author SHA1 Message Date
70cb6372f1 small test improvement 2024-11-28 16:37:46 +11:00
2 changed files with 55 additions and 46 deletions

View File

@ -1,31 +1,38 @@
import { test, expect, Page } from '@playwright/test' import { test, expect, AuthenticatedApp } from './fixtures/fixtureSetup'
import { Page } from '@playwright/test'
import { import {
getUtils, getUtils,
TEST_COLORS, TEST_COLORS,
setup,
tearDown,
commonPoints, commonPoints,
PERSIST_MODELING_CONTEXT, PERSIST_MODELING_CONTEXT,
} from './test-utils' } from './test-utils'
import { SceneFixture } from './fixtures/sceneFixture'
test.beforeEach(async ({ context, page }, testInfo) => {
await setup(context, page, testInfo)
})
test.afterEach(async ({ page }, testInfo) => {
await tearDown(page, testInfo)
})
test.setTimeout(120000) test.setTimeout(120000)
async function doBasicSketch(page: Page, openPanes: string[]) { async function doBasicSketch(
page: Page,
app: AuthenticatedApp,
scene: SceneFixture,
openPanes: string[]
) {
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await app.initialise(
'',
openPanes.includes('code')
? async () => {}
: async () => {
await app.page.addInitScript(async (persistModelingContext) => {
localStorage.setItem(
persistModelingContext,
JSON.stringify({ openPanes: [] })
)
}, PERSIST_MODELING_CONTEXT)
}
)
await app.page.setViewportSize({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio const PUR = 400 / 37.5 //pixeltoUnitRatio
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
// If we have the code pane open, we should see the code. // If we have the code pane open, we should see the code.
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(``) await expect(u.codeLocator).toHaveText(``)
@ -40,7 +47,7 @@ async function doBasicSketch(page: Page, openPanes: string[]) {
await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeVisible() await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeVisible()
// click on "Start Sketch" button // click on "Start Sketch" button
await u.clearCommandLogs() await u.openAndClearDebugPanel()
await page.getByRole('button', { name: 'Start Sketch' }).click() await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
@ -51,36 +58,39 @@ async function doBasicSketch(page: Page, openPanes: string[]) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')`) await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')`)
} }
await u.closeDebugPanel() await u.closeDebugPanel()
const yAxisRed: [number, number, number] = [92, 50, 50]
await scene.expectPixelColor(yAxisRed, { x: 600, y: 423 }, 15)
await page.waitForTimeout(1000) // TODO detect animation ending, or disable animation await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
const startXPx = 600 const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await scene.expectPixelColor(TEST_COLORS.WHITE, { x: 708, y: 392 }, 15)
|> startProfileAt(${commonPoints.startAt}, %)`)
}
await page.waitForTimeout(500)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(500)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %) |> startProfileAt(${commonPoints.startAt}, %)`)
|> xLine(${commonPoints.num1}, %)`) }
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await scene.expectPixelColor(TEST_COLORS.WHITE, { x: 799, y: 392 }, 15)
if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> xLine(${commonPoints.num1}, %)`)
} }
await page.waitForTimeout(500)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20) await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await scene.expectPixelColor(TEST_COLORS.WHITE, { x: 812, y: 297 }, 15)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %) |> startProfileAt(${commonPoints.startAt}, %)
|> xLine(${commonPoints.num1}, %) |> xLine(${commonPoints.num1}, %)
|> yLine(${commonPoints.num1 + 0.01}, %)`) |> yLine(${commonPoints.num1 + 0.01}, %)`)
} else {
await page.waitForTimeout(500)
} }
await page.waitForTimeout(200)
await page.mouse.click(startXPx, 500 - PUR * 20) await page.mouse.click(startXPx, 500 - PUR * 20)
await scene.expectPixelColor(TEST_COLORS.WHITE, { x: 612, y: 285 }, 15)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %) |> startProfileAt(${commonPoints.startAt}, %)
@ -148,20 +158,17 @@ async function doBasicSketch(page: Page, openPanes: string[]) {
} }
test.describe('Basic sketch', () => { test.describe('Basic sketch', () => {
test('code pane open at start', { tag: ['@skipWin'] }, async ({ page }) => { test(
// Skip on windows it is being weird. 'code pane open at start',
test.skip(process.platform === 'win32', 'Skip on windows') { tag: ['@skipWin'] },
await doBasicSketch(page, ['code']) async ({ app, scene }) => {
}) // Skip on windows it is being weird.
test.skip(process.platform === 'win32', 'Skip on windows')
await doBasicSketch(app.page, app, scene, ['code'])
}
)
test('code pane closed at start', async ({ page }) => { test('code pane closed at start', async ({ page, app, scene }) => {
// Load the app with the code panes await doBasicSketch(page, app, scene, [])
await page.addInitScript(async (persistModelingContext) => {
localStorage.setItem(
persistModelingContext,
JSON.stringify({ openPanes: [] })
)
}, PERSIST_MODELING_CONTEXT)
await doBasicSketch(page, [])
}) })
}) })

View File

@ -28,10 +28,12 @@ export class AuthenticatedApp {
this.testInfo = testInfo this.testInfo = testInfo
} }
async initialise(code = '') { async initialise(code = '', fn: () => Promise<any> = async () => {}) {
await setup(this.context, this.page, this.testInfo) await setup(this.context, this.page, this.testInfo)
const u = await getUtils(this.page) const u = await getUtils(this.page)
await fn()
await this.page.addInitScript(async (code) => { await this.page.addInitScript(async (code) => {
localStorage.setItem('persistCode', code) localStorage.setItem('persistCode', code)
;(window as any).playwrightSkipFilePicker = true ;(window as any).playwrightSkipFilePicker = true