Pass testing-selections.spec.ts

This commit is contained in:
49lf
2024-11-21 10:07:47 -05:00
parent f79a59d415
commit cd6b9c2166
4 changed files with 1284 additions and 1298 deletions

View File

@ -42,7 +42,9 @@ export class HomePageFixture {
this.projectButtonNew = this.page.getByTestId('home-new-file') this.projectButtonNew = this.page.getByTestId('home-new-file')
this.projectTextName = this.page.getByTestId('cmd-bar-arg-value') this.projectTextName = this.page.getByTestId('cmd-bar-arg-value')
this.projectButtonContinue = this.page.getByRole('button', { name: 'Continue' }) this.projectButtonContinue = this.page.getByRole('button', {
name: 'Continue',
})
this.sortByDateBtn = this.page.getByTestId('home-sort-by-modified') this.sortByDateBtn = this.page.getByTestId('home-sort-by-modified')
this.sortByNameBtn = this.page.getByTestId('home-sort-by-name') this.sortByNameBtn = this.page.getByTestId('home-sort-by-name')
@ -119,7 +121,7 @@ export class HomePageFixture {
await projectCard.click() await projectCard.click()
} }
goToModelingScene = async (name?: string = "testDefault") => { goToModelingScene = async (name?: string = 'testDefault') => {
await this.createAndGoToProject(name) await this.createAndGoToProject(name)
} }
} }

View File

