Pass testing-selections.spec.ts

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

View File

@ -41,7 +41,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')
@ -116,7 +118,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(
@ -276,66 +265,66 @@ test.describe('Testing selections', () => {
|> line([170.36, -121.61], %, $seg01) |> line([170.36, -121.61], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
extrude001 = extrude(50, sketch001) extrude001 = extrude(50, sketch001)
sketch005 = startSketchOn(extrude001, 'END') sketch005 = startSketchOn(extrude001, 'END')
|> startProfileAt([23.24, 136.52], %) |> startProfileAt([23.24, 136.52], %)
|> line([-8.44, 36.61], %) |> line([-8.44, 36.61], %)
|> line([49.4, 2.05], %) |> line([49.4, 2.05], %)
|> line([29.69, -46.95], %) |> line([29.69, -46.95], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
sketch003 = startSketchOn(extrude001, seg01) sketch003 = startSketchOn(extrude001, seg01)
|> startProfileAt([21.23, 17.81], %) |> startProfileAt([21.23, 17.81], %)
|> line([51.97, 21.32], %) |> line([51.97, 21.32], %)
|> line([4.07, -22.75], %) |> line([4.07, -22.75], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
sketch002 = startSketchOn(extrude001, seg02) sketch002 = startSketchOn(extrude001, seg02)
|> startProfileAt([-100.54, 16.99], %) |> startProfileAt([-100.54, 16.99], %)
|> line([0, 20.03], %) |> line([0, 20.03], %)
|> line([62.61, 0], %, $seg03) |> line([62.61, 0], %, $seg03)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
extrude002 = extrude(50, sketch002) extrude002 = extrude(50, sketch002)
sketch004 = startSketchOn(extrude002, seg03) sketch004 = startSketchOn(extrude002, seg03)
|> startProfileAt([57.07, 134.77], %) |> startProfileAt([57.07, 134.77], %)
|> line([-4.72, 22.84], %) |> line([-4.72, 22.84], %)
|> line([28.8, 6.71], %) |> line([28.8, 6.71], %)
|> line([9.19, -25.33], %) |> line([9.19, -25.33], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
extrude003 = extrude(20, sketch004) extrude003 = extrude(20, sketch004)
pipeLength = 40 pipeLength = 40
pipeSmallDia = 10 pipeSmallDia = 10
pipeLargeDia = 20 pipeLargeDia = 20
thickness = 0.5 thickness = 0.5
part009 = startSketchOn('XY') part009 = startSketchOn('XY')
|> startProfileAt([pipeLargeDia - (thickness / 2), 38], %) |> startProfileAt([pipeLargeDia - (thickness / 2), 38], %)
|> line([thickness, 0], %) |> line([thickness, 0], %)
|> line([0, -1], %) |> line([0, -1], %)
|> angledLineToX({ |> angledLineToX({
angle = 60, angle: 60,
to = pipeSmallDia + thickness to: pipeSmallDia + thickness
}, %) }, %)
|> line([0, -pipeLength], %) |> line([0, -pipeLength], %)
|> angledLineToX({ |> angledLineToX({
angle = -60, angle: -60,
to = pipeLargeDia + thickness to: pipeLargeDia + thickness
}, %) }, %)
|> line([0, -1], %) |> line([0, -1], %)
|> line([-thickness, 0], %) |> line([-thickness, 0], %)
|> line([0, 1], %) |> line([0, 1], %)
|> angledLineToX({ angle = 120, to = pipeSmallDia }, %) |> angledLineToX({ angle: 120, to: pipeSmallDia }, %)
|> line([0, pipeLength], %) |> line([0, pipeLength], %)
|> angledLineToX({ angle = 60, to = pipeLargeDia }, %) |> angledLineToX({ angle: 60, to: pipeLargeDia }, %)
|> close(%) |> close(%)
rev = revolve({ axis = 'y' }, part009) 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"]')
@ -395,27 +384,27 @@ rev = revolve({ axis = 'y' }, part009)
`extrude001 = extrude(50, sketch001)` `extrude001 = extrude(50, sketch001)`
) )
await expect(u.codeLocator).toContainText(`sketch005 = startSketchOn({ await expect(u.codeLocator).toContainText(`sketch005 = startSketchOn({
plane = { plane: {
origin = { x = 0, y = -50, z = 0 }, origin: { x: 0, y: -50, z: 0 },
x_axis = { x = 1, y = 0, z = 0 }, x_axis: { x: 1, y: 0, z: 0 },
y_axis = { x = 0, y = 0, z = 1 }, y_axis: { x: 0, y: 0, z: 1 },
z_axis = { x = 0, y = -1, z = 0 } z_axis: { x: 0, y: -1, z: 0 }
} }
})`) })`)
await expect(u.codeLocator).toContainText(`sketch003 = startSketchOn({ await expect(u.codeLocator).toContainText(`sketch003 = startSketchOn({
plane = { plane: {
origin = { x = 116.53, y = 0, z = 163.25 }, origin: { x: 116.53, y: 0, z: 163.25 },
x_axis = { x = -0.81, y = 0, z = 0.58 }, x_axis: { x: -0.81, y: 0, z: 0.58 },
y_axis = { x = 0, y = -1, z = 0 }, y_axis: { x: 0, y: -1, z: 0 },
z_axis = { x = 0.58, y = 0, z = 0.81 } z_axis: { x: 0.58, y: 0, z: 0.81 }
} }
})`) })`)
await expect(u.codeLocator).toContainText(`sketch002 = startSketchOn({ await expect(u.codeLocator).toContainText(`sketch002 = startSketchOn({
plane = { plane: {
origin = { x = -91.74, y = 0, z = 80.89 }, origin: { x: -91.74, y: 0, z: 80.89 },
x_axis = { x = -0.66, y = 0, z = -0.75 }, x_axis: { x: -0.66, y: 0, z: -0.75 },
y_axis = { x = 0, y = -1, z = 0 }, y_axis: { x: 0, y: -1, z: 0 },
z_axis = { x = -0.75, y = 0, z = 0.66 } z_axis: { x: -0.75, y: 0, z: 0.66 }
} }
})`) })`)
@ -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',
@ -444,20 +429,20 @@ rev = revolve({ axis = 'y' }, part009)
|> line([170.36, -121.61], %, $seg01) |> line([170.36, -121.61], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
extrude001 = extrude(50, sketch001) extrude001 = extrude(50, sketch001)
launderExtrudeThroughVar = extrude001 launderExtrudeThroughVar = extrude001
sketch002 = startSketchOn(launderExtrudeThroughVar, seg02) sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
|> startProfileAt([-100.54, 16.99], %) |> startProfileAt([-100.54, 16.99], %)
|> line([0, 20.03], %) |> line([0, 20.03], %)
|> line([62.61, 0], %, $seg03) |> line([62.61, 0], %, $seg03)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
` `
) )
}, 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,31 +478,27 @@ 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',
`part001 = startSketchOn('XZ') `part001 = startSketchOn('XZ')
|> startProfileAt([20, 0], %) |> startProfileAt([20, 0], %)
|> line([7.13, 4 + 0], %) |> line([7.13, 4 + 0], %)
|> angledLine({ angle = 3 + 0, length = 3.14 + 0 }, %) |> angledLine({ angle: 3 + 0, length: 3.14 + 0 }, %)
|> lineTo([20.14 + 0, -0.14 + 0], %) |> lineTo([20.14 + 0, -0.14 + 0], %)
|> xLineTo(29 + 0, %) |> xLineTo(29 + 0, %)
|> yLine(-3.14 + 0, %, $a) |> yLine(-3.14 + 0, %, $a)
|> xLine(1.63, %) |> xLine(1.63, %)
|> angledLineOfXLength({ angle = 3 + 0, length = 3.14 }, %) |> angledLineOfXLength({ angle: 3 + 0, length: 3.14 }, %)
|> angledLineOfYLength({ angle = 30, length = 3 + 0 }, %) |> angledLineOfYLength({ angle: 30, length: 3 + 0 }, %)
|> angledLineToX({ angle = 22.14 + 0, to = 12 }, %) |> angledLineToX({ angle: 22.14 + 0, to: 12 }, %)
|> angledLineToY({ angle = 30, to = 11.14 }, %) |> angledLineToY({ angle: 30, to: 11.14 }, %)
|> angledLineThatIntersects({ |> angledLineThatIntersects({
angle = 3.14, angle: 3.14,
intersectTag = a, intersectTag: a,
offset = 0 offset: 0
}, %) }, %)
|> tangentialArcTo([13.14 + 0, 13.14], %) |> tangentialArcTo([13.14 + 0, 13.14], %)
|> close(%) |> close(%)
@ -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()
@ -650,7 +631,7 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'flatExtrusionFace', 'flatExtrusionFace',
flatExtrusionFace, flatExtrusionFace,
`angledLineThatIntersects({angle=3.14,intersectTag=a,offset=0},%)extrude(5+7,%)`, `angledLineThatIntersects({angle:3.14,intersectTag:a,offset:0},%)extrude(5+7,%)`,
'}, %)' '}, %)'
) )
@ -707,19 +688,19 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentEdge', 'straightSegmentEdge',
straightSegmentEdge, straightSegmentEdge,
`angledLineToY({angle=30,to=11.14},%)`, `angledLineToY({angle:30,to:11.14},%)`,
'angledLineToY({ angle = 30, to = 11.14 }, %)' 'angledLineToY({ angle: 30, to: 11.14 }, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentOppositeEdge', 'straightSegmentOppositeEdge',
straightSegmentOppositeEdge, straightSegmentOppositeEdge,
`angledLineToY({angle=30,to=11.14},%)`, `angledLineToY({angle:30,to:11.14},%)`,
'angledLineToY({ angle = 30, to = 11.14 }, %)' 'angledLineToY({ angle: 30, to: 11.14 }, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentAdjacentEdge', 'straightSegmentAdjacentEdge',
straightSegmentAdjacentEdge, straightSegmentAdjacentEdge,
`angledLineThatIntersects({angle=3.14,intersectTag=a,offset=0},%)`, `angledLineThatIntersects({angle:3.14,intersectTag:a,offset:0},%)`,
'}, %)' '}, %)'
) )
@ -739,17 +720,17 @@ sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
], %, $yo) ], %, $yo)
|> lineTo([profileStartX(%), profileStartY(%)], %, $seg02) |> lineTo([profileStartX(%), profileStartY(%)], %, $seg02)
|> close(%) |> close(%)
extrude001 = extrude(100, sketch001) extrude001 = extrude(100, sketch001)
|> chamfer({ |> chamfer({
length = 30, length: 30,
tags = [ tags: [
seg01, seg01,
getNextAdjacentEdge(yo), getNextAdjacentEdge(yo),
getNextAdjacentEdge(seg02), getNextAdjacentEdge(seg02),
getOppositeEdge(seg01) getOppositeEdge(seg01)
] ]
}, %) }, %)
`) `)
await expect( await expect(
page.getByTestId('model-state-indicator-execution-done') page.getByTestId('model-state-indicator-execution-done')
).toBeVisible() ).toBeVisible()
@ -786,14 +767,14 @@ extrude001 = extrude(100, sketch001)
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'oppositeChamfer', 'oppositeChamfer',
oppositeChamfer, oppositeChamfer,
`angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'baseChamfer', 'baseChamfer',
baseChamfer, baseChamfer,
`angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
@ -824,21 +805,17 @@ extrude001 = extrude(100, sketch001)
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'adjacentChamfer1', 'adjacentChamfer1',
adjacentChamfer1, adjacentChamfer1,
`lineTo([profileStartX(%),profileStartY(%)],%,$seg02)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `lineTo([profileStartX(%),profileStartY(%)],%,$seg02)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'adjacentChamfer2', 'adjacentChamfer2',
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',
@ -855,13 +832,13 @@ extrude001 = extrude(100, sketch001)
|> line([-3.86, -2.73], %) |> line([-3.86, -2.73], %)
|> line([-17.67, 0.85], %) |> line([-17.67, 0.85], %)
|> close(%) |> close(%)
extrude001 = extrude(10, sketch001) 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()
@ -883,13 +860,13 @@ extrude001 = extrude(10, sketch001)
await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled()
const codeToAdd = `${await u.codeLocator.allInnerTexts()} const codeToAdd = `${await u.codeLocator.allInnerTexts()}
sketch002 = startSketchOn(extrude001, $seg01) sketch002 = startSketchOn(extrude001, $seg01)
|> startProfileAt([-12.94, 6.6], %) |> startProfileAt([-12.94, 6.6], %)
|> line([2.45, -0.2], %) |> line([2.45, -0.2], %)
|> line([-2, -1.25], %) |> line([-2, -1.25], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
` `
await u.codeLocator.fill(codeToAdd) await u.codeLocator.fill(codeToAdd)
await selectUnExtrudable() await selectUnExtrudable()
@ -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()
@ -937,7 +912,7 @@ sketch002 = startSketchOn(extrude001, $seg01)
// test fillet button with the body in the scene // test fillet button with the body in the scene
const codeToAdd = `${await u.codeLocator.allInnerTexts()} const codeToAdd = `${await u.codeLocator.allInnerTexts()}
extrude001 = extrude(10, sketch001)` extrude001 = extrude(10, sketch001)`
await u.codeLocator.clear() await u.codeLocator.clear()
await u.codeLocator.fill(codeToAdd) await u.codeLocator.fill(codeToAdd)
await selectSegment() await selectSegment()
@ -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)',
@ -978,7 +949,7 @@ extrude001 = extrude(10, sketch001)`
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
`yo = 79 `yo = 79
part001 = startSketchOn('XZ') part001 = startSketchOn('XZ')
|> startProfileAt([-7.54, -26.74], %) |> startProfileAt([-7.54, -26.74], %)
|> ${cases[0].expectedCode} |> ${cases[0].expectedCode}
|> line([-3.19, -138.43], %) |> line([-3.19, -138.43], %)
@ -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')
@ -1035,14 +1002,14 @@ part001 = startSketchOn('XZ')
|> line([170.36, -121.61], %, $seg01) |> line([170.36, -121.61], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%) |> close(%)
extrude001 = extrude(50, sketch001) 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 })
@ -25,26 +31,41 @@ export function test(desc, objOrFn, fnMaybe) {
// electron tests, never running. We need to call reload() after each call // electron tests, never running. We need to call reload() after each call
// to guarantee it runs. // to guarantee it runs.
const oldContextAddInitScript = tronApp.context.addInitScript const oldContextAddInitScript = tronApp.context.addInitScript
tronApp.context.addInitScript = async function(a, b) { tronApp.context.addInitScript = async function (a, b) {
await oldContextAddInitScript.apply(this, [a, b]) await oldContextAddInitScript.apply(this, [a, b])
await tronApp.page.reload() await tronApp.page.reload()
} }
// No idea why we mix and match page and context's addInitScript but we do // No idea why we mix and match page and context's addInitScript but we do
const oldPageAddInitScript = tronApp.page.addInitScript const oldPageAddInitScript = tronApp.page.addInitScript
tronApp.page.addInitScript = async function(a, b) { tronApp.page.addInitScript = async function (a, b) {
await oldPageAddInitScript.apply(this, [a, b]) await oldPageAddInitScript.apply(this, [a, b])
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