Fix a ton of syntax changes and deflake 2 more tests (pain)

This commit is contained in:
49lf
2024-12-03 20:03:54 -05:00
parent d9c081611f
commit 449cbb868f
8 changed files with 164 additions and 117 deletions

View File

@ -92,6 +92,9 @@ export class AuthenticatedTronApp {
this.electronApp = electronApp
this.dir = dir
// Easier to access throughout utils
this.page.dir = dir
// Setup localStorage, addCookies, reload
await setup(this.context, this.page, this.testInfo)

View File

@ -3,10 +3,10 @@
// It also tests our test wrappers are working.
// Additionally this serves as a nice minimal example.
import { test as testZoo, expect } from './fixtures/fixtureSetup'
import { test, expect } from './zoo-test'
testZoo.describe('Open the application', () => {
testZoo('see the project view', async ({ tronApp: { page, context } }) => {
test.describe('Open the application', () => {
test('see the project view', async ({ page, context }) => {
await expect(page.getByTestId('home-section')).toBeVisible()
})
})

View File

@ -4,6 +4,7 @@ import { SceneFixture } from './fixtures/sceneFixture'
import { ToolbarFixture } from './fixtures/toolbarFixture'
import fs from 'node:fs/promises'
import path from 'node:path'
import { getUtils } from './test-utils'
// test file is for testing point an click code gen functionality that's not sketch mode related
@ -38,7 +39,7 @@ test('verify extruding circle works', async ({
await test.step('check code model connection works and that button is still enable once circle is selected ', async () => {
await moveToCircle()
const circleSnippet =
'circle({ center: [318.33, 168.1], radius: 182.8 }, %)'
'circle({ center = [318.33, 168.1], radius = 182.8 }, %)'
await editor.expectState({
activeLines: ["constsketch002=startSketchOn('XZ')"],
highlightedCode: circleSnippet,
@ -213,7 +214,7 @@ test.describe('verify sketch on chamfer works', () => {
]}, %)`,
afterChamferSelectSnippet: 'sketch002 = startSketchOn(extrude001, seg03)',
afterRectangle1stClickSnippet: 'startProfileAt([160.39, 254.59], %)',
afterRectangle1stClickSnippet: 'startProfileAt([205.96, 254.59], %)',
afterRectangle2ndClickSnippet: `angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([
segAng(rectangleSegmentA002) - 90,
@ -244,7 +245,7 @@ test.describe('verify sketch on chamfer works', () => {
}, %)`,
afterChamferSelectSnippet: 'sketch003 = startSketchOn(extrude001, seg04)',
afterRectangle1stClickSnippet: 'startProfileAt([-255.89, 255.28], %)',
afterRectangle1stClickSnippet: 'startProfileAt([-209.64, 255.28], %)',
afterRectangle2ndClickSnippet: `angledLine([0, 11.56], %, $rectangleSegmentA003)
|> angledLine([
segAng(rectangleSegmentA003) - 90,
@ -269,7 +270,7 @@ test.describe('verify sketch on chamfer works', () => {
]
}, %)`,
afterChamferSelectSnippet: 'sketch003 = startSketchOn(extrude001, seg04)',
afterRectangle1stClickSnippet: 'startProfileAt([37.95, 322.96], %)',
afterRectangle1stClickSnippet: 'startProfileAt([75.8, 317.2], %)',
afterRectangle2ndClickSnippet: `angledLine([0, 11.56], %, $rectangleSegmentA003)
|> angledLine([
segAng(rectangleSegmentA003) - 90,
@ -292,7 +293,7 @@ test.describe('verify sketch on chamfer works', () => {
tags = [getNextAdjacentEdge(yo)]
}, %)`,
afterChamferSelectSnippet: 'sketch005 = startSketchOn(extrude001, seg06)',
afterRectangle1stClickSnippet: 'startProfileAt([-59.83, 19.69], %)',
afterRectangle1stClickSnippet: 'startProfileAt([-23.43, 19.69], %)',
afterRectangle2ndClickSnippet: `angledLine([0, 9.1], %, $rectangleSegmentA005)
|> angledLine([
@ -338,7 +339,7 @@ test.describe('verify sketch on chamfer works', () => {
tags = [getNextAdjacentEdge(yo)]
}, %, $seg06)
sketch005 = startSketchOn(extrude001, seg06)
|> startProfileAt([-59.83,19.69], %)
|> startProfileAt([-23.43,19.69], %)
|> angledLine([0, 9.1], %, $rectangleSegmentA005)
|> angledLine([
segAng(rectangleSegmentA005) - 90,
@ -351,7 +352,7 @@ test.describe('verify sketch on chamfer works', () => {
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
sketch004 = startSketchOn(extrude001, seg05)
|> startProfileAt([37.95,322.96], %)
|> startProfileAt([82.57,322.96], %)
|> angledLine([0, 11.16], %, $rectangleSegmentA004)
|> angledLine([
segAng(rectangleSegmentA004) - 90,
@ -364,7 +365,7 @@ test.describe('verify sketch on chamfer works', () => {
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
sketch003 = startSketchOn(extrude001, seg04)
|> startProfileAt([-255.89,255.28], %)
|> startProfileAt([-209.64,255.28], %)
|> angledLine([0, 11.56], %, $rectangleSegmentA003)
|> angledLine([
segAng(rectangleSegmentA003) - 90,
@ -377,7 +378,7 @@ test.describe('verify sketch on chamfer works', () => {
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
sketch002 = startSketchOn(extrude001, seg03)
|> startProfileAt([160.39,254.59], %)
|> startProfileAt([205.96,254.59], %)
|> angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([
segAng(rectangleSegmentA002) - 90,
@ -417,6 +418,8 @@ test.describe('verify sketch on chamfer works', () => {
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
const sketchOnAChamfer = _sketchOnAChamfer(page, editor, toolbar, scene)
await sketchOnAChamfer({
clickCoords: { x: 570, y: 220 },
cameraPos: { x: 16020, y: -2000, z: 10500 },
@ -430,7 +433,7 @@ test.describe('verify sketch on chamfer works', () => {
]}, extrude001)`,
beforeChamferSnippetEnd: '}, extrude001)',
afterChamferSelectSnippet: 'sketch002 = startSketchOn(extrude001, seg03)',
afterRectangle1stClickSnippet: 'startProfileAt([160.39, 254.59], %)',
afterRectangle1stClickSnippet: 'startProfileAt([205.96, 254.59], %)',
afterRectangle2ndClickSnippet: `angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([
segAng(rectangleSegmentA002) - 90,
@ -471,7 +474,7 @@ chamf = chamfer({
]
}, %)
sketch002 = startSketchOn(extrude001, seg03)
|> startProfileAt([160.39, 254.59], %)
|> startProfileAt([205.96, 254.59], %)
|> angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([
segAng(rectangleSegmentA002) - 90,
@ -595,11 +598,15 @@ test(`Verify axis, origin, and horizontal snapping`, async ({
})
test(`Verify user can double-click to edit a sketch`, async ({
app,
context,
page,
homePage,
editor,
toolbar,
scene,
}) => {
const u = await getUtils(page)
const initialCode = `closedSketch = startSketchOn('XZ')
|> circle({ center = [8, 5], radius = 2 }, %)
openSketch = startSketchOn('XY')
@ -608,15 +615,30 @@ openSketch = startSketchOn('XY')
|> xLine(5, %)
|> tangentialArcTo([10, 0], %)
`
await app.initialise(initialCode)
const viewPortSize = { width: 1200, height: 500 }
await page.setBodyDimensions(viewPortSize)
await context.addInitScript((code) => {
localStorage.setItem('persistCode', code)
}, initialCode)
await homePage.goToModelingScene()
await u.waitForPageLoad()
await page.waitForTimeout(1000)
const pointOnSketchArea = {
x: viewPortSize.width * 0.7,
y: viewPortSize.height * 0.7,
}
const pointInsideCircle = {
x: app.viewPortSize.width * 0.63,
y: app.viewPortSize.height * 0.5,
x: viewPortSize.width * 0.55,
y: viewPortSize.height * 0.5,
}
const pointOnPathAfterSketching = {
x: app.viewPortSize.width * 0.58,
y: app.viewPortSize.height * 0.5,
x: viewPortSize.width * 0.65,
y: viewPortSize.height * 0.5,
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_clickOpenPath, moveToOpenPath, dblClickOpenPath] =
@ -649,41 +671,54 @@ openSketch = startSketchOn('XY')
diagnostics: [],
})
})
await page.waitForTimeout(1000)
await exitSketch()
await page.waitForTimeout(1000)
// Drag the sketch line out of the axis view which blocks the click
await page.dragAndDrop('#stream', '#stream', {
sourcePosition: { x: viewPortSize.width * 0.7, y: viewPortSize.height* 0.5 },
targetPosition: { x: viewPortSize.width * 0.7, y: viewPortSize.height* 0.4 },
})
await page.waitForTimeout(500)
await test.step(`Double-click on the open sketch`, async () => {
await moveToOpenPath()
await scene.expectPixelColor([250, 250, 250], pointOnPathAfterSketching, 15)
// There is a full execution after exiting sketch that clears the scene.
await app.page.waitForTimeout(500)
await page.waitForTimeout(500)
await dblClickOpenPath()
await expect(toolbar.startSketchBtn).not.toBeVisible()
await expect(toolbar.exitSketchBtn).toBeVisible()
// Wait for enter sketch mode to complete
await app.page.waitForTimeout(500)
await page.waitForTimeout(500)
await editor.expectState({
activeLines: [`|>xLine(5,%)`],
highlightedCode: 'xLine(5,%)',
activeLines: [`|>tangentialArcTo([10,0],%)`],
highlightedCode: 'tangentialArcTo([10,0],%)',
diagnostics: [],
})
})
})
test(`Offset plane point-and-click`, async ({
app,
context,
page,
homePage,
scene,
editor,
toolbar,
cmdBar,
}) => {
await app.initialise()
// One dumb hardcoded screen pixel value
const testPoint = { x: 700, y: 150 }
const [clickOnXzPlane] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const expectedOutput = `plane001 = offsetPlane('XZ', 5)`
await homePage.goToModelingScene()
await test.step(`Look for the blue of the XZ plane`, async () => {
await scene.expectPixelColor([50, 51, 96], testPoint, 15)
})

View File

@ -7,8 +7,6 @@ import {
getMovementUtils,
getUtils,
PERSIST_MODELING_CONTEXT,
setup,
tearDown,
} from './test-utils'
import { uuidv4, roundOff } from 'lib/utils'
@ -40,9 +38,9 @@ test.describe('Sketch tests', () => {
screwHole = startSketchOn('XY')
${startProfileAt1}
|> arc({
radius: screwRadius,
angle_start: 0,
angle_end: 360
radius = screwRadius,
angle_start = 0,
angle_end = 360
}, %)
part001 = startSketchOn('XY')
@ -61,9 +59,9 @@ test.describe('Sketch tests', () => {
|> xLine(-width / 4 + wireRadius, %)
|> yLine(wireOffset, %)
|> arc({
radius: wireRadius,
angle_start: 0,
angle_end: 180
radius = wireRadius,
angle_start = 0,
angle_end = 180
}, %)
|> yLine(-wireOffset, %)
|> xLine(-width / 4, %)
@ -347,6 +345,7 @@ test.describe('Sketch tests', () => {
test('Can edit a circle center and radius by dragging its handles', async ({
page,
editor,
homePage,
}) => {
const u = await getUtils(page)
@ -354,7 +353,7 @@ test.describe('Sketch tests', () => {
localStorage.setItem(
'persistCode',
`sketch001 = startSketchOn('XZ')
|> circle({ center: [4.61, -5.01], radius: 8 }, %)`
|> circle({ center = [4.61, -5.01], radius = 8 }, %)`
)
})
@ -398,6 +397,7 @@ test.describe('Sketch tests', () => {
).toBeVisible()
await page.getByRole('button', { name: 'Edit Sketch' }).click()
await page.waitForTimeout(400)
let prevContent = await page.locator('.cm-content').innerText()
await expect(page.getByTestId('segment-overlay')).toHaveCount(1)
@ -408,7 +408,9 @@ test.describe('Sketch tests', () => {
targetPosition: { x: startPX[0] + dragPX, y: startPX[1] - dragPX },
})
await page.waitForTimeout(100)
await expect(page.locator('.cm-content')).not.toHaveText(prevContent)
await editor.expectEditor.not.toContain(prevContent)
prevContent = await page.locator('.cm-content').innerText()
})
@ -421,15 +423,13 @@ test.describe('Sketch tests', () => {
sourcePosition: { x: lineEnd.x - 5, y: lineEnd.y },
targetPosition: { x: lineEnd.x + dragPX * 2, y: lineEnd.y + dragPX },
})
await expect(page.locator('.cm-content')).not.toHaveText(prevContent)
await editor.expectEditor.not.toContain(prevContent)
prevContent = await page.locator('.cm-content').innerText()
})
// expect the code to have changed
await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ')
|> circle({ center: [7.26, -2.37], radius: 11.44 }, %)
`)
await editor.expectEditor.toContain(`sketch001 = startSketchOn('XZ')
|> circle({ center = [7.26, -2.37], radius = 11.44 }, %)`, { shouldNormalise: true })
})
test('Can edit a sketch that has been extruded in the same pipe', async ({
page,
@ -547,7 +547,7 @@ test.describe('Sketch tests', () => {
|> line([12.73, -0.09], %)
|> tangentialArcTo([24.95, -5.38], %)
|> close(%)
|> revolve({ axis: "X",}, %)`
|> revolve({ axis = "X",}, %)`
)
})
@ -633,7 +633,7 @@ test.describe('Sketch tests', () => {
|> tangentialArcTo([24.95, -5.38], %)
|> line([1.97, 2.06], %)
|> close(%)
|> revolve({ axis: "X" }, %)`)
|> revolve({ axis = "X" }, %)`)
})
test('Can add multiple sketches', async ({ page, homePage }) => {
const u = await getUtils(page)
@ -1064,11 +1064,11 @@ test.describe('Sketch tests', () => {
fn lug = (origin, length, diameter, plane) => {
lugSketch = startSketchOn(plane)
|> startProfileAt([origin[0] + lugDiameter / 2, origin[1]], %)
|> angledLineOfYLength({ angle: 60, length: lugHeadLength }, %)
|> angledLineOfYLength({ angle = 60, length = lugHeadLength }, %)
|> xLineTo(0 + .001, %)
|> yLineTo(0, %)
|> close(%)
|> revolve({ axis: "Y" }, %)
|> revolve({ axis = "Y" }, %)
return lugSketch
}

View File

@ -707,13 +707,13 @@ export const makeTemplate: (
const PLAYWRIGHT_DOWNLOAD_DIR = 'downloads-during-playwright'
export const getPlaywrightDownloadDir = (page: Page) => {
return path.resolve(page.TEST_SETTINGS_FILE_KEY, PLAYWRIGHT_DOWNLOAD_DIR)
return path.resolve(page.dir, PLAYWRIGHT_DOWNLOAD_DIR)
}
const moveDownloadedFileTo = async (page: Page, toLocation: string) => {
await fsp.mkdir(path.dirname(toLocation), { recursive: true })
const downloadDir = getPlaywrightDownloadDir()
const downloadDir = getPlaywrightDownloadDir(page)
// Expect there to be at least one file
expect

View File

@ -306,20 +306,20 @@ test.describe('Testing selections', () => {
|> line([thickness, 0], %)
|> line([0, -1], %)
|> angledLineToX({
angle: 60,
to: pipeSmallDia + thickness
angle = 60,
to = pipeSmallDia + thickness
}, %)
|> line([0, -pipeLength], %)
|> angledLineToX({
angle: -60,
to: pipeLargeDia + thickness
angle = -60,
to = pipeLargeDia + thickness
}, %)
|> line([0, -1], %)
|> line([-thickness, 0], %)
|> line([0, 1], %)
|> angledLineToX({ angle: 120, to: pipeSmallDia }, %)
|> angledLineToX({ angle = 120, to = pipeSmallDia }, %)
|> line([0, pipeLength], %)
|> angledLineToX({ angle: 60, to: pipeLargeDia }, %)
|> angledLineToX({ angle = 60, to = pipeLargeDia }, %)
|> close(%)
rev = revolve({ axis: 'y' }, part009)
`
@ -387,27 +387,27 @@ test.describe('Testing selections', () => {
`extrude001 = extrude(50, sketch001)`
)
await expect(u.codeLocator).toContainText(`sketch005 = startSketchOn({
plane: {
origin: { x: 0, y: -50, z: 0 },
x_axis: { x: 1, y: 0, z: 0 },
y_axis: { x: 0, y: 0, z: 1 },
z_axis: { x: 0, y: -1, z: 0 }
plane = {
origin = { x = 0, y = -50, z = 0 },
x_axis = { x = 1, y = 0, z = 0 },
y_axis = { x = 0, y = 0, z = 1 },
z_axis = { x = 0, y = -1, z = 0 }
}
})`)
await expect(u.codeLocator).toContainText(`sketch003 = startSketchOn({
plane: {
origin: { x: 116.53, y: 0, z: 163.25 },
x_axis: { x: -0.81, y: 0, z: 0.58 },
y_axis: { x: 0, y: -1, z: 0 },
z_axis: { x: 0.58, y: 0, z: 0.81 }
plane = {
origin = { x = 116.53, y = 0, z = 163.25 },
x_axis = { x = -0.81, y = 0, z = 0.58 },
y_axis = { x = 0, y = -1, z = 0 },
z_axis = { x = 0.58, y = 0, z = 0.81 }
}
})`)
await expect(u.codeLocator).toContainText(`sketch002 = startSketchOn({
plane: {
origin: { x: -91.74, y: 0, z: 80.89 },
x_axis: { x: -0.66, y: 0, z: -0.75 },
y_axis: { x: 0, y: -1, z: 0 },
z_axis: { x: -0.75, y: 0, z: 0.66 }
plane = {
origin = { x = -91.74, y = 0, z = 80.89 },
x_axis = { x = -0.66, y = 0, z = -0.75 },
y_axis = { x = 0, y = -1, z = 0 },
z_axis = { x = -0.75, y = 0, z = 0.66 }
}
})`)
@ -499,19 +499,19 @@ test.describe('Testing selections', () => {
`part001 = startSketchOn('XZ')
|> startProfileAt([20, 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], %)
|> xLineTo(29 + 0, %)
|> yLine(-3.14 + 0, %, $a)
|> xLine(1.63, %)
|> angledLineOfXLength({ angle: 3 + 0, length: 3.14 }, %)
|> angledLineOfYLength({ angle: 30, length: 3 + 0 }, %)
|> angledLineToX({ angle: 22.14 + 0, to: 12 }, %)
|> angledLineToY({ angle: 30, to: 11.14 }, %)
|> angledLineOfXLength({ angle = 3 + 0, length = 3.14 }, %)
|> angledLineOfYLength({ angle = 30, length = 3 + 0 }, %)
|> angledLineToX({ angle = 22.14 + 0, to = 12 }, %)
|> angledLineToY({ angle = 30, to = 11.14 }, %)
|> angledLineThatIntersects({
angle: 3.14,
intersectTag: a,
offset: 0
angle = 3.14,
intersectTag = a,
offset = 0
}, %)
|> tangentialArcTo([13.14 + 0, 13.14], %)
|> close(%)
@ -735,8 +735,8 @@ test.describe('Testing selections', () => {
|> close(%)
extrude001 = extrude(100, sketch001)
|> chamfer({
length: 30,
tags: [
length = 30,
tags = [
seg01,
getNextAdjacentEdge(yo),
getNextAdjacentEdge(seg02),
@ -831,9 +831,11 @@ test.describe('Testing selections', () => {
})
test("Extrude button should be disabled if there's no extrudable geometry when nothing is selected", async ({
page,
editor,
homePage,
}) => {
const u = await getUtils(page)
await page.addInitScript(async () => {
localStorage.setItem(
'persistCode',
@ -854,17 +856,20 @@ test.describe('Testing selections', () => {
`
)
})
await page.setBodyDimensions({ width: 1000, height: 500 })
await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene()
await u.waitForPageLoad()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
const selectUnExtrudable = () =>
page.getByText(`line([4.99, -0.46], %, $seg01)`).click()
const selectUnExtrudable = async () => {
await editor.scrollToText(`line([4.99, -0.46], %, $seg01)`)
await page.getByText(`line([4.99, -0.46], %, $seg01)`).click()
}
const clickEmpty = () => page.mouse.click(700, 460)
await selectUnExtrudable()
// expect extrude button to be disabled
@ -874,6 +879,7 @@ test.describe('Testing selections', () => {
// expect active line to contain nothing
await expect(page.locator('.cm-activeLine')).toHaveText('')
// and extrude to still be disabled
await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled()

View File

@ -53,27 +53,27 @@ part001 = startSketchOn('-XZ')
|> yLine(baseHeight, %)
|> xLine(baseLen, %)
|> angledLineToY({
angle: topAng,
to: totalHeightHalf,
angle = topAng,
to = totalHeightHalf,
}, %, $seg04)
|> xLineTo(totalLen, %, $seg03)
|> yLine(-armThick, %, $seg01)
|> angledLineThatIntersects({
angle: HALF_TURN,
offset: -armThick,
intersectTag: seg04
angle = HALF_TURN,
offset = -armThick,
intersectTag = seg04
}, %)
|> angledLineToY([segAng(seg04) + 180, ZERO], %)
|> angledLineToY({
angle: -bottomAng,
to: -totalHeightHalf - armThick,
angle = -bottomAng,
to = -totalHeightHalf - armThick,
}, %, $seg02)
|> xLineTo(segEndX(seg03) + 0, %)
|> yLine(-segLen(seg01), %)
|> angledLineThatIntersects({
angle: HALF_TURN,
offset: -armThick,
intersectTag: seg02
angle = HALF_TURN,
offset = -armThick,
intersectTag = seg02
}, %)
|> angledLineToY([segAng(seg02) + 180, -baseHeight], %)
|> xLineTo(ZERO, %)

View File

@ -61,7 +61,6 @@ export function test(desc, objOrFn, fnMaybe) {
await tronApp.page.reload()
}
if (tronApp instanceof AuthenticatedTronApp) {
// Create a consistent way to resize the page across electron and web.
// (lee) I had to do everyhting in the book to make electron change its
// damn window size. I succeded in making it consistently and reliably
@ -70,11 +69,16 @@ export function test(desc, objOrFn, fnMaybe) {
width: number
height: number
}) {
await tronApp.page.setViewportSize(dims)
if (!(tronApp instanceof AuthenticatedTronApp)) {
return
}
await tronApp.electronApp.evaluateHandle(async ({ app }, dims) => {
await app.resizeWindow(dims.width, dims.height)
}, dims)
await tronApp.page.setViewportSize(dims)
return tronApp.page.evaluate(async (dims) => {
await window.electron.resizeWindow(dims.width, dims.height)
window.document.body.style.width = dims.width + 'px'
@ -90,7 +94,6 @@ export function test(desc, objOrFn, fnMaybe) {
tronApp.context.folderSetupFn = function (fn) {
return fn(tronApp.dir).then(() => ({ dir: tronApp.dir }))
}
}
await fn(
{