Clean up and working pw test

This commit is contained in:
Pierre Jacquier
2024-12-03 13:49:26 -05:00
parent df3e541cdf
commit 4347e0cf84
4 changed files with 23 additions and 43 deletions

View File

@ -687,18 +687,18 @@ test(`Loft point-and-click`, async ({
cmdBar, cmdBar,
}) => { }) => {
const initialCode = `sketch001 = startSketchOn('XZ') const initialCode = `sketch001 = startSketchOn('XZ')
|> circle({ center = [0, 0], radius = 10 }, %) |> circle({ center = [0, 0], radius = 30 }, %)
plane001 = offsetPlane('XZ', 20) plane001 = offsetPlane('XZ', 50)
sketch002 = startSketchOn(plane001) sketch002 = startSketchOn(plane001)
|> circle({ center = [0, 0], radius = 5 }, %) |> circle({ center = [0, 0], radius = 20 }, %)
` `
await app.initialise(initialCode) await app.initialise(initialCode)
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 575, y: 200 } const testPoint = { x: 575, y: 200 }
const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y) const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const [clickOnSketch2] = scene.makeMouseHelpers(testPoint.x, testPoint.y + 50) const [clickOnSketch2] = scene.makeMouseHelpers(testPoint.x, testPoint.y + 80)
const expectedOutput = `${initialCode}loft001 = loft([sketch001, sketch002])` const loftDeclaration = 'loft001 = loft([sketch001, sketch002])'
await test.step(`Look for the white of the sketch001 shape`, async () => { await test.step(`Look for the white of the sketch001 shape`, async () => {
await scene.expectPixelColor([254, 254, 254], testPoint, 15) await scene.expectPixelColor([254, 254, 254], testPoint, 15)
@ -716,6 +716,8 @@ sketch002 = startSketchOn(plane001)
await clickOnSketch1() await clickOnSketch1()
await page.keyboard.down('Shift') await page.keyboard.down('Shift')
await clickOnSketch2() await clickOnSketch2()
await app.page.waitForTimeout(500)
await page.keyboard.up('Shift')
await cmdBar.progressCmdBar() await cmdBar.progressCmdBar()
await cmdBar.expectState({ await cmdBar.expectState({
stage: 'review', stage: 'review',
@ -726,12 +728,12 @@ sketch002 = startSketchOn(plane001)
}) })
await test.step(`Confirm code is added to the editor, scene has changed`, async () => { await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await editor.expectEditor.toContain(expectedOutput) await editor.expectEditor.toContain(loftDeclaration)
await editor.expectState({ await editor.expectState({
diagnostics: [], diagnostics: [],
activeLines: [expectedOutput], activeLines: [loftDeclaration],
highlightedCode: '', highlightedCode: '',
}) })
await scene.expectPixelColor([74, 74, 74], testPoint, 15) await scene.expectPixelColor([109, 109, 109], testPoint, 15)
}) })
}) })

View File

@ -577,10 +577,6 @@ export const ModelingMachineProvider = ({
isSelectionLastLine(selectionRanges, codeManager.code) isSelectionLastLine(selectionRanges, codeManager.code)
if (hasNoSelection) { if (hasNoSelection) {
// TODO: can't select more than one face now if not done prior
// they have no selection, we should enable the button
// so they can select the faces through the cmdbar
// BUT only if there's two extrudable geometry
const count = 2 const count = 2
return doesSceneHaveSweepableSketch(kclManager.ast, count) return doesSceneHaveSweepableSketch(kclManager.ast, count)
} }

View File

@ -355,23 +355,20 @@ export function loftSketches(
pathToLoftArg: PathToNode pathToLoftArg: PathToNode
} }
| Error { | Error {
const _node = structuredClone(node) const modifiedAst = structuredClone(node)
const variableDeclarators = [] const variableDeclarators = []
const pathsToDeclaration = []
for (const path of nodePaths) { for (const path of nodePaths) {
const node = getNodeFromPath<VariableDeclarator>( const nodeFromPath = getNodeFromPath<VariableDeclarator>(
_node, modifiedAst,
path, path,
'VariableDeclarator' 'VariableDeclarator'
) )
if (err(node)) {
return node if (err(nodeFromPath)) {
return nodeFromPath
} }
const { node: variableDeclarator, shallowPath: pathToDecleration } = node variableDeclarators.push(nodeFromPath.node)
variableDeclarators.push(variableDeclarator)
pathsToDeclaration.push(pathToDecleration)
} }
const identifiers = createArrayExpression( const identifiers = createArrayExpression(
@ -379,32 +376,20 @@ export function loftSketches(
) )
const loftCall = createCallExpressionStdLib('loft', [identifiers]) const loftCall = createCallExpressionStdLib('loft', [identifiers])
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.LOFT) const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.LOFT)
const VariableDeclaration = createVariableDeclaration(name, loftCall) const loftDeclaration = createVariableDeclaration(name, loftCall)
modifiedAst.body.push(loftDeclaration)
const sketchIndexInPathToNode = (path: PathToNode) =>
path.findIndex((a) => a[0] === 'body') + 1
pathsToDeclaration.sort(
(a, b) =>
(a[sketchIndexInPathToNode(a)][0] as number) -
(b[sketchIndexInPathToNode(b)][0] as number)
)
const lastPath = pathsToDeclaration[pathsToDeclaration.length - 1]
const sketchIndexInBody = lastPath[
sketchIndexInPathToNode(lastPath)
][0] as number
_node.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration)
const pathToLoftArg: PathToNode = [ const pathToLoftArg: PathToNode = [
['body', ''], ['body', ''],
[sketchIndexInBody + 1, 'index'], [modifiedAst.body.length - 1, 'index'],
['declarations', 'VariableDeclaration'], ['declarations', 'VariableDeclaration'],
[0, 'index'], ['0', 'index'],
['init', 'VariableDeclarator'], ['init', 'VariableDeclarator'],
['arguments', 'CallExpression'], ['arguments', 'CallExpression'],
[0, 'index'], [0, 'index'],
] ]
return { return {
modifiedAst: _node, modifiedAst,
pathToLoftArg, pathToLoftArg,
} }
} }

View File

@ -564,12 +564,9 @@ export function canSweepSelection(selection: Selections) {
} }
export function canLoftSelection(selection: Selections) { export function canLoftSelection(selection: Selections) {
console.log('selection', selection)
const commonNodes = selection.graphSelections.map((_, i) => const commonNodes = selection.graphSelections.map((_, i) =>
buildCommonNodeFromSelection(selection, i) buildCommonNodeFromSelection(selection, i)
) )
console.log('commonNodes', commonNodes)
console.log('isSketchPipe', isSketchPipe(selection))
return ( return (
!!isCursorInSketchCommandRange( !!isCursorInSketchCommandRange(
engineCommandManager.artifactGraph, engineCommandManager.artifactGraph,