Compare commits

...

2 Commits

Author SHA1 Message Date
148a682822 Fix flakiness in for segments tests 2024-06-03 17:25:35 -04:00
cf9123617b Fix tests unrelated to this PR 2024-06-03 17:24:04 -04:00
2 changed files with 279 additions and 199 deletions

View File

@ -27,6 +27,8 @@ document.addEventListener('mousemove', (e) =>
)
*/
const deg = Math.PI*2 / 360
const commonPoints = {
startAt: '[9.06, -12.22]',
num1: 9.14,
@ -35,6 +37,55 @@ const commonPoints = {
// num2: 19.19,
}
// Utilities for writing tests that depend on test values
const getTools = (opts) => {
// The way we truncate is kinda odd apparently, so we need this function
// "[k]itty[c]ad round"
const kcRound = (n) => Math.trunc(n * 100) / 100
// To translate between screen and engine ("[U]nit") coordinates
// NOTE: these pretty much can't be perfect because of screen scaling.
// Handle on a case-by-case.
const toU = (x, y) => [
kcRound( x*0.0854),
kcRound(-y*0.0854), // Y is inverted in our coordinate system
];
// Turn the array into a string with specific formatting
const fromUToString = (xy) => `[${xy[0]}, ${xy[1]}]`
// Combine because used often
const toSU = (xy) => fromUToString(toU(xy[0], xy[1]))
// Make it easier to click around from center ("click [from] zero zero")
const click00 = (x, y) => opts.page.mouse.click(opts.center.x + x, opts.center.y + y)
// Relative clicker, must keep state
let last = { x: 0, y: 0 };
const click00r = (x, y) => {
// reset relative coordinates when anything is undefined
if (x === undefined || y === undefined) {
last.x = 0
last.y = 0
return
}
const ret = click00(last.x + x, last.y + y)
last.x += x
last.y += y
// Returns the new absolute coordinate if you need it.
return ret.then(() => [last.x, last.y])
}
const expectCodeToBe = async (str) => {
await expect(opts.page.locator('.cm-content')).toHaveText(str)
await opts.page.waitForTimeout(100)
}
return { toSU, click00r, expectCodeToBe }
}
test.beforeEach(async ({ context, page }) => {
// wait for Vite preview server to be up
await waitOn({
@ -1484,12 +1535,15 @@ const part001 = startSketchOn('XZ')
test('Can add multiple sketches', async ({ page }) => {
test.skip(process.platform === 'darwin', 'Can add multiple sketches')
const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio
const viewportSize = { width: 1200, height: 500, };
await page.setViewportSize(viewportSize)
await page.goto('/')
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
const center = { x: viewportSize.width / 2, y: viewportSize.height / 2 };
const { toSU, click00r, expectCodeToBe } = getTools({ center, page });
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled()
@ -1502,127 +1556,71 @@ test('Can add multiple sketches', async ({ page }) => {
200
)
// select a plane
await page.mouse.click(700, 200)
await expect(page.locator('.cm-content')).toHaveText(
`const part001 = startSketchOn('XZ')`
)
let codeStr = "const part001 = startSketchOn('XY')";
await page.mouse.click(center.x, viewportSize.height * 0.55)
await expectCodeToBe(codeStr)
await u.closeDebugPanel()
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
const startXPx = 600
await u.closeDebugPanel()
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)`)
await page.waitForTimeout(100)
await click00r(0, 0)
codeStr += ` |> startProfileAt(${toSU([0, 0])}, %)`
await expectCodeToBe(codeStr)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)
await click00r(50, 0)
codeStr += ` |> line(${toSU([50, 0])}, %)`;
await expectCodeToBe(codeStr)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)`)
await click00r(0, 50)
codeStr += ` |> line(${toSU([0, 50])}, %)`;
await expectCodeToBe(codeStr)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect(page.locator('.cm-content'))
.toHaveText(`const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)
|> line([0, ${commonPoints.num1}], %)`)
await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20)
const finalCodeFirstSketch = `const part001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> line([${commonPoints.num1}, 0], %)
|> line([0, ${commonPoints.num1}], %)
|> line([-${commonPoints.num2}, 0], %)`
await expect(page.locator('.cm-content')).toHaveText(finalCodeFirstSketch)
// exit the sketch
await click00r(-50, 0)
codeStr += ` |> line(${toSU([-50, 0])}, %)`;
await expectCodeToBe(codeStr)
// exit the sketch, reset relative clicker
click00r(undefined, undefined)
await u.openAndClearDebugPanel()
await page.getByRole('button', { name: 'Exit Sketch' }).click()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.updateCamPosition([100, 100, 100])
await page.waitForTimeout(250)
await u.clearCommandLogs()
// start a new sketch
await u.clearCommandLogs()
await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(400)
await page.mouse.click(650, 450)
// when exiting the sketch above the camera is still looking down at XY,
// so selecting the plane again is a bit easier.
await page.mouse.click(center.x + 30, center.y)
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
await u.clearAndCloseDebugPanel()
// on mock os there are issues with getting the camera to update
// it should not be selecting the 'XZ' plane here if the camera updated
// properly, but if we just role with it we can still verify everything
// in the rest of the test
const plane = process.platform === 'darwin' ? 'XZ' : 'XY'
await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
const startAt2 =
process.platform === 'darwin' ? '[9.75, -13.16]' : '[0.93, -1.25]'
await expect(
(await page.locator('.cm-content').innerText()).replace(/\s/g, '')
).toBe(
`${finalCodeFirstSketch}
const part002 = startSketchOn('${plane}')
|> startProfileAt(${startAt2}, %)`.replace(/\s/g, '')
)
await page.waitForTimeout(100)
codeStr += "const part002 = startSketchOn('XY')";
await expectCodeToBe(codeStr)
await u.closeDebugPanel()
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)
const num2 = process.platform === 'darwin' ? 9.84 : 0.94
await expect(
(await page.locator('.cm-content').innerText()).replace(/\s/g, '')
).toBe(
`${finalCodeFirstSketch}
const part002 = startSketchOn('${plane}')
|> startProfileAt(${startAt2}, %)
|> line([${num2}, 0], %)`.replace(/\s/g, '')
)
await click00r(30, 0)
codeStr += ` |> startProfileAt(${toSU([30, 0])}, %)`
await expectCodeToBe(codeStr)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect(
(await page.locator('.cm-content').innerText()).replace(/\s/g, '')
).toBe(
`${finalCodeFirstSketch}
const part002 = startSketchOn('${plane}')
|> startProfileAt(${startAt2}, %)
|> line([${num2}, 0], %)
|> line([0, ${roundOff(
num2 + (process.platform === 'darwin' ? 0.01 : -0.01)
)}], %)`.replace(/\s/g, '')
)
await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20)
await expect(
(await page.locator('.cm-content').innerText()).replace(/\s/g, '')
).toBe(
`${finalCodeFirstSketch}
const part002 = startSketchOn('${plane}')
|> startProfileAt(${startAt2}, %)
|> line([${num2}, 0], %)
|> line([0, ${roundOff(
num2 + (process.platform === 'darwin' ? 0.01 : -0.01)
)}], %)
|> line([-${process.platform === 'darwin' ? 19.59 : 1.87}, 0], %)`.replace(
/\s/g,
''
)
)
await click00r(30, 0)
codeStr += ` |> line(${toSU([30 - 0.1 /* imprecision */, 0])}, %)`;
await expectCodeToBe(codeStr)
await click00r(0, 30)
codeStr += ` |> line(${toSU([0, 30])}, %)`;
await expectCodeToBe(codeStr)
await click00r(-30, 0)
codeStr += ` |> line(${toSU([-30 + 0.1, 0])}, %)`;
await expectCodeToBe(codeStr)
click00r(undefined, undefined)
await u.openAndClearDebugPanel()
await page.getByRole('button', { name: 'Exit Sketch' }).click()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.updateCamPosition([100, 100, 100])
await page.waitForTimeout(250)
await u.clearCommandLogs()
})
test('ProgramMemory can be serialised', async ({ page }) => {
@ -2439,6 +2437,7 @@ test('Extrude from command bar selects extrude line after', async ({
)
})
<<<<<<< HEAD
test.describe('Testing constraints', () => {
test(`Test remove constraints`, async ({ page }) => {
await page.addInitScript(async () => {
@ -3226,6 +3225,27 @@ const part002 = startSketchOn('XZ')
})
})
const wiggleMove = async (page, x, y, steps, dist, ang, amplitude, freq) => {
const tau = Math.PI*2
const deg = tau / 360
const step = dist / steps;
for (let i = 0, j = 0; i < dist; i += step, j += 1) {
const [x1, y1] = [
0,
Math.sin(tau / steps * j * freq) * amplitude,
]
const [x2, y2] = [
Math.cos(-ang*deg)*i - Math.sin(-ang*deg)*y1,
Math.sin(-ang*deg)*i + Math.cos(-ang*deg)*y1,
]
const [xr, yr] = [
x2,
y2
]
await page.mouse.move(x + xr, y + yr, { steps: 2 })
}
}
test.describe('Testing segment overlays', () => {
test.describe('Hover over a segment should show its overlay, hovering over the input overlays should show its popover, clicking the input overlay should constrain/unconstrain it:\nfor the following segments', () => {
/**
@ -3246,7 +3266,7 @@ test.describe('Testing segment overlays', () => {
expectAfterUnconstrained,
expectFinal,
ang = 45,
steps = 6,
steps = 10,
}: {
hoverPos: { x: number; y: number }
constraintType:
@ -3261,13 +3281,15 @@ test.describe('Testing segment overlays', () => {
steps?: number
}) => {
await expect(page.getByText('Added variable')).not.toBeVisible()
const [x, y] = [
Math.cos((ang * Math.PI) / 180) * 45,
Math.sin((ang * Math.PI) / 180) * 45,
]
await page.mouse.move(hoverPos.x + x, hoverPos.y + y)
await page.mouse.move(hoverPos.x, hoverPos.y, { steps })
await page.mouse.move(0, 0)
await page.waitForTimeout(1000)
let x = 0, y = 0
x = hoverPos.x + Math.cos(ang*deg)*32
y = hoverPos.y - Math.sin(ang*deg)*32
await page.mouse.move(x, y)
await wiggleMove(page, x, y, 20, 30, ang, 10, 5)
await expect(page.locator('.cm-content')).toContainText(
expectBeforeUnconstrained
)
@ -3283,6 +3305,14 @@ test.describe('Testing segment overlays', () => {
await expect(page.locator('.cm-content')).toContainText(
expectAfterUnconstrained
)
await page.mouse.move(0, 0)
await page.waitForTimeout(1000)
x = hoverPos.x + Math.cos(ang*deg)*32
y = hoverPos.y - Math.sin(ang*deg)*32
await page.mouse.move(x, y)
await wiggleMove(page, x, y, 20, 30, ang, 10, 5)
const unconstrainedLocator = page.locator(
`[data-constraint-type="${constraintType}"][data-is-constrained="false"]`
)
@ -3328,14 +3358,16 @@ test.describe('Testing segment overlays', () => {
ang?: number
steps?: number
}) => {
const [x, y] = [
Math.cos((ang * Math.PI) / 180) * 45,
Math.sin((ang * Math.PI) / 180) * 45,
]
await page.mouse.move(hoverPos.x + x, hoverPos.y + y)
await page.mouse.move(0, 0)
await page.waitForTimeout(1000)
let x = 0, y = 0
x = hoverPos.x + Math.cos(ang*deg)*32
y = hoverPos.y - Math.sin(ang*deg)*32
await page.mouse.move(x, y)
await wiggleMove(page, x, y, 20, 30, ang, 10, 5)
await expect(page.getByText('Added variable')).not.toBeVisible()
await page.mouse.move(hoverPos.x, hoverPos.y, { steps })
await expect(page.locator('.cm-content')).toContainText(
expectBeforeUnconstrained
)
@ -3353,7 +3385,14 @@ test.describe('Testing segment overlays', () => {
expectAfterUnconstrained
)
await expect(page.getByText('Added variable')).not.toBeVisible()
await page.mouse.move(hoverPos.x, hoverPos.y, { steps })
await page.mouse.move(0, 0)
await page.waitForTimeout(1000)
x = hoverPos.x + Math.cos(ang*deg)*32
y = hoverPos.y - Math.sin(ang*deg)*32
await page.mouse.move(x, y)
await wiggleMove(page, x, y, 20, 30, ang, 10, 5)
const constrainedLocator = page.locator(
`[data-constraint-type="${constraintType}"][data-is-constrained="true"]`
)
@ -3365,6 +3404,7 @@ test.describe('Testing segment overlays', () => {
await constrainedLocator.click()
await expect(page.locator('.cm-content')).toContainText(expectFinal)
}
test.setTimeout(120000)
test('for segments [line, angledLine, lineTo, xLineTo]', async ({
page,
}) => {
@ -3372,24 +3412,24 @@ test.describe('Testing segment overlays', () => {
localStorage.setItem(
'persistCode',
`const part001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> startProfileAt([5 + 0, 20 + 0], %)
|> line([0.5, -14 + 0], %)
|> angledLine({ angle: 3 + 0, length: 32 + 0 }, %)
|> lineTo([33, 11.5 + 0], %)
|> xLineTo(9 - 5, %)
|> yLineTo(-10.77, %, 'a')
|> lineTo([5 + 33, 20 + 11.5 + 0], %)
|> xLineTo(5 + 9 - 5, %)
|> yLineTo(20 + -10.77, %, 'a')
|> xLine(26.04, %)
|> yLine(21.14 + 0, %)
|> angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)
|> angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)
|> angledLineToX({ angle: 3 + 0, to: 26 }, %)
|> angledLineToY({ angle: 89, to: 9.14 + 0 }, %)
|> angledLineToX({ angle: 3 + 0, to: 5 + 26 }, %)
|> angledLineToY({ angle: 89, to: 20 + 9.14 + 0 }, %)
|> angledLineThatIntersects({
angle: 4.14,
intersectTag: 'a',
offset: 9
}, %)
|> tangentialArcTo([3.14 + 13, 3.14], %)
|> tangentialArcTo([5 + 3.14 + 13, 20 + 3.14], %)
`
)
})
@ -3423,8 +3463,9 @@ test.describe('Testing segment overlays', () => {
},
})
await page.waitForTimeout(100)
await u.closeDebugPanel()
await page.getByText('xLineTo(9 - 5, %)').click()
await page.getByText('xLineTo(5 + 9 - 5, %)').click()
await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click()
await page.waitForTimeout(500)
@ -3434,45 +3475,62 @@ test.describe('Testing segment overlays', () => {
const clickUnconstrained = _clickUnconstrained(page)
const clickConstrained = _clickConstrained(page)
// Drag the sketch into view
await page.mouse.move(600, 64)
await page.mouse.down({ button: "middle" })
await page.mouse.move(600, 450, { steps: 10 })
await page.mouse.up({ button: "middle" })
await page.mouse.move(600, 64)
await page.mouse.down({ button: "middle" })
await page.mouse.move(600, 120, { steps: 10 })
await page.mouse.up({ button: "middle" })
let ang = 0
const line = await u.getBoundingBox(`[data-overlay-index="${0}"]`)
console.log('line1')
ang = await u.getAngle(`[data-overlay-index="${0}"]`)
console.log('line1', line, ang)
await clickConstrained({
hoverPos: { x: line.x, y: line.y - 10 },
hoverPos: { x: line.x, y: line.y },
constraintType: 'yRelative',
expectBeforeUnconstrained: '|> line([0.5, -14 + 0], %)',
expectAfterUnconstrained: '|> line([0.5, -14], %)',
expectFinal: '|> line([0.5, yRel001], %)',
ang: 135,
ang: ang+180,
})
console.log('line2')
await clickUnconstrained({
hoverPos: { x: line.x, y: line.y - 10 },
hoverPos: { x: line.x, y: line.y },
constraintType: 'xRelative',
expectBeforeUnconstrained: '|> line([0.5, yRel001], %)',
expectAfterUnconstrained: 'line([xRel001, yRel001], %)',
expectFinal: '|> line([0.5, yRel001], %)',
ang: -45,
ang: ang+180,
})
const angledLine = await u.getBoundingBox(`[data-overlay-index="1"]`)
ang = await u.getAngle(`[data-overlay-index="1"]`)
console.log('angledLine1')
await clickConstrained({
hoverPos: { x: angledLine.x - 10, y: angledLine.y },
hoverPos: { x: angledLine.x, y: angledLine.y },
constraintType: 'angle',
expectBeforeUnconstrained:
'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)',
expectAfterUnconstrained: 'angledLine({ angle: 3, length: 32 + 0 }, %)',
expectFinal: 'angledLine({ angle: angle001, length: 32 + 0 }, %)',
ang: ang+180,
})
console.log('angledLine2')
await clickConstrained({
hoverPos: { x: angledLine.x - 10, y: angledLine.y },
hoverPos: { x: angledLine.x, y: angledLine.y },
constraintType: 'length',
expectBeforeUnconstrained:
'angledLine({ angle: angle001, length: 32 + 0 }, %)',
expectAfterUnconstrained:
'angledLine({ angle: angle001, length: 32 }, %)',
expectFinal: 'angledLine({ angle: angle001, length: len001 }, %)',
ang: ang+180,
})
await page.mouse.move(700, 250)
@ -3483,35 +3541,38 @@ test.describe('Testing segment overlays', () => {
await page.waitForTimeout(200)
const lineTo = await u.getBoundingBox(`[data-overlay-index="2"]`)
ang = await u.getAngle(`[data-overlay-index="2"]`)
console.log('lineTo1')
await clickConstrained({
hoverPos: { x: lineTo.x, y: lineTo.y + 21 },
hoverPos: { x: lineTo.x, y: lineTo.y },
constraintType: 'yAbsolute',
expectBeforeUnconstrained: 'lineTo([33, 11.5 + 0], %)',
expectAfterUnconstrained: 'lineTo([33, 11.5], %)',
expectFinal: 'lineTo([33, yAbs001], %)',
expectBeforeUnconstrained: 'lineTo([5 + 33, 20 + 11.5 + 0], %)',
expectAfterUnconstrained: 'lineTo([5 + 33, 31.5], %)',
expectFinal: 'lineTo([5 + 33, yAbs001], %)',
steps: 8,
ang: 55,
ang: ang+180,
})
console.log('lineTo2')
await clickUnconstrained({
hoverPos: { x: lineTo.x, y: lineTo.y + 25 },
await clickConstrained({
hoverPos: { x: lineTo.x, y: lineTo.y },
constraintType: 'xAbsolute',
expectBeforeUnconstrained: 'lineTo([33, yAbs001], %)',
expectAfterUnconstrained: 'lineTo([xAbs001, yAbs001], %)',
expectFinal: 'lineTo([33, yAbs001], %)',
expectBeforeUnconstrained: 'lineTo([5 + 33, yAbs001], %)',
expectAfterUnconstrained: 'lineTo([38, yAbs001], %)',
expectFinal: 'lineTo([xAbs001, yAbs001], %)',
steps: 8,
ang: ang+180,
})
const xLineTo = await u.getBoundingBox(`[data-overlay-index="3"]`)
ang = await u.getAngle(`[data-overlay-index="3"]`)
console.log('xlineTo1')
await clickConstrained({
hoverPos: { x: xLineTo.x + 15, y: xLineTo.y },
hoverPos: { x: xLineTo.x, y: xLineTo.y },
constraintType: 'xAbsolute',
expectBeforeUnconstrained: 'xLineTo(9 - 5, %)',
expectAfterUnconstrained: 'xLineTo(4, %)',
expectBeforeUnconstrained: 'xLineTo(5 + 9 - 5, %)',
expectAfterUnconstrained: 'xLineTo(9, %)',
expectFinal: 'xLineTo(xAbs002, %)',
ang: -45,
ang: ang+180,
steps: 8,
})
})
@ -3566,26 +3627,31 @@ const part001 = startSketchOn('XZ')
await page.waitForTimeout(300)
let ang = 0
const yLineTo = await u.getBoundingBox(`[data-overlay-index="4"]`)
ang = await u.getAngle(`[data-overlay-index="4"]`)
console.log('ylineTo1')
await clickUnconstrained({
hoverPos: { x: yLineTo.x, y: yLineTo.y - 30 },
hoverPos: { x: yLineTo.x, y: yLineTo.y },
constraintType: 'yAbsolute',
expectBeforeUnconstrained: "yLineTo(-10.77, %, 'a')",
expectAfterUnconstrained: "yLineTo(yAbs002, %, 'a')",
expectFinal: "yLineTo(-10.77, %, 'a')",
ang: ang + 180,
})
const xLine = await u.getBoundingBox(`[data-overlay-index="5"]`)
ang = await u.getAngle(`[data-overlay-index="5"]`)
console.log('xline')
await clickUnconstrained({
hoverPos: { x: xLine.x - 25, y: xLine.y },
hoverPos: { x: xLine.x, y: xLine.y },
constraintType: 'xRelative',
expectBeforeUnconstrained: 'xLine(26.04, %)',
expectAfterUnconstrained: 'xLine(xRel002, %)',
expectFinal: 'xLine(26.04, %)',
steps: 10,
ang: 50,
ang: ang + 180,
})
})
test('for segments [yLine, angledLineOfXLength, angledLineOfYLength]', async ({
@ -3625,6 +3691,7 @@ const part001 = startSketchOn('XZ')
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.waitForTimeout(500)
await page.getByText('xLineTo(9 - 5, %)').click()
await page.waitForTimeout(100)
@ -3636,7 +3703,10 @@ const part001 = startSketchOn('XZ')
const clickUnconstrained = _clickUnconstrained(page)
const clickConstrained = _clickConstrained(page)
let ang = 0
const yLine = await u.getBoundingBox(`[data-overlay-index="6"]`)
ang = await u.getAngle(`[data-overlay-index="6"]`)
console.log('yline1')
await clickConstrained({
hoverPos: { x: yLine.x, y: yLine.y + 20 },
@ -3644,11 +3714,13 @@ const part001 = startSketchOn('XZ')
expectBeforeUnconstrained: 'yLine(21.14 + 0, %)',
expectAfterUnconstrained: 'yLine(21.14, %)',
expectFinal: 'yLine(yRel001, %)',
ang: ang + 180
})
const angledLineOfXLength = await u.getBoundingBox(
`[data-overlay-index="7"]`
)
ang = await u.getAngle(`[data-overlay-index="7"]`)
console.log('angledLineOfXLength1')
await clickConstrained({
hoverPos: { x: angledLineOfXLength.x + 20, y: angledLineOfXLength.y },
@ -3659,6 +3731,7 @@ const part001 = startSketchOn('XZ')
'angledLineOfXLength({ angle: -179, length: 23.14 }, %)',
expectFinal:
'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)',
ang: ang + 180
})
console.log('angledLineOfXLength2')
await clickUnconstrained({
@ -3671,11 +3744,13 @@ const part001 = startSketchOn('XZ')
expectFinal:
'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)',
steps: 7,
ang: ang + 180
})
const angledLineOfYLength = await u.getBoundingBox(
`[data-overlay-index="8"]`
)
ang = await u.getAngle(`[data-overlay-index="8"]`)
console.log('angledLineOfYLength1')
await clickUnconstrained({
hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y - 20 },
@ -3685,7 +3760,7 @@ const part001 = startSketchOn('XZ')
expectAfterUnconstrained:
'angledLineOfYLength({ angle: angle002, length: 19 + 0 }, %)',
expectFinal: 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)',
ang: 135,
ang: ang + 180,
steps: 6,
})
console.log('angledLineOfYLength2')
@ -3697,14 +3772,13 @@ const part001 = startSketchOn('XZ')
expectAfterUnconstrained:
'angledLineOfYLength({ angle: -91, length: 19 }, %)',
expectFinal: 'angledLineOfYLength({ angle: -91, length: yRel002 }, %)',
ang: -45,
ang: ang + 180,
steps: 7,
})
})
test('for segments [angledLineToX, angledLineToY, angledLineThatIntersects]', async ({
page,
}) => {
test.skip(process.platform !== 'darwin', 'too flakey on ubuntu')
await page.addInitScript(async () => {
localStorage.setItem(
'persistCode',
@ -3750,14 +3824,18 @@ const part001 = startSketchOn('XZ')
const clickUnconstrained = _clickUnconstrained(page)
const clickConstrained = _clickConstrained(page)
let ang = 0
const angledLineToX = await u.getBoundingBox(`[data-overlay-index="9"]`)
ang = await u.getAngle(`[data-overlay-index="9"]`)
console.log('angledLineToX')
await clickConstrained({
hoverPos: { x: angledLineToX.x - 20, y: angledLineToX.y },
hoverPos: { x: angledLineToX.x, y: angledLineToX.y },
constraintType: 'angle',
expectBeforeUnconstrained: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)',
expectAfterUnconstrained: 'angledLineToX({ angle: 3, to: 26 }, %)',
expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)',
ang: ang + 180
})
console.log('angledLineToX2')
await clickUnconstrained({
@ -3768,12 +3846,14 @@ const part001 = startSketchOn('XZ')
expectAfterUnconstrained:
'angledLineToX({ angle: angle001, to: xAbs001 }, %)',
expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)',
ang: ang + 180
})
const angledLineToY = await u.getBoundingBox(`[data-overlay-index="10"]`)
ang = await u.getAngle(`[data-overlay-index="10"]`)
console.log('angledLineToY')
await clickUnconstrained({
hoverPos: { x: angledLineToY.x, y: angledLineToY.y + 20 },
hoverPos: { x: angledLineToY.x, y: angledLineToY.y },
constraintType: 'angle',
expectBeforeUnconstrained:
'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)',
@ -3781,7 +3861,7 @@ const part001 = startSketchOn('XZ')
'angledLineToY({ angle: angle002, to: 9.14 + 0 }, %)',
expectFinal: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)',
steps: process.platform === 'darwin' ? 8 : 9,
ang: 135,
ang: ang + 180
})
console.log('angledLineToY2')
await clickConstrained({
@ -3791,12 +3871,13 @@ const part001 = startSketchOn('XZ')
'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)',
expectAfterUnconstrained: 'angledLineToY({ angle: 89, to: 9.14 }, %)',
expectFinal: 'angledLineToY({ angle: 89, to: yAbs001 }, %)',
ang: 135,
ang: ang + 180
})
const angledLineThatIntersects = await u.getBoundingBox(
`[data-overlay-index="11"]`
)
ang = await u.getAngle(`[data-overlay-index="11"]`)
console.log('angledLineThatIntersects')
await clickUnconstrained({
hoverPos: {
@ -3819,7 +3900,7 @@ const part001 = startSketchOn('XZ')
offset: 9,
intersectTag: 'a'
}, %)`,
ang: -45,
ang: ang + 180,
})
console.log('angledLineThatIntersects2')
await clickUnconstrained({
@ -3843,7 +3924,7 @@ const part001 = startSketchOn('XZ')
offset: 9,
intersectTag: 'a'
}, %)`,
ang: -25,
ang: ang + 180,
})
})
test('for segment [tangentialArcTo]', async ({ page }) => {
@ -3895,24 +3976,25 @@ const part001 = startSketchOn('XZ')
const tangentialArcTo = await u.getBoundingBox(
`[data-overlay-index="12"]`
)
let ang = await u.getAngle(`[data-overlay-index="12"]`)
console.log('tangentialArcTo')
await clickConstrained({
hoverPos: { x: tangentialArcTo.x - 10, y: tangentialArcTo.y + 20 },
hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y },
constraintType: 'xAbsolute',
expectBeforeUnconstrained: 'tangentialArcTo([3.14 + 13, -3.14], %)',
expectAfterUnconstrained: 'tangentialArcTo([16.14, -3.14], %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)',
ang: -45,
ang: ang + 180,
steps: 6,
})
console.log('tangentialArcTo2')
await clickUnconstrained({
hoverPos: { x: tangentialArcTo.x - 10, y: tangentialArcTo.y + 20 },
hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y },
constraintType: 'yAbsolute',
expectBeforeUnconstrained: 'tangentialArcTo([xAbs001, -3.14], %)',
expectAfterUnconstrained: 'tangentialArcTo([xAbs001, yAbs001], %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)',
ang: -135,
ang: ang + 180,
steps: 10,
})
})
@ -4007,25 +4089,7 @@ const part001 = startSketchOn('XZ')
steps: 6,
})
segmentToDelete = await getOverlayByIndex(0)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y - 20 },
codeToBeDeleted: 'line([0.5, -14 + 0], %)',
stdLibFnName: 'line',
ang: -45,
})
segmentToDelete = await getOverlayByIndex(0)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x - 20, y: segmentToDelete.y },
codeToBeDeleted: 'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)',
stdLibFnName: 'angledLine',
ang: 135,
})
await page.waitForTimeout(200)
segmentToDelete = await getOverlayByIndex(9)
segmentToDelete = await getOverlayByIndex(11)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x + 10, y: segmentToDelete.y },
codeToBeDeleted: `angledLineThatIntersects({
@ -4038,21 +4102,21 @@ const part001 = startSketchOn('XZ')
steps: 7,
})
segmentToDelete = await getOverlayByIndex(8)
segmentToDelete = await getOverlayByIndex(10)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x + 10, y: segmentToDelete.y },
codeToBeDeleted: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)',
stdLibFnName: 'angledLineToY',
})
segmentToDelete = await getOverlayByIndex(7)
segmentToDelete = await getOverlayByIndex(9)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x - 10, y: segmentToDelete.y },
codeToBeDeleted: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)',
stdLibFnName: 'angledLineToX',
})
segmentToDelete = await getOverlayByIndex(6)
segmentToDelete = await getOverlayByIndex(8)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y - 10 },
codeToBeDeleted:
@ -4060,7 +4124,7 @@ const part001 = startSketchOn('XZ')
stdLibFnName: 'angledLineOfYLength',
})
segmentToDelete = await getOverlayByIndex(5)
segmentToDelete = await getOverlayByIndex(7)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x + 10, y: segmentToDelete.y },
codeToBeDeleted:
@ -4068,42 +4132,36 @@ const part001 = startSketchOn('XZ')
stdLibFnName: 'angledLineOfXLength',
})
segmentToDelete = await getOverlayByIndex(4)
segmentToDelete = await getOverlayByIndex(6)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y + 10 },
codeToBeDeleted: 'yLine(21.14 + 0, %)',
stdLibFnName: 'yLine',
})
segmentToDelete = await getOverlayByIndex(3)
segmentToDelete = await getOverlayByIndex(5)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x - 10, y: segmentToDelete.y },
codeToBeDeleted: 'xLine(26.04, %)',
stdLibFnName: 'xLine',
})
segmentToDelete = await getOverlayByIndex(2)
segmentToDelete = await getOverlayByIndex(4)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y - 10 },
codeToBeDeleted: "yLineTo(-10.77, %, 'a')",
stdLibFnName: 'yLineTo',
})
segmentToDelete = await getOverlayByIndex(1)
segmentToDelete = await getOverlayByIndex(3)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x + 10, y: segmentToDelete.y },
codeToBeDeleted: 'xLineTo(9 - 5, %)',
stdLibFnName: 'xLineTo',
})
for (let i = 0; i < 15; i++) {
await page.mouse.wheel(0, 100)
await page.waitForTimeout(25)
}
await page.waitForTimeout(200)
segmentToDelete = await getOverlayByIndex(0)
// Not sure why this is diff. from the others - Kurt, ideas?
segmentToDelete = await getOverlayByIndex(2)
const hoverPos = { x: segmentToDelete.x - 10, y: segmentToDelete.y + 10 }
await expect(page.getByText('Added variable')).not.toBeVisible()
const [x, y] = [
@ -4122,6 +4180,24 @@ const part001 = startSketchOn('XZ')
await expect(page.locator('.cm-content')).not.toContainText(
codeToBeDeleted
)
segmentToDelete = await getOverlayByIndex(1)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x - 20, y: segmentToDelete.y },
codeToBeDeleted: 'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)',
stdLibFnName: 'angledLine',
ang: 135,
})
segmentToDelete = await getOverlayByIndex(0)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y - 20 },
codeToBeDeleted: 'line([0.5, -14 + 0], %)',
stdLibFnName: 'line',
ang: -45,
})
await page.waitForTimeout(200)
})
})
test.describe('Testing delete with dependent segments', () => {

View File

@ -145,11 +145,15 @@ export async function getUtils(page: Page) {
y: bbox.y - angleYOffset,
}
},
getAngle: async (locator: string) => {
const overlay = page.locator(locator)
return Number(await overlay.getAttribute('data-overlay-angle'))
},
getBoundingBox: async (locator: string) =>
page
.locator(locator)
.boundingBox()
.then((box) => ({ x: box?.x || 0, y: box?.y || 0 })),
.then((box) => ({ ...box, x: box?.x || 0, y: box?.y || 0 })),
doAndWaitForCmd: async (
fn: () => Promise<void>,
commandType: string,