@ -151,11 +151,12 @@ test.describe('Sketch tests', () => {
|
||||
|
||||
await page.mouse.click(700, 200)
|
||||
|
||||
await expect(page.locator('.cm-content')).toHaveText(
|
||||
`const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.61, -14.01], %)
|
||||
|> line([0.31, 16.47], %)`
|
||||
)
|
||||
await expect.poll(u.normalisedEditorCode)
|
||||
.toBe(`const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([12.34, -12.34], %)
|
||||
|> line([-12.34, 12.34], %)
|
||||
|
||||
`)
|
||||
})
|
||||
test('Can exit selection of face', async ({ page }) => {
|
||||
// Load the app with the code panes
|
||||
|
@ -268,6 +268,18 @@ async function waitForAuthAndLsp(page: Page) {
|
||||
return waitForLspPromise
|
||||
}
|
||||
|
||||
export function normaliseKclNumbers(code: string, ignoreZero = true): string {
|
||||
const numberRegexp = /(?<!\w)-?\b\d+(\.\d+)?\b(?!\w)/g
|
||||
const replaceNumber = (number: string) => {
|
||||
if (ignoreZero && (number === '0' || number === '-0')) return number
|
||||
const sign = number.startsWith('-') ? '-' : ''
|
||||
return `${sign}12.34`
|
||||
}
|
||||
const replaceNumbers = (text: string) =>
|
||||
text.replace(numberRegexp, replaceNumber)
|
||||
return replaceNumbers(code)
|
||||
}
|
||||
|
||||
export async function getUtils(page: Page) {
|
||||
// Chrome devtools protocol session only works in Chromium
|
||||
const browserType = page.context().browser()?.browserType().name()
|
||||
@ -330,6 +342,11 @@ export async function getUtils(page: Page) {
|
||||
.boundingBox()
|
||||
.then((box) => ({ ...box, x: box?.x || 0, y: box?.y || 0 })),
|
||||
codeLocator: page.locator('.cm-content'),
|
||||
normalisedEditorCode: async () => {
|
||||
const code = await page.locator('.cm-content').innerText()
|
||||
return normaliseKclNumbers(code)
|
||||
},
|
||||
normalisedCode: (code: string) => normaliseKclNumbers(code),
|
||||
canvasLocator: page.getByTestId('client-side-scene'),
|
||||
doAndWaitForCmd: async (
|
||||
fn: () => Promise<void>,
|
||||
|
@ -80,11 +80,11 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %, $seg01)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> angledLine([segAng(seg01), yo], %)
|
||||
|> line([41.19, 28.97 + 5], %)
|
||||
|> line([41.19, 58.97 + 5], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
|> yLine(-264.06, %)
|
||||
|> startProfileAt([299.05, 120], %)
|
||||
|> xLine(-385.34, %, $seg_what)
|
||||
|> yLine(-170.06, %)
|
||||
|> xLine(segLen(seg_what), %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)`
|
||||
)
|
||||
@ -138,7 +138,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %, $seg01)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> angledLine([segAng(seg01), 78.33], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
@ -237,7 +237,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> line([9.16, 77.79], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
@ -343,7 +343,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> line([9.16, 77.79], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
@ -450,7 +450,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> line([9.16, 77.79], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
@ -560,7 +560,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> line([9.16, 77.79], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
@ -613,14 +613,14 @@ const part002 = startSketchOn('XZ')
|
||||
codeAfter: [
|
||||
`|> yLine(130.4, %)`,
|
||||
`|> yLine(77.79, %)`,
|
||||
`|> yLine(28.97, %)`,
|
||||
`|> yLine(48.97, %)`,
|
||||
],
|
||||
},
|
||||
{
|
||||
codeAfter: [
|
||||
`|> xLine(74.36, %)`,
|
||||
`|> xLine(9.16, %)`,
|
||||
`|> xLine(41.19, %)`,
|
||||
`|> xLine(51.19, %)`,
|
||||
],
|
||||
constraintName: 'Horizontal',
|
||||
},
|
||||
@ -636,7 +636,7 @@ const part001 = startSketchOn('XZ')
|
||||
|> line([74.36, 130.4], %)
|
||||
|> line([78.92, -120.11], %)
|
||||
|> line([9.16, 77.79], %)
|
||||
|> line([41.19, 28.97], %)
|
||||
|> line([51.19, 48.97], %)
|
||||
const part002 = startSketchOn('XZ')
|
||||
|> startProfileAt([299.05, 231.45], %)
|
||||
|> xLine(-425.34, %, $seg_what)
|
||||
|
@ -468,7 +468,7 @@ test('Sketch on face', async ({ page }) => {
|
||||
|
||||
await u.openAndClearDebugPanel()
|
||||
await u.doAndWaitForCmd(
|
||||
() => page.mouse.click(625, 133),
|
||||
() => page.mouse.click(625, 165),
|
||||
'default_camera_get_settings',
|
||||
true
|
||||
)
|
||||
@ -498,13 +498,14 @@ test('Sketch on face', async ({ page }) => {
|
||||
await expect(page.locator('.cm-content')).not.toHaveText(previousCodeContent)
|
||||
previousCodeContent = await page.locator('.cm-content').innerText()
|
||||
|
||||
await expect(page.locator('.cm-content'))
|
||||
.toContainText(`const sketch002 = startSketchOn(extrude001, seg01)
|
||||
await expect.poll(u.normalisedEditorCode).toContain(
|
||||
u.normalisedCode(`const sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.94, 6.6], %)
|
||||
|> line([2.45, -0.2], %)
|
||||
|> line([-2.6, -1.25], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`)
|
||||
)
|
||||
|
||||
await u.openAndClearDebugPanel()
|
||||
await page.getByRole('button', { name: 'Exit Sketch' }).click()
|
||||
@ -513,7 +514,7 @@ test('Sketch on face', async ({ page }) => {
|
||||
await u.updateCamPosition([1049, 239, 686])
|
||||
await u.closeDebugPanel()
|
||||
|
||||
await page.getByText('startProfileAt([-12.94, 6.6], %)').click()
|
||||
await page.getByText('startProfileAt([-12').click()
|
||||
await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Edit Sketch' }).click()
|
||||
await page.waitForTimeout(400)
|
||||
@ -549,7 +550,7 @@ test('Sketch on face', async ({ page }) => {
|
||||
await page.getByRole('button', { name: 'Exit Sketch' }).click()
|
||||
await u.expectCmdLog('[data-message-type="execution-done"]')
|
||||
|
||||
await page.getByText('startProfileAt([-12.94, 6.6], %)').click()
|
||||
await page.getByText('startProfileAt([-12').click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Extrude' })).not.toBeDisabled()
|
||||
await page.waitForTimeout(100)
|
||||
|
41
src/test-utils.test.ts
Normal file
41
src/test-utils.test.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { normaliseKclNumbers } from '../e2e/playwright/test-utils'
|
||||
|
||||
test('normaliseKclNumbers', () => {
|
||||
expect(
|
||||
normaliseKclNumbers(`const sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-15, sketch001)`)
|
||||
).toBe(`const sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> line([12.34, 0], %)
|
||||
|> line([0, -12.34], %)
|
||||
|> line([-12.34, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-12.34, sketch001)`)
|
||||
expect(
|
||||
normaliseKclNumbers(
|
||||
`const sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-15, sketch001)`,
|
||||
false
|
||||
)
|
||||
).toBe(`const sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> line([12.34, 12.34], %)
|
||||
|> line([12.34, -12.34], %)
|
||||
|> line([-12.34, 12.34], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-12.34, sketch001)`)
|
||||
})
|
Reference in New Issue
Block a user