@ -99,7 +99,8 @@ async function removeCurrentCode(page: Page) {
export async function sendCustomCmd(page: Page, cmd: EngineCommand) { export async function sendCustomCmd(page: Page, cmd: EngineCommand) {
await page.getByTestId('custom-cmd-input').fill(JSON.stringify(cmd)) await page.getByTestId('custom-cmd-input').fill(JSON.stringify(cmd))
await page.getByTestId('custom-cmd-send-button').click() await page.getByTestId('custom-cmd-send-button').scrollIntoViewIfNeeded()
await page.getByTestId('custom-cmd-send-button').click({ delay: 1000 })
} }
async function clearCommandLogs(page: Page) { async function clearCommandLogs(page: Page) {
@ -165,6 +166,9 @@ async function closeKclCodePanel(page: Page) {
async function openDebugPanel(page: Page) { async function openDebugPanel(page: Page) {
await openPane(page, 'debug-pane-button') await openPane(page, 'debug-pane-button')
// The debug pane needs time to load everything.
await page.waitForTimeout(3000)
} }
export async function closeDebugPanel(page: Page) { export async function closeDebugPanel(page: Page) {

View File

@ -1,25 +1,17 @@
import { test, expect } from '@playwright/test' import { test, expect } from './zoo-test'
import { commonPoints, getUtils, setup, tearDown } from './test-utils' import { commonPoints, getUtils, } from './test-utils'
import { Coords2d } from 'lang/std/sketch' import { Coords2d } from 'lang/std/sketch'
import { KCL_DEFAULT_LENGTH } from 'lib/constants' import { KCL_DEFAULT_LENGTH } from 'lib/constants'
import { uuidv4 } from 'lib/utils' import { uuidv4 } from 'lib/utils'
test.beforeEach(async ({ context, page }, testInfo) => {
await setup(context, page, testInfo)
})
test.afterEach(async ({ page }, testInfo) => {
await tearDown(page, testInfo)
})
test.describe('Testing selections', () => { test.describe('Testing selections', () => {
test.setTimeout(90_000) test.setTimeout(90_000)
test( test('Selections work on fresh and edited sketch', { tag: ['@skipWin'] }, async ({ page, homePage }) => { // Skip on windows its being weird.
'Selections work on fresh and edited sketch',
{ tag: ['@skipWin'] },
async ({ page }) => {
// Skip on windows its being weird.
test.skip(process.platform === 'win32', 'Skip on windows') test.skip(process.platform === 'win32', 'Skip on windows')
// tests mapping works on fresh sketch and edited sketch // tests mapping works on fresh sketch and edited sketch
@ -27,9 +19,9 @@ test.describe('Testing selections', () => {
// source ranges are wrong, hovers won't work // source ranges are wrong, hovers won't work
const u = await getUtils(page) const u = await getUtils(page)
const PUR = 400 / 37.5 //pixeltoUnitRatio const PUR = 400 / 37.5 //pixeltoUnitRatio
await page.setViewportSize({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openDebugPanel() await u.openDebugPanel()
const yAxisClick = () => const yAxisClick = () =>
@ -260,12 +252,9 @@ test.describe('Testing selections', () => {
await test.step(`Test hovering and selecting on edited sketch`, async () => { await test.step(`Test hovering and selecting on edited sketch`, async () => {
await selectionSequence() await selectionSequence()
}) }) })
}
)
test('Solids should be select and deletable', async ({ page }) => { test('Solids should be select and deletable', async ({ page, homePage }) => { test.setTimeout(90_000)
test.setTimeout(90_000)
const u = await getUtils(page) const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
@ -333,9 +322,9 @@ rev = revolve({ axis: 'y' }, part009)
` `
) )
}, KCL_DEFAULT_LENGTH) }, KCL_DEFAULT_LENGTH)
await page.setViewportSize({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await page.goto('/')
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
@ -429,12 +418,8 @@ rev = revolve({ axis: 'y' }, part009)
await page.keyboard.press('Backspace') await page.keyboard.press('Backspace')
await u.expectCmdLog('[data-message-type="execution-done"]', 10_000) await u.expectCmdLog('[data-message-type="execution-done"]', 10_000)
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect(u.codeLocator).not.toContainText(`sketch005 = startSketchOn({`) await expect(u.codeLocator).not.toContainText(`sketch005 = startSketchOn({`) })
}) test("Deleting solid that the AST mod can't handle results in a toast message", async ({ page, homePage }) => { const u = await getUtils(page)
test("Deleting solid that the AST mod can't handle results in a toast message", async ({
page,
}) => {
const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
@ -455,9 +440,9 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
` `
) )
}, KCL_DEFAULT_LENGTH) }, KCL_DEFAULT_LENGTH)
await page.setViewportSize({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await page.goto('/')
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]', 10_000) await u.expectCmdLog('[data-message-type="execution-done"]', 10_000)
@ -493,12 +478,8 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
await u.clearCommandLogs() await u.clearCommandLogs()
await page.keyboard.press('Backspace') await page.keyboard.press('Backspace')
await expect(page.getByText('Unable to delete part')).toBeVisible() await expect(page.getByText('Unable to delete part')).toBeVisible() })
}) test('Hovering over 3d features highlights code, clicking puts the cursor in the right place and sends selection id to engine', async ({ page, homePage }) => { const u = await getUtils(page)
test('Hovering over 3d features highlights code, clicking puts the cursor in the right place and sends selection id to engine', async ({
page,
}) => {
const u = await getUtils(page)
await page.addInitScript(async (KCL_DEFAULT_LENGTH) => { await page.addInitScript(async (KCL_DEFAULT_LENGTH) => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
@ -525,9 +506,9 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
` `
) )
}, KCL_DEFAULT_LENGTH) }, KCL_DEFAULT_LENGTH)
await page.setViewportSize({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
// wait for execution done // wait for execution done
await u.openDebugPanel() await u.openDebugPanel()
@ -833,12 +814,8 @@ extrude001 = extrude(100, sketch001)
adjacentChamfer2, adjacentChamfer2,
`angledLine([segAng(rectangleSegmentA001),-segLen(rectangleSegmentA001)],%,$yo)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001),-segLen(rectangleSegmentA001)],%,$yo)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) ) })
}) test("Extrude button should be disabled if there's no extrudable geometry when nothing is selected", async ({ page, homePage }) => { const u = await getUtils(page)
test("Extrude button should be disabled if there's no extrudable geometry when nothing is selected", async ({
page,
}) => {
const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
@ -859,9 +836,9 @@ extrude001 = extrude(10, sketch001)
` `
) )
}) })
await page.setViewportSize({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
// wait for execution done // wait for execution done
await u.openDebugPanel() await u.openDebugPanel()
@ -901,11 +878,9 @@ sketch002 = startSketchOn(extrude001, $seg01)
// there's not extrudable geometry, so button should be enabled // there's not extrudable geometry, so button should be enabled
await expect( await expect(
page.getByRole('button', { name: 'Extrude' }) page.getByRole('button', { name: 'Extrude' })
).not.toBeDisabled() ).not.toBeDisabled() })
})
test('Fillet button states test', async ({ page }) => { test('Fillet button states test', async ({ page, homePage }) => { const u = await getUtils(page)
const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
@ -919,8 +894,8 @@ sketch002 = startSketchOn(extrude001, $seg01)
) )
}) })
await page.setViewportSize({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel() await u.closeDebugPanel()
@ -945,8 +920,7 @@ extrude001 = extrude(10, sketch001)`
await selectClose() await selectClose()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeDisabled() await expect(page.getByRole('button', { name: 'Fillet' })).toBeDisabled()
await clickEmpty() await clickEmpty()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeEnabled() await expect(page.getByRole('button', { name: 'Fillet' })).toBeEnabled() })
})
const removeAfterFirstParenthesis = (inputString: string) => { const removeAfterFirstParenthesis = (inputString: string) => {
const index = inputString.indexOf('(') const index = inputString.indexOf('(')
@ -956,10 +930,7 @@ extrude001 = extrude(10, sketch001)`
return inputString // return the original string if '(' is not found return inputString // return the original string if '(' is not found
} }
test('Testing selections (and hovers) work on sketches when NOT in sketch mode', async ({ test('Testing selections (and hovers) work on sketches when NOT in sketch mode', async ({ page, homePage }) => { const cases = [
page,
}) => {
const cases = [
{ {
pos: [694, 185], pos: [694, 185],
expectedCode: 'line([74.36, 130.4], %, $seg01)', expectedCode: 'line([74.36, 130.4], %, $seg01)',
@ -990,9 +961,9 @@ part001 = startSketchOn('XZ')
{ cases } { cases }
) )
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
@ -1021,12 +992,8 @@ part001 = startSketchOn('XZ')
await expect(page.locator('.cm-activeLine')).toHaveText( await expect(page.locator('.cm-activeLine')).toHaveText(
'|> ' + expectedCode '|> ' + expectedCode
) )
} } })
}) test("Hovering and selection of extruded faces works, and is not overridden shortly after user's click", async ({ page, homePage }) => { await page.addInitScript(async () => {
test("Hovering and selection of extruded faces works, and is not overridden shortly after user's click", async ({
page,
}) => {
await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')
@ -1040,9 +1007,9 @@ extrude001 = extrude(50, sketch001)
) )
}) })
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
@ -1121,12 +1088,8 @@ extrude001 = extrude(50, sketch001)
await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15) await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15)
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
// check color stays there, i.e. not overridden (this was a bug previously) // check color stays there, i.e. not overridden (this was a bug previously)
await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15) await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15) })
}) test("Various pipe expressions should and shouldn't allow edit and or extrude", async ({ page, homePage }) => { const u = await getUtils(page)
test("Various pipe expressions should and shouldn't allow edit and or extrude", async ({
page,
}) => {
const u = await getUtils(page)
const selectionsSnippets = { const selectionsSnippets = {
extrudeAndEditBlocked: '|> startProfileAt([10.81, 32.99], %)', extrudeAndEditBlocked: '|> startProfileAt([10.81, 32.99], %)',
extrudeAndEditBlockedInFunction: '|> startProfileAt(pos, %)', extrudeAndEditBlockedInFunction: '|> startProfileAt(pos, %)',
@ -1180,9 +1143,9 @@ extrude001 = extrude(50, sketch001)
}, },
selectionsSnippets selectionsSnippets
) )
await page.setViewportSize({ width: 1200, height: 1000 }) await page.setBodyDimensions({ width: 1200, height: 1000 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
// wait for execution done // wait for execution done
await u.openDebugPanel() await u.openDebugPanel()
@ -1217,22 +1180,18 @@ extrude001 = extrude(50, sketch001)
await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled()
await expect( await expect(
page.getByRole('button', { name: 'Edit Sketch' }) page.getByRole('button', { name: 'Edit Sketch' })
).not.toBeVisible() ).not.toBeVisible() })
})
test('Deselecting line tool should mean nothing happens on click', async ({ test('Deselecting line tool should mean nothing happens on click', async ({ page, homePage }) => { /**
page,
}) => {
/**
* If the line tool is clicked when the state is 'No Points' it will exit Sketch mode. * If the line tool is clicked when the state is 'No Points' it will exit Sketch mode.
* This is the same exact workflow as pressing ESC. * This is the same exact workflow as pressing ESC.
* *
* To continue to test this workflow, we now enter sketch mode and place a single point before exiting the line tool. * To continue to test this workflow, we now enter sketch mode and place a single point before exiting the line tool.
*/ */
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await u.waitForAuthSkipAppStart() await homePage.goToModelingScene()
await u.openDebugPanel() await u.openDebugPanel()
await expect( await expect(
@ -1302,6 +1261,5 @@ extrude001 = extrude(50, sketch001)
await expect(page.locator('.cm-content')).not.toHaveText( await expect(page.locator('.cm-content')).not.toHaveText(
previousCodeContent previousCodeContent
) )
previousCodeContent = await page.locator('.cm-content').innerText() previousCodeContent = await page.locator('.cm-content').innerText() })
})
}) })

View File

@ -1,5 +1,9 @@
import { test as playwrightTestFn } from '@playwright/test' import { test as playwrightTestFn } from '@playwright/test'
import { fixtures, Fixtures, AuthenticatedTronApp } from './fixtures/fixtureSetup' import {
fixtures,
Fixtures,
AuthenticatedTronApp,
} from './fixtures/fixtureSetup'
export { expect, Page, BrowserContext, TestInfo } from '@playwright/test' export { expect, Page, BrowserContext, TestInfo } from '@playwright/test'
// Our custom decorated Zoo test object. Makes it easier to add fixtures, and // Our custom decorated Zoo test object. Makes it easier to add fixtures, and
@ -10,13 +14,15 @@ export function test(desc, objOrFn, fnMaybe) {
const hasTestConf = typeof objOrFn === 'object' const hasTestConf = typeof objOrFn === 'object'
const fn = hasTestConf ? fnMaybe : objOrFn const fn = hasTestConf ? fnMaybe : objOrFn
return pwTestFnWithFixtures(desc, hasTestConf ? objOrFn : {}, async ({ page, context, cmdBar, editor, toolbar, scene, homePage }, testInfo) => { return pwTestFnWithFixtures(
// To switch to web, change this to AuthenticatedApp from fixtureSetup.ts desc,
const tronApp = new AuthenticatedTronApp( hasTestConf ? objOrFn : {},
context, async (
page, { page, context, cmdBar, editor, toolbar, scene, homePage },
testInfo testInfo
) ) => {
// To switch to web, change this to AuthenticatedApp from fixtureSetup.ts
const tronApp = new AuthenticatedTronApp(context, page, testInfo)
const fixtures: Fixtures = { cmdBar, editor, toolbar, scene, homePage } const fixtures: Fixtures = { cmdBar, editor, toolbar, scene, homePage }
await tronApp.initialise({ fixtures }) await tronApp.initialise({ fixtures })
@ -37,14 +43,29 @@ export function test(desc, objOrFn, fnMaybe) {
await tronApp.page.reload() await tronApp.page.reload()
} }
await fn({ // Create a consistent way to resize the page across electron and web.
tronApp.page.setBodyDimensions = async function (dims: {
width: number
height: number
}) {
return this.evaluate((dims) => {
window.document.body.style.width = dims.width + 'px'
window.document.body.style.height = dims.height + 'px'
}, dims)
}
await fn(
{
context: tronApp.context, context: tronApp.context,
page: tronApp.page, page: tronApp.page,
...fixtures ...fixtures,
}, testInfo) },
testInfo
)
testInfo.tronApp = tronApp testInfo.tronApp = tronApp
}) }
)
} }
test.describe = pwTestFnWithFixtures.describe test.describe = pwTestFnWithFixtures.describe
@ -52,3 +73,4 @@ test.beforeEach = pwTestFnWithFixtures.beforeEach
test.afterEach = pwTestFnWithFixtures.afterEach test.afterEach = pwTestFnWithFixtures.afterEach
test.step = pwTestFnWithFixtures.step test.step = pwTestFnWithFixtures.step
test.skip = pwTestFnWithFixtures.skip test.skip = pwTestFnWithFixtures.skip
test.setTimeout = pwTestFnWithFixtures.setTimeout