diff --git a/e2e/playwright/sketch-tests.spec.ts b/e2e/playwright/sketch-tests.spec.ts index 8ea06d781..03e6f342a 100644 --- a/e2e/playwright/sketch-tests.spec.ts +++ b/e2e/playwright/sketch-tests.spec.ts @@ -12,177 +12,164 @@ import { } from './test-utils' import { uuidv4, roundOff } from 'lib/utils' -test.afterEach(async ({ page }, testInfo) => { - await tearDown(page, testInfo) -}) + test.describe('Sketch tests', () => { - test('multi-sketch file shows multiple Edit Sketch buttons', async ({ - page, - context, - homePage, - }) => { - const u = await getUtils(page) - const selectionsSnippets = { - startProfileAt1: - '|> startProfileAt([-width / 4 + screwRadius, height / 2], %)', - startProfileAt2: '|> startProfileAt([-width / 2, 0], %)', - startProfileAt3: '|> startProfileAt([0, thickness], %)', - } - await context.addInitScript( - async ({ startProfileAt1, startProfileAt2, startProfileAt3 }: any) => { - localStorage.setItem( - 'persistCode', - ` - width = 20 - height = 10 - thickness = 5 - screwRadius = 3 - wireRadius = 2 - wireOffset = 0.5 - - screwHole = startSketchOn('XY') - ${startProfileAt1} - |> arc({ - radius = screwRadius, - angle_start = 0, - angle_end = 360 - }, %) - - part001 = startSketchOn('XY') - ${startProfileAt2} - |> xLine(width * .5, %) - |> yLine(height, %) - |> xLine(-width * .5, %) - |> close(%) - |> hole(screwHole, %) - |> extrude(thickness, %) - - part002 = startSketchOn('-XZ') - ${startProfileAt3} - |> xLine(width / 4, %) - |> tangentialArcTo([width / 2, 0], %) - |> xLine(-width / 4 + wireRadius, %) - |> yLine(wireOffset, %) - |> arc({ - radius = wireRadius, - angle_start = 0, - angle_end = 180 - }, %) - |> yLine(-wireOffset, %) - |> xLine(-width / 4, %) - |> close(%) - |> extrude(-height, %) - ` - ) - }, - selectionsSnippets - ) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText(selectionsSnippets.startProfileAt1).click() - await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).toBeVisible() - - await page.getByText(selectionsSnippets.startProfileAt2).click() - await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).toBeVisible() - - await page.getByText(selectionsSnippets.startProfileAt3).click() - await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).toBeVisible() - }) - test('Can delete most of a sketch and the line tool will still work', async ({ - page, - center, - homePage, - }) => { - const u = await getUtils(page) - await page.addInitScript(async () => { + test('multi-sketch file shows multiple Edit Sketch buttons', async ({ page, context, + homePage }) => { const u = await getUtils(page) + const selectionsSnippets = { + startProfileAt1: + '|> startProfileAt([-width / 4 + screwRadius, height / 2], %)', + startProfileAt2: '|> startProfileAt([-width / 2, 0], %)', + startProfileAt3: '|> startProfileAt([0, thickness], %)', + } + await context.addInitScript( + async ({ startProfileAt1, startProfileAt2, startProfileAt3 }: any) => { localStorage.setItem( 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([4.61, -14.01], %) - |> xLine(12.73, %) - |> tangentialArcTo([24.95, -5.38], %)` + ` + width = 20 + height = 10 + thickness = 5 + screwRadius = 3 + wireRadius = 2 + wireOffset = 0.5 + + screwHole = startSketchOn('XY') + ${startProfileAt1} + |> arc({ + radius: screwRadius, + angle_start: 0, + angle_end: 360 + }, %) + + part001 = startSketchOn('XY') + ${startProfileAt2} + |> xLine(width * .5, %) + |> yLine(height, %) + |> xLine(-width * .5, %) + |> close(%) + |> hole(screwHole, %) + |> extrude(thickness, %) + + part002 = startSketchOn('-XZ') + ${startProfileAt3} + |> xLine(width / 4, %) + |> tangentialArcTo([width / 2, 0], %) + |> xLine(-width / 4 + wireRadius, %) + |> yLine(wireOffset, %) + |> arc({ + radius: wireRadius, + angle_start: 0, + angle_end: 180 + }, %) + |> yLine(-wireOffset, %) + |> xLine(-width / 4, %) + |> close(%) + |> extrude(-height, %) + ` ) - }) - - await homePage.goToModelingScene() - - await expect(async () => { - await page.getByText('tangentialArcTo([24.95, -5.38], %)').click() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).toBeEnabled({ timeout: 1000 }) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - }).toPass({ timeout: 40_000, intervals: [1_000] }) - - await page.waitForTimeout(600) // wait for animation - + }, + selectionsSnippets + ) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText(selectionsSnippets.startProfileAt1).click() + await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).toBeVisible() + + await page.getByText(selectionsSnippets.startProfileAt2).click() + await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).toBeVisible() + + await page.getByText(selectionsSnippets.startProfileAt3).click() + await expect(page.getByRole('button', { name: 'Extrude' })).toBeDisabled() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).toBeVisible() }) + test('Can delete most of a sketch and the line tool will still work', async ({ page, center, + homePage }) => { const u = await getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> startProfileAt([4.61, -14.01], %) + |> xLine(12.73, %) + |> tangentialArcTo([24.95, -5.38], %)` + ) + }) + + await homePage.goToModelingScene() + + await expect(async () => { await page.getByText('tangentialArcTo([24.95, -5.38], %)').click() - await page.keyboard.press('End') - await page.keyboard.down('Shift') - await page.keyboard.press('ArrowUp') - await page.keyboard.press('Home') - await page.keyboard.up('Shift') - await page.keyboard.press('Backspace') - await u.openAndClearDebugPanel() - - await u.expectCmdLog('[data-message-type="execution-done"]', 10_000) - await page.waitForTimeout(100) - - await page.getByRole('button', { name: 'line Line', exact: true }).click() - await page.waitForTimeout(100) - - await expect(async () => { - await page.mouse.move(700, 200, { step: 25 }) - await page.mouse.click(700, 200) - - await expect.poll(u.normalisedEditorCode, { timeout: 1000 }) - .toBe(`sketch001 = startSketchOn('XZ') - |> startProfileAt([12.34, -12.34], %) - |> yLine(12.34, %) - -`) - }).toPass({ timeout: 40_000, intervals: [1_000] }) - }) - test('Can exit selection of face', async ({ page, homePage }) => { - // Load the app with the code panes - await page.addInitScript(async () => { - localStorage.setItem('persistCode', ``) - }) - - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - await page.getByRole('button', { name: 'Start Sketch' }).click() await expect( - page.getByRole('button', { name: 'Exit Sketch' }) - ).toBeVisible() + page.getByRole('button', { name: 'Edit Sketch' }) + ).toBeEnabled({ timeout: 1000 }) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + }).toPass({ timeout: 40_000, intervals: [1_000] }) + + await page.waitForTimeout(600) // wait for animation + + await page.getByText('tangentialArcTo([24.95, -5.38], %)').click() + await page.keyboard.press('End') + await page.keyboard.down('Shift') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('Home') + await page.keyboard.up('Shift') + await page.keyboard.press('Backspace') + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]', 10_000) + await page.waitForTimeout(100) + + await page.getByRole('button', { name: 'line Line', exact: true }).click() + await page.waitForTimeout(100) + + await expect(async () => { + await page.mouse.move(700, 200, { step: 25 }) + await page.mouse.click(700, 200) + + await expect.poll(u.crushKclCodeIntoOneLineAndThenMaybeSome, { timeout: 1000 }) + .toBe(`sketch001 = startSketchOn('XZ') + |> startProfileAt([4.61,-14.01], %) + |> yLine(15.95, %) +`.replaceAll(' ', '').replaceAll("\n", '')) + }).toPass({ timeout: 40_000, intervals: [1_000] }) - await expect(page.getByText('select a plane or face')).toBeVisible() - - await page.keyboard.press('Escape') - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).toBeVisible() }) + + test('Can exit selection of face', async ({ page, homePage }) => { // Load the app with the code panes + await page.addInitScript(async () => { + localStorage.setItem('persistCode', ``) + }) + + const u = await getUtils(page) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + await page.getByRole('button', { name: 'Start Sketch' }).click() + await expect( + page.getByRole('button', { name: 'Exit Sketch' }) + ).toBeVisible() + + await expect(page.getByText('select a plane or face')).toBeVisible() + + await page.keyboard.press('Escape') + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).toBeVisible() }) test.describe('Can edit segments by dragging their handles', () => { const doEditSegmentsByDraggingHandle = async ( page: Page, @@ -204,7 +191,7 @@ test.describe('Sketch tests', () => { const u = await getUtils(page) await homePage.goToModelingScene() - await expect( + await expect( page.getByRole('button', { name: 'Start Sketch' }) ).not.toBeDisabled() @@ -317,418 +304,397 @@ test.describe('Sketch tests', () => { |> line([1.97, 2.06], %) |> close(%)`) } - test('code pane open at start-handles', async ({ page, homePage }) => { - // Load the app with the code panes - await page.addInitScript(async () => { - localStorage.setItem( - 'store', - JSON.stringify({ - state: { - openPanes: ['code'], - }, - version: 0, - }) - ) - }) - await doEditSegmentsByDraggingHandle(page, homePage, ['code']) - }) - - test('code pane closed at start-handles', async ({ page, homePage }) => { - // Load the app with the code panes - await page.addInitScript(async (persistModelingContext) => { - localStorage.setItem( - persistModelingContext, - JSON.stringify({ openPanes: [] }) - ) - }, PERSIST_MODELING_CONTEXT) - await doEditSegmentsByDraggingHandle(page, homePage, []) - }) - }) - - test('Can edit a circle center and radius by dragging its handles', async ({ - page, - homePage, - }) => { - const u = await getUtils(page) + test('code pane open at start-handles', async ({ page, homePage }) => { // Load the app with the code panes await page.addInitScript(async () => { localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> circle({ center = [4.61, -5.01], radius = 8 }, %)` + 'store', + JSON.stringify({ + state: { + openPanes: ['code'], + }, + version: 0, + }) ) }) + await doEditSegmentsByDraggingHandle(page, homePage, ['code']) }) - await homePage.goToModelingScene() - - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).not.toBeDisabled() - - await page.waitForTimeout(100) - await u.openAndClearDebugPanel() - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_look_at', - vantage: { x: 0, y: -1250, z: 580 }, - center: { x: 0, y: 0, z: 0 }, - up: { x: 0, y: 0, z: 1 }, - }, - }) - await page.waitForTimeout(100) - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_get_settings', - }, - }) - await page.waitForTimeout(100) - - const startPX = [667, 325] - - const dragPX = 40 - - await page - .getByText('circle({ center = [4.61, -5.01], radius = 8 }, %)') - .click() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).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) - - await test.step('drag circle center handle', async () => { - await page.dragAndDrop('#stream', '#stream', { - sourcePosition: { x: startPX[0], y: startPX[1] }, - targetPosition: { x: startPX[0] + dragPX, y: startPX[1] - dragPX }, - }) - await page.waitForTimeout(100) - await expect(page.locator('.cm-content')).not.toHaveText(prevContent) - prevContent = await page.locator('.cm-content').innerText() - }) - - await test.step('drag circle radius handle', async () => { - await page.waitForTimeout(100) - - const lineEnd = await u.getBoundingBox('[data-overlay-index="0"]') - await page.waitForTimeout(100) - await page.dragAndDrop('#stream', '#stream', { - 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) - 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 }, %) -`) - }) - test('Can edit a sketch that has been extruded in the same pipe', async ({ - page, - homePage - }) => { - const u = await getUtils(page) - await page.addInitScript(async () => { + test('code pane closed at start-handles', async ({ page, homePage }) => { // Load the app with the code panes + await page.addInitScript(async (persistModelingContext) => { localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([4.61, -10.01], %) - |> line([12.73, -0.09], %) - |> tangentialArcTo([24.95, -0.38], %) - |> close(%) - |> extrude(5, %)` + persistModelingContext, + JSON.stringify({ openPanes: [] }) ) - }) + }, PERSIST_MODELING_CONTEXT) + await doEditSegmentsByDraggingHandle(page, homePage, []) }) + }) - await homePage.goToModelingScene() - - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).not.toBeDisabled() - - await page.waitForTimeout(100) - await u.openAndClearDebugPanel() - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_look_at', - vantage: { x: 0, y: -1250, z: 580 }, - center: { x: 0, y: 0, z: 0 }, - up: { x: 0, y: 0, z: 1 }, - }, - }) - await page.waitForTimeout(100) - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_get_settings', - }, - }) - await page.waitForTimeout(100) - - const startPX = [665, 397] - - const dragPX = 40 - - await page.getByText('startProfileAt([4.61, -10.01], %)').click() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).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(2) - - // drag startProfieAt handle + test('Can edit a circle center and radius by dragging its handles', async ({ page, homePage }) => { const u = await getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> circle({ center: [4.61, -5.01], radius: 8 }, %)` + ) + }) + + await homePage.goToModelingScene() + + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).not.toBeDisabled() + + await page.waitForTimeout(100) + await u.openAndClearDebugPanel() + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_look_at', + vantage: { x: 0, y: -1250, z: 580 }, + center: { x: 0, y: 0, z: 0 }, + up: { x: 0, y: 0, z: 1 }, + }, + }) + await page.waitForTimeout(100) + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_get_settings', + }, + }) + await page.waitForTimeout(100) + + const startPX = [667, 325] + + const dragPX = 40 + + await page + .getByText('circle({ center: [4.61, -5.01], radius: 8 }, %)') + .click() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).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) + + await test.step('drag circle center handle', async () => { await page.dragAndDrop('#stream', '#stream', { sourcePosition: { x: startPX[0], y: startPX[1] }, - targetPosition: { x: startPX[0] + dragPX, y: startPX[1] + dragPX }, + targetPosition: { x: startPX[0] + dragPX, y: startPX[1] - dragPX }, }) await page.waitForTimeout(100) await expect(page.locator('.cm-content')).not.toHaveText(prevContent) prevContent = await page.locator('.cm-content').innerText() - - // drag line handle + }) + + await test.step('drag circle radius handle', async () => { await page.waitForTimeout(100) - + const lineEnd = await u.getBoundingBox('[data-overlay-index="0"]') - await page.dragAndDrop('#stream', '#stream', { - sourcePosition: { x: lineEnd.x - 15, y: lineEnd.y }, - targetPosition: { x: lineEnd.x, y: lineEnd.y + 15 }, - }) await page.waitForTimeout(100) + await page.dragAndDrop('#stream', '#stream', { + 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) prevContent = await page.locator('.cm-content').innerText() - - // drag tangentialArcTo handle - const tangentEnd = await u.getBoundingBox('[data-overlay-index="1"]') - await page.dragAndDrop('#stream', '#stream', { - sourcePosition: { x: tangentEnd.x + 10, y: tangentEnd.y - 5 }, - targetPosition: { - x: tangentEnd.x, - y: tangentEnd.y - 15, - }, - }) - await page.waitForTimeout(100) - await expect(page.locator('.cm-content')).not.toHaveText(prevContent) - - // expect the code to have changed - await expect(page.locator('.cm-content')) - .toHaveText(`sketch001 = startSketchOn('XZ') - |> startProfileAt([7.12, -12.68], %) - |> line([12.68, -1.09], %) - |> tangentialArcTo([24.89, 0.68], %) + }) + + // 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 }, %) + `) }) + test('Can edit a sketch that has been extruded in the same pipe', async ({ page, homePage }) => { const u = await getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> startProfileAt([4.61, -10.01], %) + |> line([12.73, -0.09], %) + |> tangentialArcTo([24.95, -0.38], %) |> close(%) - |> extrude(5, %) -`) - }) - - test('Can edit a sketch that has been revolved in the same pipe', async ({ - page, - homePage, - }) => { - const u = await getUtils(page) - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([4.61, -14.01], %) - |> line([12.73, -0.09], %) - |> tangentialArcTo([24.95, -5.38], %) - |> close(%) - |> revolve({ axis = "X",}, %)` - ) - }) - - await homePage.goToModelingScene() - - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).not.toBeDisabled() - - await page.waitForTimeout(100) - await u.openAndClearDebugPanel() - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_look_at', - vantage: { x: 0, y: -1250, z: 580 }, - center: { x: 0, y: 0, z: 0 }, - up: { x: 0, y: 0, z: 1 }, - }, - }) - await page.waitForTimeout(100) - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_get_settings', - }, - }) - await page.waitForTimeout(100) - - const startPX = [665, 458] - - const dragPX = 30 - - await page.getByText('startProfileAt([4.61, -14.01], %)').click() - await expect( - page.getByRole('button', { name: 'Edit Sketch' }) - ).toBeVisible() - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(400) - let prevContent = await page.locator('.cm-content').innerText() - - const step5 = { steps: 5 } - - await expect(page.getByTestId('segment-overlay')).toHaveCount(2) - - // drag startProfieAt handle - await page.mouse.move(startPX[0], startPX[1]) - await page.mouse.down() - await page.mouse.move(startPX[0] + dragPX, startPX[1] - dragPX, step5) - await page.mouse.up() - - await expect(page.locator('.cm-content')).not.toHaveText(prevContent) - prevContent = await page.locator('.cm-content').innerText() - - // drag line handle - await page.waitForTimeout(100) - - const lineEnd = await u.getBoundingBox('[data-overlay-index="0"]') - await page.mouse.move(lineEnd.x - 5, lineEnd.y) - await page.mouse.down() - await page.mouse.move(lineEnd.x + dragPX, lineEnd.y - dragPX, step5) - await page.mouse.up() - await page.waitForTimeout(100) - await expect(page.locator('.cm-content')).not.toHaveText(prevContent) - prevContent = await page.locator('.cm-content').innerText() - - // drag tangentialArcTo handle - const tangentEnd = await u.getBoundingBox('[data-overlay-index="1"]') - await page.mouse.move(tangentEnd.x, tangentEnd.y - 5) - await page.mouse.down() - await page.mouse.move(tangentEnd.x + dragPX, tangentEnd.y - dragPX, step5) - await page.mouse.up() - await page.waitForTimeout(100) - await expect(page.locator('.cm-content')).not.toHaveText(prevContent) - - // expect the code to have changed - await expect(page.locator('.cm-content')) - .toHaveText(`sketch001 = startSketchOn('XZ') - |> startProfileAt([6.44, -12.07], %) - |> line([14.72, 1.97], %) - |> tangentialArcTo([24.95, -5.38], %) - |> line([1.97, 2.06], %) - |> close(%) - |> revolve({ axis = "X" }, %)`) - }) - test('Can add multiple sketches', async ({ page, homePage }) => { - const u = await getUtils(page) - - const viewportSize = { width: 1200, height: 500 } - await page.setViewportSize(viewportSize) - - await homePage.goToModelingScene() - await u.openDebugPanel() - - const center = { x: viewportSize.width / 2, y: viewportSize.height / 2 } - const { toSU, toU, click00r } = getMovementUtils({ center, page }) - - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).not.toBeDisabled() - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).toBeVisible() - - // click on "Start Sketch" button - await u.clearCommandLogs() - await u.doAndWaitForImageDiff( - () => page.getByRole('button', { name: 'Start Sketch' }).click(), - 200 + |> extrude(5, %)` ) - - let codeStr = "sketch001 = startSketchOn('XY')" - - await page.mouse.click(center.x, viewportSize.height * 0.55) - await expect(u.codeLocator).toHaveText(codeStr) - await u.closeDebugPanel() - await page.waitForTimeout(500) // TODO detect animation ending, or disable animation - - await click00r(0, 0) - codeStr += ` |> startProfileAt(${toSU([0, 0])}, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await click00r(50, 0) - await page.waitForTimeout(100) - codeStr += ` |> xLine(${toU(50, 0)[0]}, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await click00r(0, 50) - codeStr += ` |> yLine(${toU(0, 50)[1]}, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await click00r(-50, 0) - codeStr += ` |> xLine(${toU(-50, 0)[0]}, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - // exit the sketch, reset relative clicker - await click00r(undefined, undefined) - await u.openAndClearDebugPanel() - await page.getByRole('button', { name: 'Exit Sketch' }).click() - await u.expectCmdLog('[data-message-type="execution-done"]') - await page.waitForTimeout(250) - await u.clearCommandLogs() - - // start a new sketch - await page.getByRole('button', { name: 'Start Sketch' }).click() - - // 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 + 200, center.y + 100) - await page.waitForTimeout(600) // TODO detect animation ending, or disable animation - codeStr += "sketch002 = startSketchOn('XY')" - await expect(u.codeLocator).toHaveText(codeStr) - await u.closeDebugPanel() - - await click00r(30, 0) - codeStr += ` |> startProfileAt([2.03, 0], %)` - await expect(u.codeLocator).toHaveText(codeStr) - - // TODO: I couldn't use `toSU` here because of some rounding error causing - // it to be off by 0.01 - await click00r(30, 0) - codeStr += ` |> xLine(2.04, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await click00r(0, 30) - codeStr += ` |> yLine(-2.03, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await click00r(-30, 0) - codeStr += ` |> xLine(-2.04, %)` - await expect(u.codeLocator).toHaveText(codeStr) - - await 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 u.clearCommandLogs() }) + + await homePage.goToModelingScene() + + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).not.toBeDisabled() + + await page.waitForTimeout(100) + await u.openAndClearDebugPanel() + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_look_at', + vantage: { x: 0, y: -1250, z: 580 }, + center: { x: 0, y: 0, z: 0 }, + up: { x: 0, y: 0, z: 1 }, + }, + }) + await page.waitForTimeout(100) + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_get_settings', + }, + }) + await page.waitForTimeout(100) + + const startPX = [665, 397] + + const dragPX = 40 + + await page.getByText('startProfileAt([4.61, -10.01], %)').click() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).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(2) + + // drag startProfieAt handle + await page.dragAndDrop('#stream', '#stream', { + sourcePosition: { x: startPX[0], y: startPX[1] }, + targetPosition: { x: startPX[0] + dragPX, y: startPX[1] + dragPX }, + }) + await page.waitForTimeout(100) + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + prevContent = await page.locator('.cm-content').innerText() + + // drag line handle + await page.waitForTimeout(100) + + const lineEnd = await u.getBoundingBox('[data-overlay-index="0"]') + await page.dragAndDrop('#stream', '#stream', { + sourcePosition: { x: lineEnd.x - 15, y: lineEnd.y }, + targetPosition: { x: lineEnd.x, y: lineEnd.y + 15 }, + }) + await page.waitForTimeout(100) + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + prevContent = await page.locator('.cm-content').innerText() + + // drag tangentialArcTo handle + const tangentEnd = await u.getBoundingBox('[data-overlay-index="1"]') + await page.dragAndDrop('#stream', '#stream', { + sourcePosition: { x: tangentEnd.x + 10, y: tangentEnd.y - 5 }, + targetPosition: { + x: tangentEnd.x, + y: tangentEnd.y - 15, + }, + }) + await page.waitForTimeout(100) + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + + // expect the code to have changed + await expect(page.locator('.cm-content')) + .toHaveText(`sketch001 = startSketchOn('XZ') + |> startProfileAt([7.12, -12.68], %) + |> line([12.68, -1.09], %) + |> tangentialArcTo([24.89, 0.68], %) + |> close(%) + |> extrude(5, %) + `) }) + + test('Can edit a sketch that has been revolved in the same pipe', async ({ page, homePage }) => { const u = await getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> startProfileAt([4.61, -14.01], %) + |> line([12.73, -0.09], %) + |> tangentialArcTo([24.95, -5.38], %) + |> close(%) + |> revolve({ axis: "X",}, %)` + ) + }) + + await homePage.goToModelingScene() + + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).not.toBeDisabled() + + await page.waitForTimeout(100) + await u.openAndClearDebugPanel() + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_look_at', + vantage: { x: 0, y: -1250, z: 580 }, + center: { x: 0, y: 0, z: 0 }, + up: { x: 0, y: 0, z: 1 }, + }, + }) + await page.waitForTimeout(100) + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_get_settings', + }, + }) + await page.waitForTimeout(100) + + const startPX = [665, 458] + + const dragPX = 30 + + await page.getByText('startProfileAt([4.61, -14.01], %)').click() + await expect( + page.getByRole('button', { name: 'Edit Sketch' }) + ).toBeVisible() + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(400) + let prevContent = await page.locator('.cm-content').innerText() + + const step5 = { steps: 5 } + + await expect(page.getByTestId('segment-overlay')).toHaveCount(2) + + // drag startProfieAt handle + await page.mouse.move(startPX[0], startPX[1]) + await page.mouse.down() + await page.mouse.move(startPX[0] + dragPX, startPX[1] - dragPX, step5) + await page.mouse.up() + + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + prevContent = await page.locator('.cm-content').innerText() + + // drag line handle + await page.waitForTimeout(100) + + const lineEnd = await u.getBoundingBox('[data-overlay-index="0"]') + await page.mouse.move(lineEnd.x - 5, lineEnd.y) + await page.mouse.down() + await page.mouse.move(lineEnd.x + dragPX, lineEnd.y - dragPX, step5) + await page.mouse.up() + await page.waitForTimeout(100) + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + prevContent = await page.locator('.cm-content').innerText() + + // drag tangentialArcTo handle + const tangentEnd = await u.getBoundingBox('[data-overlay-index="1"]') + await page.mouse.move(tangentEnd.x, tangentEnd.y - 5) + await page.mouse.down() + await page.mouse.move(tangentEnd.x + dragPX, tangentEnd.y - dragPX, step5) + await page.mouse.up() + await page.waitForTimeout(100) + await expect(page.locator('.cm-content')).not.toHaveText(prevContent) + + // expect the code to have changed + await expect(page.locator('.cm-content')) + .toHaveText(`sketch001 = startSketchOn('XZ') + |> startProfileAt([6.44, -12.07], %) + |> line([14.72, 1.97], %) + |> tangentialArcTo([24.95, -5.38], %) + |> line([1.97, 2.06], %) + |> close(%) + |> revolve({ axis: "X" }, %)`) }) + test('Can add multiple sketches', async ({ page, homePage }) => { const u = await getUtils(page) + + const viewportSize = { width: 1200, height: 500 } + await page.setBodyDimensions(viewportSize) + + await homePage.goToModelingScene() + await u.openDebugPanel() + + const center = { x: viewportSize.width / 2, y: viewportSize.height / 2 } + const { toSU, toU, click00r } = getMovementUtils({ center, page }) + + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).not.toBeDisabled() + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).toBeVisible() + + // click on "Start Sketch" button + await u.clearCommandLogs() + await u.doAndWaitForImageDiff( + () => page.getByRole('button', { name: 'Start Sketch' }).click(), + 200 + ) + + let codeStr = "sketch001 = startSketchOn('XY')" + + await page.mouse.click(center.x, viewportSize.height * 0.55) + await expect(u.codeLocator).toHaveText(codeStr) + await u.closeDebugPanel() + await page.waitForTimeout(500) // TODO detect animation ending, or disable animation + + await click00r(0, 0) + codeStr += ` |> startProfileAt(${toSU([0, 0])}, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await click00r(50, 0) + await page.waitForTimeout(100) + codeStr += ` |> xLine(${toU(50, 0)[0]}, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await click00r(0, 50) + codeStr += ` |> yLine(${toU(0, 50)[1]}, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await click00r(-50, 0) + codeStr += ` |> xLine(${toU(-50, 0)[0]}, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + // exit the sketch, reset relative clicker + await click00r(undefined, undefined) + await u.openAndClearDebugPanel() + await page.getByRole('button', { name: 'Exit Sketch' }).click() + await u.expectCmdLog('[data-message-type="execution-done"]') + await page.waitForTimeout(250) + await u.clearCommandLogs() + + // start a new sketch + await page.getByRole('button', { name: 'Start Sketch' }).click() + + // 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 + 200, center.y + 100) + await page.waitForTimeout(600) // TODO detect animation ending, or disable animation + codeStr += "sketch002 = startSketchOn('XY')" + await expect(u.codeLocator).toHaveText(codeStr) + await u.closeDebugPanel() + + await click00r(30, 0) + codeStr += ` |> startProfileAt([2.03, 0], %)` + await expect(u.codeLocator).toHaveText(codeStr) + + // TODO: I couldn't use `toSU` here because of some rounding error causing + // it to be off by 0.01 + await click00r(30, 0) + codeStr += ` |> xLine(2.04, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await click00r(0, 30) + codeStr += ` |> yLine(-2.03, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await click00r(-30, 0) + codeStr += ` |> xLine(-2.04, %)` + await expect(u.codeLocator).toHaveText(codeStr) + + await 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 u.clearCommandLogs() }) test.describe('Snap to close works (at any scale)', () => { const doSnapAtDifferentScales = async ( page: any, @@ -736,9 +702,9 @@ test.describe('Sketch tests', () => { scale = 1 ) => { const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) + await page.setBodyDimensions({ width: 1200, height: 500 }) - await u.openDebugPanel() + await u.openDebugPanel() const code = `sketch001 = startSketchOn('-XZ') |> startProfileAt([${roundOff(scale * 69.6)}, ${roundOff(scale * 34.8)}], %) @@ -819,494 +785,364 @@ test.describe('Sketch tests', () => { await u.expectCmdLog('[data-message-type="execution-done"]') await u.removeCurrentCode() } - test('[0, 100, 100]', async ({ page, homePage }) => { - await homePage.goToModelingScene() - await doSnapAtDifferentScales(page, [0, 100, 100], 0.01) - }) + test('[0, 100, 100]', async ({ page, homePage }) => { await homePage.goToModelingScene() + await doSnapAtDifferentScales(page, [0, 100, 100], 0.01) }) - test('[0, 10000, 10000]', async ({ page, homePage }) => { - await homePage.goToModelingScene() - await doSnapAtDifferentScales(page, [0, 10000, 10000]) - }) + test('[0, 10000, 10000]', async ({ page, homePage }) => { await homePage.goToModelingScene() + await doSnapAtDifferentScales(page, [0, 10000, 10000]) }) }) - test('exiting a close extrude, has the extrude button enabled ready to go', async ({ - page, - homePage, - }) => { - // this was a regression https://github.com/KittyCAD/modeling-app/issues/2832 - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([-0.45, 0.87], %) - |> line([1.32, 0.38], %) - |> line([1.02, -1.32], %, $seg01) - |> line([-1.01, -0.77], %) - |> lineTo([profileStartX(%), profileStartY(%)], %) -|> close(%) -` - ) - }) - - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - // click "line([1.32, 0.38], %)" - await page.getByText(`line([1.32, 0.38], %)`).click() - await page.waitForTimeout(100) - await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeEnabled( - { timeout: 10_000 } - ) - // click edit sketch - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(600) // wait for animation - - // exit sketch - await page.getByRole('button', { name: 'Exit Sketch' }).click() - - // expect extrude button to be enabled - await expect( - page.getByRole('button', { name: 'Extrude' }) - ).not.toBeDisabled() - - // click extrude - await page.getByRole('button', { name: 'Extrude' }).click() - - // sketch selection should already have been made. "Selection: 1 face" only show up when the selection has been made already - // otherwise the cmdbar would be waiting for a selection. - await expect( - page.getByRole('button', { name: 'selection : 1 face', exact: false }) - ).toBeVisible({ - timeout: 10_000, - }) - }) - test("Existing sketch with bad code delete user's code", async ({ page, homePage }) => { - // this was a regression https://github.com/KittyCAD/modeling-app/issues/2832 - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([-0.45, 0.87], %) - |> line([1.32, 0.38], %) - |> line([1.02, -1.32], %, $seg01) - |> line([-1.01, -0.77], %) - |> lineTo([profileStartX(%), profileStartY(%)], %) - |> close(%) -extrude001 = extrude(5, sketch001) -` - ) - }) - - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByRole('button', { name: 'Start Sketch' }).click() - - await page.mouse.click(622, 355) - - await page.waitForTimeout(800) - await page.getByText(`END')`).click() - await page.keyboard.press('End') - await page.keyboard.press('Enter') - await page.keyboard.type(' |>', { delay: 100 }) - await page.waitForTimeout(100) - await expect(page.locator('.cm-lint-marker-error')).toBeVisible() - - await page.getByRole('button', { name: 'Exit Sketch' }).click() - - await expect( - page.getByRole('button', { name: 'Start Sketch' }) - ).toBeVisible() - - await expect((await u.codeLocator.innerText()).replace(/\s/g, '')).toBe( + test('exiting a close extrude, has the extrude button enabled ready to go', async ({ page, homePage }) => { // this was a regression https://github.com/KittyCAD/modeling-app/issues/2832 + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', `sketch001 = startSketchOn('XZ') - |> startProfileAt([-0.45, 0.87], %) - |> line([1.32, 0.38], %) - |> line([1.02, -1.32], %, $seg01) - |> line([-1.01, -0.77], %) - |> lineTo([profileStartX(%), profileStartY(%)], %) + |> startProfileAt([-0.45, 0.87], %) + |> line([1.32, 0.38], %) + |> line([1.02, -1.32], %, $seg01) + |> line([-1.01, -0.77], %) + |> lineTo([profileStartX(%), profileStartY(%)], %) |> close(%) -extrude001 = extrude(5, sketch001) -sketch002 = startSketchOn(extrude001, 'END') - |> -`.replace(/\s/g, '') + ` ) }) - - /* TODO: once we fix bug turn on. - test('empty-scene default-planes act as expected when spaces in file', async ({ - page, - browserName, - }) => { - - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await u.waitForAuthSkipAppStart() - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - const XYPlanePoint = { x: 774, y: 116 } as const - const unHoveredColor: [number, number, number] = [47, 47, 93] - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - - // color should not change for having been hovered - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await u.openAndClearDebugPanel() - - // Fill with spaces - await u.codeLocator.fill(` -`) - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - - // color should not change for having been hovered - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) + + const u = await getUtils(page) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // click "line([1.32, 0.38], %)" + await page.getByText(`line([1.32, 0.38], %)`).click() + await page.waitForTimeout(100) + await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeEnabled( + { timeout: 10_000 } + ) + // click edit sketch + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(600) // wait for animation + + // exit sketch + await page.getByRole('button', { name: 'Exit Sketch' }).click() + + // expect extrude button to be enabled + await expect( + page.getByRole('button', { name: 'Extrude' }) + ).not.toBeDisabled() + + // click extrude + await page.getByRole('button', { name: 'Extrude' }).click() + + // sketch selection should already have been made. "Selection: 1 face" only show up when the selection has been made already + // otherwise the cmdbar would be waiting for a selection. + await expect( + page.getByRole('button', { name: 'selection : 1 face', exact: false }) + ).toBeVisible({ + timeout: 10_000, + }) }) + test("Existing sketch with bad code delete user's code", async ({ page, homePage }) => { // this was a regression https://github.com/KittyCAD/modeling-app/issues/2832 + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> startProfileAt([-0.45, 0.87], %) + |> line([1.32, 0.38], %) + |> line([1.02, -1.32], %, $seg01) + |> line([-1.01, -0.77], %) + |> lineTo([profileStartX(%), profileStartY(%)], %) + |> close(%) + extrude001 = extrude(5, sketch001) + ` + ) }) - - test('empty-scene default-planes act as expected when only code comments in file', async ({ - page, - browserName, - }) => { - - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await u.waitForAuthSkipAppStart() - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - const XYPlanePoint = { x: 774, y: 116 } as const - const unHoveredColor: [number, number, number] = [47, 47, 93] - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - - // color should not change for having been hovered - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await u.openAndClearDebugPanel() - - // Fill with spaces - await u.codeLocator.fill(`// this is a code comments ya nerds -`) - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - - // color should not change for having been hovered - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - })*/ - - test('empty-scene default-planes act as expected', async ({ - page, - homePage, - }) => { - /** - * Tests the following things - * 1) The the planes are there on load because the scene is empty - * 2) The planes don't changes color when hovered initially - * 3) Putting something in the scene makes the planes hidden - * 4) Removing everything from the scene shows the plans again - * 3) Once "start sketch" is click, the planes do respond to hovers - * 4) Selecting a plan works as expected, i.e. sketch mode - * 5) Reloading the scene with something already in the scene means the planes are hidden - */ - - const u = await getUtils(page) - await homePage.goToModelingScene() - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - const XYPlanePoint = { x: 774, y: 116 } as const - const unHoveredColor: [number, number, number] = [47, 47, 93] - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - - // color should not change for having been hovered - expect( - await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) - ).toBeLessThan(8) - - await u.openAndClearDebugPanel() - - await u.codeLocator.fill(`sketch001 = startSketchOn('XY') - |> startProfileAt([-10, -10], %) - |> line([20, 0], %) - |> line([0, 20], %) - |> xLine(-20, %) -`) - - await u.expectCmdLog('[data-message-type="execution-done"]') - - const noPlanesColor: [number, number, number] = [30, 30, 30] - expect( - await u.getGreatestPixDiff(XYPlanePoint, noPlanesColor) - ).toBeLessThan(3) - - await u.clearCommandLogs() - await u.removeCurrentCode() - await u.expectCmdLog('[data-message-type="execution-done"]') - - await expect - .poll(() => u.getGreatestPixDiff(XYPlanePoint, unHoveredColor), { - timeout: 5_000, - }) - .toBeLessThan(8) - - // click start Sketch - await page.getByRole('button', { name: 'Start Sketch' }).click() - await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y, { steps: 50 }) - const hoveredColor: [number, number, number] = [93, 93, 127] - // now that we're expecting the user to select a plan, it does respond to hover - await expect - .poll(() => u.getGreatestPixDiff(XYPlanePoint, hoveredColor)) - .toBeLessThan(8) - - await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(600) - - await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y) - await page.waitForTimeout(200) - await page.mouse.click(XYPlanePoint.x + 50, XYPlanePoint.y + 50) - await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') - |> startProfileAt([11.8, 9.09], %) - |> line([3.39, -3.39], %) -`) - - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `sketch001 = startSketchOn('XZ') - |> startProfileAt([11.8, 9.09], %) - |> line([3.39, -3.39], %) -` - ) + + const u = await getUtils(page) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByRole('button', { name: 'Start Sketch' }).click() + + await page.mouse.click(622, 355) + + await page.waitForTimeout(800) + await page.getByText(`END')`).click() + await page.keyboard.press('End') + await page.keyboard.press('Enter') + await page.keyboard.type(' |>', { delay: 100 }) + await page.waitForTimeout(100) + await expect(page.locator('.cm-lint-marker-error')).toBeVisible() + + await page.getByRole('button', { name: 'Exit Sketch' }).click() + + await expect( + page.getByRole('button', { name: 'Start Sketch' }) + ).toBeVisible() + + await expect((await u.codeLocator.innerText()).replace(/\s/g, '')).toBe( + `sketch001 = startSketchOn('XZ') + |> startProfileAt([-0.45, 0.87], %) + |> line([1.32, 0.38], %) + |> line([1.02, -1.32], %, $seg01) + |> line([-1.01, -0.77], %) + |> lineTo([profileStartX(%), profileStartY(%)], %) + |> close(%) + extrude001 = extrude(5, sketch001) + sketch002 = startSketchOn(extrude001, 'END') + |> + `.replace(/\s/g, '') + ) }) + test('empty-scene default-planes act as expected', async ({ page, homePage }) => { /** + * Tests the following things + * 1) The the planes are there on load because the scene is empty + * 2) The planes don't changes color when hovered initially + * 3) Putting something in the scene makes the planes hidden + * 4) Removing everything from the scene shows the plans again + * 3) Once "start sketch" is click, the planes do respond to hovers + * 4) Selecting a plan works as expected, i.e. sketch mode + * 5) Reloading the scene with something already in the scene means the planes are hidden + */ + + const u = await getUtils(page) + await homePage.goToModelingScene() + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + const XYPlanePoint = { x: 774, y: 116 } as const + const unHoveredColor: [number, number, number] = [47, 47, 93] + expect( + await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) + ).toBeLessThan(8) + + await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) + await page.waitForTimeout(200) + + // color should not change for having been hovered + expect( + await u.getGreatestPixDiff(XYPlanePoint, unHoveredColor) + ).toBeLessThan(8) + + await u.openAndClearDebugPanel() + + await u.codeLocator.fill(`sketch001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> xLine(-20, %) + `) + + await u.expectCmdLog('[data-message-type="execution-done"]') + + const noPlanesColor: [number, number, number] = [30, 30, 30] + expect( + await u.getGreatestPixDiff(XYPlanePoint, noPlanesColor) + ).toBeLessThan(3) + + await u.clearCommandLogs() + await u.removeCurrentCode() + await u.expectCmdLog('[data-message-type="execution-done"]') + + await expect + .poll(() => u.getGreatestPixDiff(XYPlanePoint, unHoveredColor), { + timeout: 5_000, }) - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - // expect there to be no planes on load since there's something in the scene - expect( - await u.getGreatestPixDiff(XYPlanePoint, noPlanesColor) - ).toBeLessThan(3) + .toBeLessThan(8) + + // click start Sketch + await page.getByRole('button', { name: 'Start Sketch' }).click() + await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y, { steps: 50 }) + const hoveredColor: [number, number, number] = [93, 93, 127] + // now that we're expecting the user to select a plan, it does respond to hover + await expect + .poll(() => u.getGreatestPixDiff(XYPlanePoint, hoveredColor)) + .toBeLessThan(8) + + await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y) + await page.waitForTimeout(600) + + await page.mouse.click(XYPlanePoint.x, XYPlanePoint.y) + await page.waitForTimeout(200) + await page.mouse.click(XYPlanePoint.x + 50, XYPlanePoint.y + 50) + await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') + |> startProfileAt([11.8, 9.09], %) + |> line([3.39, -3.39], %) + `) + + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `sketch001 = startSketchOn('XZ') + |> startProfileAt([11.8, 9.09], %) + |> line([3.39, -3.39], %) + ` + ) }) + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // expect there to be no planes on load since there's something in the scene + expect( + await u.getGreatestPixDiff(XYPlanePoint, noPlanesColor) + ).toBeLessThan(3) }) - test('Can attempt to sketch on revolved face', async ({ - page, - homePage, - }) => { - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `lugHeadLength = 0.25 - lugDiameter = 0.5 - lugLength = 2 - - fn lug = (origin, length, diameter, plane) => { - lugSketch = startSketchOn(plane) - |> startProfileAt([origin[0] + lugDiameter / 2, origin[1]], %) - |> angledLineOfYLength({ angle = 60, length = lugHeadLength }, %) - |> xLineTo(0 + .001, %) - |> yLineTo(0, %) - |> close(%) - |> revolve({ axis = "Y" }, %) - - return lugSketch - } - - lug([0, 0], 10, .5, "XY")` - ) - }) - - await homePage.goToModelingScene() - - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - /*** - * Test Plan - * Start the sketch mode - * Click the middle of the screen which should click the top face that is revolved - * Wait till you see the line tool be enabled - * Wait till you see the exit sketch enabled - * - * This is supposed to test that you are allowed to go into sketch mode to sketch on a revolved face - */ - - await page.getByRole('button', { name: 'Start Sketch' }).click() - - await expect(async () => { - await page.mouse.click(600, 250) - await page.waitForTimeout(1000) - await expect( - page.getByRole('button', { name: 'Exit Sketch' }) - ).toBeVisible() - await expect( - page.getByRole('button', { name: 'line Line', exact: true }) - ).toHaveAttribute('aria-pressed', 'true') - }).toPass({ timeout: 40_000, intervals: [1_000] }) + test('Can attempt to sketch on revolved face', async ({ page, homePage }) => { const u = await getUtils(page) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `lugHeadLength = 0.25 + lugDiameter = 0.5 + lugLength = 2 + + fn lug = (origin, length, diameter, plane) => { + lugSketch = startSketchOn(plane) + |> startProfileAt([origin[0] + lugDiameter / 2, origin[1]], %) + |> angledLineOfYLength({ angle: 60, length: lugHeadLength }, %) + |> xLineTo(0 + .001, %) + |> yLineTo(0, %) + |> close(%) + |> revolve({ axis: "Y" }, %) + + return lugSketch + } + + lug([0, 0], 10, .5, "XY")` + ) }) - - test('Can sketch on face when user defined function was used in the sketch', async ({ - page, - homePage, - }) => { - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - // Checking for a regression that performs a sketch when a user defined function - // is declared at the top of the file and used in the sketch that is being drawn on. - // fn in2mm is declared at the top of the file and used rail which does a an extrusion with the function. - - await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `fn in2mm = (inches) => { - return inches * 25.4 -} - -const railTop = in2mm(.748) -const railSide = in2mm(.024) -const railBaseWidth = in2mm(.612) -const railWideWidth = in2mm(.835) -const railBaseLength = in2mm(.200) -const railClampable = in2mm(.200) - -const rail = startSketchOn('XZ') - |> startProfileAt([ - -railTop / 2, - railClampable + railBaseLength - ], %) - |> lineTo([ - railTop / 2, - railClampable + railBaseLength - ], %) - |> lineTo([ - railWideWidth / 2, - railClampable / 2 + railBaseLength - ], %, $seg01) - |> lineTo([railTop / 2, railBaseLength], %) - |> lineTo([railBaseWidth / 2, railBaseLength], %) - |> lineTo([railBaseWidth / 2, 0], %) - |> lineTo([-railBaseWidth / 2, 0], %) - |> lineTo([-railBaseWidth / 2, railBaseLength], %) - |> lineTo([-railTop / 2, railBaseLength], %) - |> lineTo([ - -railWideWidth / 2, - railClampable / 2 + railBaseLength - ], %) - |> lineTo([ - -railTop / 2, - railClampable + railBaseLength - ], %) - |> close(%) - |> extrude(in2mm(2), %)` - ) - }) - - const center = { x: 600, y: 250 } - const rectangleSize = 20 - await homePage.goToModelingScene() - - // Start a sketch - await page.getByRole('button', { name: 'Start Sketch' }).click() - - // Click the top face of this rail - await page.mouse.click(center.x, center.y) + + await homePage.goToModelingScene() + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + /*** + * Test Plan + * Start the sketch mode + * Click the middle of the screen which should click the top face that is revolved + * Wait till you see the line tool be enabled + * Wait till you see the exit sketch enabled + * + * This is supposed to test that you are allowed to go into sketch mode to sketch on a revolved face + */ + + await page.getByRole('button', { name: 'Start Sketch' }).click() + + await expect(async () => { + await page.mouse.click(600, 250) await page.waitForTimeout(1000) + await expect( + page.getByRole('button', { name: 'Exit Sketch' }) + ).toBeVisible() + await expect( + page.getByRole('button', { name: 'line Line', exact: true }) + ).toHaveAttribute('aria-pressed', 'true') + }).toPass({ timeout: 40_000, intervals: [1_000] }) }) - // Draw a rectangle - // top left - await page.mouse.click(center.x - rectangleSize, center.y - rectangleSize) - await page.waitForTimeout(250) - // top right - await page.mouse.click(center.x + rectangleSize, center.y - rectangleSize) - await page.waitForTimeout(250) - - // bottom right - await page.mouse.click(center.x + rectangleSize, center.y + rectangleSize) - await page.waitForTimeout(250) - - // bottom left - await page.mouse.click(center.x - rectangleSize, center.y + rectangleSize) - await page.waitForTimeout(250) - - // top left - await page.mouse.click(center.x - rectangleSize, center.y - rectangleSize) - await page.waitForTimeout(250) - - // exit sketch - await page.getByRole('button', { name: 'Exit Sketch' }).click() - - // Check execution is done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() + test('Can sketch on face when user defined function was used in the sketch', async ({ page, homePage }) => { const u = await getUtils(page) + await page.setBodyDimensions({ width: 1200, height: 500 }) + + // Checking for a regression that performs a sketch when a user defined function + // is declared at the top of the file and used in the sketch that is being drawn on. + // fn in2mm is declared at the top of the file and used rail which does a an extrusion with the function. + + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `fn in2mm = (inches) => { + return inches * 25.4 + } + + const railTop = in2mm(.748) + const railSide = in2mm(.024) + const railBaseWidth = in2mm(.612) + const railWideWidth = in2mm(.835) + const railBaseLength = in2mm(.200) + const railClampable = in2mm(.200) + + const rail = startSketchOn('XZ') + |> startProfileAt([ + -railTop / 2, + railClampable + railBaseLength + ], %) + |> lineTo([ + railTop / 2, + railClampable + railBaseLength + ], %) + |> lineTo([ + railWideWidth / 2, + railClampable / 2 + railBaseLength + ], %, $seg01) + |> lineTo([railTop / 2, railBaseLength], %) + |> lineTo([railBaseWidth / 2, railBaseLength], %) + |> lineTo([railBaseWidth / 2, 0], %) + |> lineTo([-railBaseWidth / 2, 0], %) + |> lineTo([-railBaseWidth / 2, railBaseLength], %) + |> lineTo([-railTop / 2, railBaseLength], %) + |> lineTo([ + -railWideWidth / 2, + railClampable / 2 + railBaseLength + ], %) + |> lineTo([ + -railTop / 2, + railClampable + railBaseLength + ], %) + |> close(%) + |> extrude(in2mm(2), %)` + ) }) + + const center = { x: 600, y: 250 } + const rectangleSize = 20 + await homePage.goToModelingScene() + + // Start a sketch + await page.getByRole('button', { name: 'Start Sketch' }).click() + + // Click the top face of this rail + await page.mouse.click(center.x, center.y) + await page.waitForTimeout(1000) + + // Draw a rectangle + // top left + await page.mouse.click(center.x - rectangleSize, center.y - rectangleSize) + await page.waitForTimeout(250) + // top right + await page.mouse.click(center.x + rectangleSize, center.y - rectangleSize) + await page.waitForTimeout(250) + + // bottom right + await page.mouse.click(center.x + rectangleSize, center.y + rectangleSize) + await page.waitForTimeout(250) + + // bottom left + await page.mouse.click(center.x - rectangleSize, center.y + rectangleSize) + await page.waitForTimeout(250) + + // top left + await page.mouse.click(center.x - rectangleSize, center.y - rectangleSize) + await page.waitForTimeout(250) + + // exit sketch + await page.getByRole('button', { name: 'Exit Sketch' }).click() + + // Check execution is done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() }) }) test.describe('Sketch mode should be toleratant to syntax errors', () => { @@ -1314,7 +1150,14 @@ test.describe('Sketch mode should be toleratant to syntax errors', () => { 'adding a syntax error, recovers after fixing', { tag: ['@skipWin'] }, async ({ page, homePage, context, scene, editor, toolbar }) => { - const file = await fs.readFile(path.resolve(__dirname, '../../', './src/wasm-lib/tests/executor/inputs/e2e-can-sketch-on-chamfer.kcl'), 'utf-8') + const file = await fs.readFile( + path.resolve( + __dirname, + '../../', + './src/wasm-lib/tests/executor/inputs/e2e-can-sketch-on-chamfer.kcl' + ), + 'utf-8' + ) await context.addInitScript((file) => { localStorage.setItem('persistCode', file) }, file) @@ -1369,19 +1212,26 @@ test.describe('Sketch mode should be toleratant to syntax errors', () => { ) }) -test2.describe(`Sketching with offset planes`, () => { - test2( +test.describe(`Sketching with offset planes`, () => { + test( `Can select an offset plane to sketch on`, - async ({ app, scene, toolbar, editor }) => { + async ({ context, page, scene, toolbar, editor, homePage }) => { // We seed the scene with a single offset plane - await app.initialise(`offsetPlane001 = offsetPlane("XY", 10)`) + await context.addInitScript(() => { + localStorage.setItem( + 'persistCode', + `offsetPlane001 = offsetPlane("XY", 10)` + ) + }) + + homePage.goToModelingScene() const [planeClick, planeHover] = scene.makeMouseHelpers(650, 200) - await test2.step(`Start sketching on the offset plane`, async () => { + await test.step(`Start sketching on the offset plane`, async () => { await toolbar.startSketchPlaneSelection() - await test2.step(`Hovering should highlight code`, async () => { + await test.step(`Hovering should highlight code`, async () => { await planeHover() await editor.expectState({ activeLines: [`offsetPlane001=offsetPlane("XY",10)`], @@ -1390,13 +1240,13 @@ test2.describe(`Sketching with offset planes`, () => { }) }) - await test2.step( + await test.step( `Clicking should select the plane and enter sketch mode`, async () => { await planeClick() // Have to wait for engine-side animation to finish - await app.page.waitForTimeout(600) - await expect2(toolbar.lineBtn).toBeEnabled() + await page.waitForTimeout(600) + await expect(toolbar.lineBtn).toBeEnabled() await editor.expectEditor.toContain('startSketchOn(offsetPlane001)') await editor.expectState({ activeLines: [`offsetPlane001=offsetPlane("XY",10)`], diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index d7934dced..e63e7a301 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -416,6 +416,10 @@ export async function getUtils(page: Page, test_?: typeof test) { .boundingBox({ timeout: 5_000 }) .then((box) => ({ ...box, x: box?.x || 0, y: box?.y || 0 })), codeLocator: page.locator('.cm-content'), + crushKclCodeIntoOneLineAndThenMaybeSome: async () => { + const code = await page.locator('.cm-content').innerText() + return code.replaceAll(' ', '').replaceAll("\n", '') + }, normalisedEditorCode: async () => { const code = await page.locator('.cm-content').innerText() return normaliseKclNumbers(code) diff --git a/e2e/playwright/testing-segment-overlays.spec.ts b/e2e/playwright/testing-segment-overlays.spec.ts index 039b436c0..2d94fbfae 100644 --- a/e2e/playwright/testing-segment-overlays.spec.ts +++ b/e2e/playwright/testing-segment-overlays.spec.ts @@ -1,6 +1,6 @@ import { test, expect, Page } from './zoo-test' -import { deg, getUtils, wiggleMove } from './test-utils' +import { deg, getUtils, wiggleMove } from './test-utils' import { LineInputsType } from 'lang/std/sketchcombos' import { uuidv4 } from 'lib/utils' @@ -182,11 +182,14 @@ test.describe('Testing segment overlays', () => { await expect(page.locator('.cm-content')).toContainText(expectFinal) } test.setTimeout(120000) - - test('for segments [line, angledLine, lineTo, xLineTo]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test('for segments [line, angledLine, lineTo, xLineTo]', async ({ + page, + homePage, + }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([5 + 0, 20 + 0], %) |> line([0.5, -14 + 0], %) |> angledLine({ angle: 3 + 0, length: 32 + 0 }, %) @@ -206,146 +209,148 @@ test.describe('Testing segment overlays', () => { }, %) |> tangentialArcTo([5 + 3.14 + 13, 20 + 3.14], %) ` - ) + ) + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText('xLineTo(5 + 9 - 5, %)').click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(13) + + const clickUnconstrained = _clickUnconstrained(page) + const clickConstrained = _clickConstrained(page) + + await u.openAndClearDebugPanel() + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_look_at', + vantage: { x: 80, y: -1350, z: 510 }, + center: { x: 80, y: 0, z: 510 }, + up: { x: 0, y: 0, z: 1 }, + }, + }) + await page.waitForTimeout(100) + await u.sendCustomCmd({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + type: 'default_camera_get_settings', + }, + }) + await page.waitForTimeout(100) + await u.closeDebugPanel() + + let ang = 0 + + const line = await u.getBoundingBox(`[data-overlay-index="${0}"]`) + ang = await u.getAngle(`[data-overlay-index="${0}"]`) + console.log('line1', line, ang) + await clickConstrained({ + 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: ang + 180, + locator: '[data-overlay-toolbar-index="0"]', + }) + console.log('line2') + await clickUnconstrained({ + hoverPos: { x: line.x, y: line.y }, + constraintType: 'xRelative', + expectBeforeUnconstrained: '|> line([0.5, yRel001], %)', + expectAfterUnconstrained: 'line([xRel001, yRel001], %)', + expectFinal: '|> line([0.5, yRel001], %)', + ang: ang + 180, + locator: '[data-overlay-index="0"]', + }) + + 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, 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, + locator: '[data-overlay-toolbar-index="1"]', + }) + console.log('angledLine2') + await clickConstrained({ + 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, + locator: '[data-overlay-toolbar-index="1"]', + }) + + await page.mouse.move(700, 250) + await page.waitForTimeout(100) + + let 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 }, + constraintType: 'yAbsolute', + expectBeforeUnconstrained: 'lineTo([5 + 33, 20 + 11.5 + 0], %)', + expectAfterUnconstrained: 'lineTo([5 + 33, 31.5], %)', + expectFinal: 'lineTo([5 + 33, yAbs001], %)', + steps: 8, + ang: ang + 180, + locator: '[data-overlay-toolbar-index="2"]', + }) + console.log('lineTo2') + await clickConstrained({ + hoverPos: { x: lineTo.x, y: lineTo.y }, + constraintType: 'xAbsolute', + expectBeforeUnconstrained: 'lineTo([5 + 33, yAbs001], %)', + expectAfterUnconstrained: 'lineTo([38, yAbs001], %)', + expectFinal: 'lineTo([xAbs001, yAbs001], %)', + steps: 8, + ang: ang + 180, + locator: '[data-overlay-toolbar-index="2"]', + }) + + 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, y: xLineTo.y }, + constraintType: 'xAbsolute', + expectBeforeUnconstrained: 'xLineTo(5 + 9 - 5, %)', + expectAfterUnconstrained: 'xLineTo(9, %)', + expectFinal: 'xLineTo(xAbs002, %)', + ang: ang + 180, + steps: 8, + locator: '[data-overlay-toolbar-index="3"]', + }) }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText('xLineTo(5 + 9 - 5, %)').click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(13) - - const clickUnconstrained = _clickUnconstrained(page) - const clickConstrained = _clickConstrained(page) - - await u.openAndClearDebugPanel() - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_look_at', - vantage: { x: 80, y: -1350, z: 510 }, - center: { x: 80, y: 0, z: 510 }, - up: { x: 0, y: 0, z: 1 }, - }, - }) - await page.waitForTimeout(100) - await u.sendCustomCmd({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd: { - type: 'default_camera_get_settings', - }, - }) - await page.waitForTimeout(100) - await u.closeDebugPanel() - - let ang = 0 - - const line = await u.getBoundingBox(`[data-overlay-index="${0}"]`) - ang = await u.getAngle(`[data-overlay-index="${0}"]`) - console.log('line1', line, ang) - await clickConstrained({ - 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: ang + 180, - locator: '[data-overlay-toolbar-index="0"]', - }) - console.log('line2') - await clickUnconstrained({ - hoverPos: { x: line.x, y: line.y }, - constraintType: 'xRelative', - expectBeforeUnconstrained: '|> line([0.5, yRel001], %)', - expectAfterUnconstrained: 'line([xRel001, yRel001], %)', - expectFinal: '|> line([0.5, yRel001], %)', - ang: ang + 180, - locator: '[data-overlay-index="0"]', - }) - - 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, 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, - locator: '[data-overlay-toolbar-index="1"]', - }) - console.log('angledLine2') - await clickConstrained({ - 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, - locator: '[data-overlay-toolbar-index="1"]', - }) - - await page.mouse.move(700, 250) - await page.waitForTimeout(100) - - let 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 }, - constraintType: 'yAbsolute', - expectBeforeUnconstrained: 'lineTo([5 + 33, 20 + 11.5 + 0], %)', - expectAfterUnconstrained: 'lineTo([5 + 33, 31.5], %)', - expectFinal: 'lineTo([5 + 33, yAbs001], %)', - steps: 8, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="2"]', - }) - console.log('lineTo2') - await clickConstrained({ - hoverPos: { x: lineTo.x, y: lineTo.y }, - constraintType: 'xAbsolute', - expectBeforeUnconstrained: 'lineTo([5 + 33, yAbs001], %)', - expectAfterUnconstrained: 'lineTo([38, yAbs001], %)', - expectFinal: 'lineTo([xAbs001, yAbs001], %)', - steps: 8, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="2"]', - }) - - 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, y: xLineTo.y }, - constraintType: 'xAbsolute', - expectBeforeUnconstrained: 'xLineTo(5 + 9 - 5, %)', - expectAfterUnconstrained: 'xLineTo(9, %)', - expectFinal: 'xLineTo(xAbs002, %)', - ang: ang + 180, - steps: 8, - locator: '[data-overlay-toolbar-index="3"]', - }) }) - test('for segments [yLineTo, xLine]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `yRel001 = -14 + test('for segments [yLineTo, xLine]', async ({ page, homePage }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `yRel001 = -14 xRel001 = 0.5 angle001 = 3 len001 = 32 @@ -363,62 +368,67 @@ test.describe('Testing segment overlays', () => { |> yLine(21.14 + 0, %) |> angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %) ` - ) + ) + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText('xLine(26.04, %)').click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(8) + + const clickUnconstrained = _clickUnconstrained(page) + + await page.mouse.move(700, 250) + await page.waitForTimeout(100) + + 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 }, + constraintType: 'yAbsolute', + expectBeforeUnconstrained: 'yLineTo(-10.77, %, $a)', + expectAfterUnconstrained: 'yLineTo(yAbs002, %, $a)', + expectFinal: 'yLineTo(-10.77, %, $a)', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="4"]', + }) + + 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, y: xLine.y }, + constraintType: 'xRelative', + expectBeforeUnconstrained: 'xLine(26.04, %)', + expectAfterUnconstrained: 'xLine(xRel002, %)', + expectFinal: 'xLine(26.04, %)', + steps: 10, + ang: ang + 180, + locator: '[data-overlay-toolbar-index="5"]', + }) }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText('xLine(26.04, %)').click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(8) - - const clickUnconstrained = _clickUnconstrained(page) - - await page.mouse.move(700, 250) - await page.waitForTimeout(100) - - 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 }, - constraintType: 'yAbsolute', - expectBeforeUnconstrained: 'yLineTo(-10.77, %, $a)', - expectAfterUnconstrained: 'yLineTo(yAbs002, %, $a)', - expectFinal: 'yLineTo(-10.77, %, $a)', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="4"]', - }) - - 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, y: xLine.y }, - constraintType: 'xRelative', - expectBeforeUnconstrained: 'xLine(26.04, %)', - expectAfterUnconstrained: 'xLine(xRel002, %)', - expectFinal: 'xLine(26.04, %)', - steps: 10, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="5"]', - }) }) - test('for segments [yLine, angledLineOfXLength, angledLineOfYLength]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test('for segments [yLine, angledLineOfXLength, angledLineOfYLength]', async ({ + page, + homePage, + }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([0, 0], %) |> line([0.5, -14 + 0], %) |> angledLine({ angle: 3 + 0, length: 32 + 0 }, %) @@ -438,111 +448,116 @@ test.describe('Testing segment overlays', () => { }, %) |> tangentialArcTo([3.14 + 13, 3.14], %) ` + ) + localStorage.setItem('disableAxis', 'true') + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + 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) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(13) + + 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 }, + constraintType: 'yRelative', + expectBeforeUnconstrained: 'yLine(21.14 + 0, %)', + expectAfterUnconstrained: 'yLine(21.14, %)', + expectFinal: 'yLine(yRel001, %)', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="6"]', + }) + + const angledLineOfXLength = await u.getBoundingBox( + `[data-overlay-index="7"]` ) - localStorage.setItem('disableAxis', 'true') + ang = await u.getAngle(`[data-overlay-index="7"]`) + console.log('angledLineOfXLength1') + await clickConstrained({ + hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y }, + constraintType: 'angle', + expectBeforeUnconstrained: + 'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', + expectAfterUnconstrained: + 'angledLineOfXLength({ angle: -179, length: 23.14 }, %)', + expectFinal: + 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="7"]', + }) + console.log('angledLineOfXLength2') + await clickUnconstrained({ + hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y }, + constraintType: 'xRelative', + expectBeforeUnconstrained: + 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', + expectAfterUnconstrained: + 'angledLineOfXLength({ angle: angle001, length: xRel001 }, %)', + expectFinal: + 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', + steps: 7, + ang: ang + 180, + locator: '[data-overlay-toolbar-index="7"]', + }) + + 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 }, + constraintType: 'angle', + expectBeforeUnconstrained: + 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', + expectAfterUnconstrained: + 'angledLineOfYLength({ angle: angle002, length: 19 + 0 }, %)', + expectFinal: 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', + ang: ang + 180, + steps: 6, + locator: '[data-overlay-toolbar-index="8"]', + }) + console.log('angledLineOfYLength2') + await clickConstrained({ + hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y }, + constraintType: 'yRelative', + expectBeforeUnconstrained: + 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', + expectAfterUnconstrained: + 'angledLineOfYLength({ angle: -91, length: 19 }, %)', + expectFinal: 'angledLineOfYLength({ angle: -91, length: yRel002 }, %)', + ang: ang + 180, + steps: 7, + locator: '[data-overlay-toolbar-index="8"]', + }) }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - 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) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(13) - - 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 }, - constraintType: 'yRelative', - expectBeforeUnconstrained: 'yLine(21.14 + 0, %)', - expectAfterUnconstrained: 'yLine(21.14, %)', - expectFinal: 'yLine(yRel001, %)', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="6"]', - }) - - 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, y: angledLineOfXLength.y }, - constraintType: 'angle', - expectBeforeUnconstrained: - 'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', - expectAfterUnconstrained: - 'angledLineOfXLength({ angle: -179, length: 23.14 }, %)', - expectFinal: - 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="7"]', - }) - console.log('angledLineOfXLength2') - await clickUnconstrained({ - hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y }, - constraintType: 'xRelative', - expectBeforeUnconstrained: - 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', - expectAfterUnconstrained: - 'angledLineOfXLength({ angle: angle001, length: xRel001 }, %)', - expectFinal: - 'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', - steps: 7, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="7"]', - }) - - 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 }, - constraintType: 'angle', - expectBeforeUnconstrained: - 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', - expectAfterUnconstrained: - 'angledLineOfYLength({ angle: angle002, length: 19 + 0 }, %)', - expectFinal: 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', - ang: ang + 180, - steps: 6, - locator: '[data-overlay-toolbar-index="8"]', - }) - console.log('angledLineOfYLength2') - await clickConstrained({ - hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y }, - constraintType: 'yRelative', - expectBeforeUnconstrained: - 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', - expectAfterUnconstrained: - 'angledLineOfYLength({ angle: -91, length: 19 }, %)', - expectFinal: 'angledLineOfYLength({ angle: -91, length: yRel002 }, %)', - ang: ang + 180, - steps: 7, - locator: '[data-overlay-toolbar-index="8"]', - }) }) - test('for segments [angledLineToX, angledLineToY, angledLineThatIntersects]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test('for segments [angledLineToX, angledLineToY, angledLineThatIntersects]', async ({ + page, + homePage, + }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([0, 0], %) |> line([0.5, -14 + 0], %) |> angledLine({ angle: 3 + 0, length: 32 + 0 }, %) @@ -562,142 +577,143 @@ test.describe('Testing segment overlays', () => { }, %) |> tangentialArcTo([3.14 + 13, 1.14], %) ` - ) - localStorage.setItem('disableAxis', 'true') - }) + ) + localStorage.setItem('disableAxis', 'true') + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText('xLineTo(9 - 5, %)').click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(13) - - 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, 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, - locator: '[data-overlay-toolbar-index="9"]', - }) - console.log('angledLineToX2') - await clickUnconstrained({ - hoverPos: { x: angledLineToX.x, y: angledLineToX.y }, - constraintType: 'xAbsolute', - expectBeforeUnconstrained: - 'angledLineToX({ angle: angle001, to: 26 }, %)', - expectAfterUnconstrained: - 'angledLineToX({ angle: angle001, to: xAbs001 }, %)', - expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="9"]', - }) - - 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 }, - constraintType: 'angle', - expectBeforeUnconstrained: - 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', - expectAfterUnconstrained: - 'angledLineToY({ angle: angle002, to: 9.14 + 0 }, %)', - expectFinal: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', - steps: process.platform === 'darwin' ? 8 : 9, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="10"]', - }) - console.log('angledLineToY2') - await clickConstrained({ - hoverPos: { x: angledLineToY.x, y: angledLineToY.y }, - constraintType: 'yAbsolute', - expectBeforeUnconstrained: - 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', - expectAfterUnconstrained: 'angledLineToY({ angle: 89, to: 9.14 }, %)', - expectFinal: 'angledLineToY({ angle: 89, to: yAbs001 }, %)', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="10"]', - }) - - const angledLineThatIntersects = await u.getBoundingBox( - `[data-overlay-index="11"]` - ) - ang = await u.getAngle(`[data-overlay-index="11"]`) - console.log('angledLineThatIntersects') - await clickUnconstrained({ - hoverPos: { - x: angledLineThatIntersects.x, - y: angledLineThatIntersects.y, - }, - constraintType: 'angle', - expectBeforeUnconstrained: `angledLineThatIntersects({ + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText('xLineTo(9 - 5, %)').click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(13) + + 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, 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, + locator: '[data-overlay-toolbar-index="9"]', + }) + console.log('angledLineToX2') + await clickUnconstrained({ + hoverPos: { x: angledLineToX.x, y: angledLineToX.y }, + constraintType: 'xAbsolute', + expectBeforeUnconstrained: + 'angledLineToX({ angle: angle001, to: 26 }, %)', + expectAfterUnconstrained: + 'angledLineToX({ angle: angle001, to: xAbs001 }, %)', + expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="9"]', + }) + + 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 }, + constraintType: 'angle', + expectBeforeUnconstrained: + 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', + expectAfterUnconstrained: + 'angledLineToY({ angle: angle002, to: 9.14 + 0 }, %)', + expectFinal: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', + steps: process.platform === 'darwin' ? 8 : 9, + ang: ang + 180, + locator: '[data-overlay-toolbar-index="10"]', + }) + console.log('angledLineToY2') + await clickConstrained({ + hoverPos: { x: angledLineToY.x, y: angledLineToY.y }, + constraintType: 'yAbsolute', + expectBeforeUnconstrained: + 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', + expectAfterUnconstrained: 'angledLineToY({ angle: 89, to: 9.14 }, %)', + expectFinal: 'angledLineToY({ angle: 89, to: yAbs001 }, %)', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="10"]', + }) + + const angledLineThatIntersects = await u.getBoundingBox( + `[data-overlay-index="11"]` + ) + ang = await u.getAngle(`[data-overlay-index="11"]`) + console.log('angledLineThatIntersects') + await clickUnconstrained({ + hoverPos: { + x: angledLineThatIntersects.x, + y: angledLineThatIntersects.y, + }, + constraintType: 'angle', + expectBeforeUnconstrained: `angledLineThatIntersects({ angle: 4.14, intersectTag: a, offset: 9 }, %)`, - expectAfterUnconstrained: `angledLineThatIntersects({ + expectAfterUnconstrained: `angledLineThatIntersects({ angle: angle003, intersectTag: a, offset: 9 }, %)`, - expectFinal: `angledLineThatIntersects({ + expectFinal: `angledLineThatIntersects({ angle: -176, offset: 9, intersectTag: a }, %)`, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="11"]', - }) - console.log('angledLineThatIntersects2') - await clickUnconstrained({ - hoverPos: { - x: angledLineThatIntersects.x, - y: angledLineThatIntersects.y, - }, - constraintType: 'intersectionOffset', - expectBeforeUnconstrained: `angledLineThatIntersects({ + ang: ang + 180, + locator: '[data-overlay-toolbar-index="11"]', + }) + console.log('angledLineThatIntersects2') + await clickUnconstrained({ + hoverPos: { + x: angledLineThatIntersects.x, + y: angledLineThatIntersects.y, + }, + constraintType: 'intersectionOffset', + expectBeforeUnconstrained: `angledLineThatIntersects({ angle: -176, offset: 9, intersectTag: a }, %)`, - expectAfterUnconstrained: `angledLineThatIntersects({ + expectAfterUnconstrained: `angledLineThatIntersects({ angle: -176, offset: perpDist001, intersectTag: a }, %)`, - expectFinal: `angledLineThatIntersects({ + expectFinal: `angledLineThatIntersects({ angle: -176, offset: 9, intersectTag: a }, %)`, - ang: ang + 180, - locator: '[data-overlay-toolbar-index="11"]', - }) }) - test('for segment [tangentialArcTo]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + ang: ang + 180, + locator: '[data-overlay-toolbar-index="11"]', + }) + }) + test('for segment [tangentialArcTo]', async ({ page, homePage }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([0, 0], %) |> line([0.5, -14 + 0], %) |> angledLine({ angle: 3 + 0, length: 32 + 0 }, %) @@ -717,127 +733,130 @@ test.describe('Testing segment overlays', () => { }, %) |> tangentialArcTo([3.14 + 13, -3.14], %) ` + ) + localStorage.setItem('disableAxis', 'true') + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText('xLineTo(9 - 5, %)').click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(13) + + const clickUnconstrained = _clickUnconstrained(page) + const clickConstrained = _clickConstrained(page) + + const tangentialArcTo = await u.getBoundingBox( + '[data-overlay-index="12"]' ) - localStorage.setItem('disableAxis', 'true') + let ang = await u.getAngle('[data-overlay-index="12"]') + console.log('tangentialArcTo') + await clickConstrained({ + 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: ang + 180, + steps: 6, + locator: '[data-overlay-toolbar-index="12"]', + }) + console.log('tangentialArcTo2') + await clickUnconstrained({ + hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y }, + constraintType: 'yAbsolute', + expectBeforeUnconstrained: 'tangentialArcTo([xAbs001, -3.14], %)', + expectAfterUnconstrained: 'tangentialArcTo([xAbs001, yAbs001], %)', + expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)', + ang: ang + 180, + steps: 10, + locator: '[data-overlay-toolbar-index="12"]', + }) }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText('xLineTo(9 - 5, %)').click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(13) - - const clickUnconstrained = _clickUnconstrained(page) - const clickConstrained = _clickConstrained(page) - - 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, y: tangentialArcTo.y }, - constraintType: 'xAbsolute', - expectBeforeUnconstrained: 'tangentialArcTo([3.14 + 13, -3.14], %)', - expectAfterUnconstrained: 'tangentialArcTo([16.14, -3.14], %)', - expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)', - ang: ang + 180, - steps: 6, - locator: '[data-overlay-toolbar-index="12"]', - }) - console.log('tangentialArcTo2') - await clickUnconstrained({ - hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y }, - constraintType: 'yAbsolute', - expectBeforeUnconstrained: 'tangentialArcTo([xAbs001, -3.14], %)', - expectAfterUnconstrained: 'tangentialArcTo([xAbs001, yAbs001], %)', - expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)', - ang: ang + 180, - steps: 10, - locator: '[data-overlay-toolbar-index="12"]', - }) }) - test('for segment [circle]', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test('for segment [circle]', async ({ page, homePage }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> circle({ center: [1 + 0, 0], radius: 8 }, %) ` - ) - localStorage.setItem('disableAxis', 'true') + ) + localStorage.setItem('disableAxis', 'true') + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page + .getByText('circle({ center: [1 + 0, 0], radius: 8 }, %)') + .click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(1) + + const clickUnconstrained = _clickUnconstrained(page) + const clickConstrained = _clickConstrained(page) + + const hoverPos = { x: 789, y: 114 } as const + let ang = await u.getAngle('[data-overlay-index="0"]') + console.log('angl', ang) + console.log('circle center x') + await clickConstrained({ + hoverPos, + constraintType: 'xAbsolute', + expectBeforeUnconstrained: + 'circle({ center: [1 + 0, 0], radius: 8 }, %)', + expectAfterUnconstrained: 'circle({ center: [1, 0], radius: 8 }, %)', + expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', + ang: ang + 105, + steps: 6, + locator: '[data-overlay-toolbar-index="0"]', + }) + console.log('circle center y') + await clickUnconstrained({ + hoverPos, + constraintType: 'yAbsolute', + expectBeforeUnconstrained: + 'circle({ center: [xAbs001, 0], radius: 8 }, %)', + expectAfterUnconstrained: + 'circle({ center: [xAbs001, yAbs001], radius: 8 }, %)', + expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', + ang: ang + 105, + steps: 10, + locator: '[data-overlay-toolbar-index="0"]', + }) + console.log('circle radius') + await clickUnconstrained({ + hoverPos, + constraintType: 'radius', + expectBeforeUnconstrained: + 'circle({ center: [xAbs001, 0], radius: 8 }, %)', + expectAfterUnconstrained: + 'circle({ center: [xAbs001, 0], radius: radius001 }, %)', + expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', + ang: ang + 105, + steps: 10, + locator: '[data-overlay-toolbar-index="0"]', + }) }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page - .getByText('circle({ center: [1 + 0, 0], radius: 8 }, %)') - .click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(1) - - const clickUnconstrained = _clickUnconstrained(page) - const clickConstrained = _clickConstrained(page) - - const hoverPos = { x: 789, y: 114 } as const - let ang = await u.getAngle('[data-overlay-index="0"]') - console.log('angl', ang) - console.log('circle center x') - await clickConstrained({ - hoverPos, - constraintType: 'xAbsolute', - expectBeforeUnconstrained: - 'circle({ center: [1 + 0, 0], radius: 8 }, %)', - expectAfterUnconstrained: 'circle({ center: [1, 0], radius: 8 }, %)', - expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', - ang: ang + 105, - steps: 6, - locator: '[data-overlay-toolbar-index="0"]', - }) - console.log('circle center y') - await clickUnconstrained({ - hoverPos, - constraintType: 'yAbsolute', - expectBeforeUnconstrained: - 'circle({ center: [xAbs001, 0], radius: 8 }, %)', - expectAfterUnconstrained: - 'circle({ center: [xAbs001, yAbs001], radius: 8 }, %)', - expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', - ang: ang + 105, - steps: 10, - locator: '[data-overlay-toolbar-index="0"]', - }) - console.log('circle radius') - await clickUnconstrained({ - hoverPos, - constraintType: 'radius', - expectBeforeUnconstrained: - 'circle({ center: [xAbs001, 0], radius: 8 }, %)', - expectAfterUnconstrained: - 'circle({ center: [xAbs001, 0], radius: radius001 }, %)', - expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', - ang: ang + 105, - steps: 10, - locator: '[data-overlay-toolbar-index="0"]', - }) }) }) test.describe('Testing deleting a segment', () => { const _deleteSegmentSequence = @@ -877,11 +896,11 @@ test.describe('Testing segment overlays', () => { codeToBeDeleted ) } - - test('all segment types', async ({ page, homePage }) => { await page.addInitScript(async () => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test('all segment types', async ({ page, homePage }) => { + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([0, 0], %) |> line([0.5, -14 + 0], %) |> angledLine({ angle: 3 + 0, length: 32 + 0 }, %) @@ -901,189 +920,190 @@ test.describe('Testing segment overlays', () => { }, %) |> tangentialArcTo([3.14 + 13, 1.14], %) ` - ) - localStorage.setItem('disableAxis', 'true') - }) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - - // wait for execution done - await u.openDebugPanel() - await u.expectCmdLog('[data-message-type="execution-done"]') - await u.closeDebugPanel() - - await page.getByText('xLineTo(9 - 5, %)').click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(13) - const deleteSegmentSequence = _deleteSegmentSequence(page) - - let segmentToDelete - - const getOverlayByIndex = (index: number) => - u.getBoundingBox(`[data-overlay-index="${index}"]`) - segmentToDelete = await getOverlayByIndex(12) - let ang = await u.getAngle(`[data-overlay-index="${12}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'tangentialArcTo([3.14 + 13, 1.14], %)', - stdLibFnName: 'tangentialArcTo', - ang: ang + 180, - steps: 6, - locator: '[data-overlay-toolbar-index="12"]', - }) - - segmentToDelete = await getOverlayByIndex(11) - ang = await u.getAngle(`[data-overlay-index="${11}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: `angledLineThatIntersects({ + ) + localStorage.setItem('disableAxis', 'true') + }) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await page.getByText('xLineTo(9 - 5, %)').click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(13) + const deleteSegmentSequence = _deleteSegmentSequence(page) + + let segmentToDelete + + const getOverlayByIndex = (index: number) => + u.getBoundingBox(`[data-overlay-index="${index}"]`) + segmentToDelete = await getOverlayByIndex(12) + let ang = await u.getAngle(`[data-overlay-index="${12}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'tangentialArcTo([3.14 + 13, 1.14], %)', + stdLibFnName: 'tangentialArcTo', + ang: ang + 180, + steps: 6, + locator: '[data-overlay-toolbar-index="12"]', + }) + + segmentToDelete = await getOverlayByIndex(11) + ang = await u.getAngle(`[data-overlay-index="${11}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: `angledLineThatIntersects({ angle: 4.14, intersectTag: a, offset: 9 }, %)`, - stdLibFnName: 'angledLineThatIntersects', - ang: ang + 180, - steps: 7, - locator: '[data-overlay-toolbar-index="11"]', + stdLibFnName: 'angledLineThatIntersects', + ang: ang + 180, + steps: 7, + locator: '[data-overlay-toolbar-index="11"]', + }) + + segmentToDelete = await getOverlayByIndex(10) + ang = await u.getAngle(`[data-overlay-index="${10}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', + stdLibFnName: 'angledLineToY', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="10"]', + }) + + segmentToDelete = await getOverlayByIndex(9) + ang = await u.getAngle(`[data-overlay-index="${9}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)', + stdLibFnName: 'angledLineToX', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="9"]', + }) + + segmentToDelete = await getOverlayByIndex(8) + ang = await u.getAngle(`[data-overlay-index="${8}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: + 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', + stdLibFnName: 'angledLineOfYLength', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="8"]', + }) + + segmentToDelete = await getOverlayByIndex(7) + ang = await u.getAngle(`[data-overlay-index="${7}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: + 'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', + stdLibFnName: 'angledLineOfXLength', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="7"]', + }) + + segmentToDelete = await getOverlayByIndex(6) + ang = await u.getAngle(`[data-overlay-index="${6}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'yLine(21.14 + 0, %)', + stdLibFnName: 'yLine', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="6"]', + }) + + segmentToDelete = await getOverlayByIndex(5) + ang = await u.getAngle(`[data-overlay-index="${5}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'xLine(26.04, %)', + stdLibFnName: 'xLine', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="5"]', + }) + + segmentToDelete = await getOverlayByIndex(4) + ang = await u.getAngle(`[data-overlay-index="${4}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'yLineTo(-10.77, %, $a)', + stdLibFnName: 'yLineTo', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="4"]', + }) + + segmentToDelete = await getOverlayByIndex(3) + ang = await u.getAngle(`[data-overlay-index="${3}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'xLineTo(9 - 5, %)', + stdLibFnName: 'xLineTo', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="3"]', + }) + + segmentToDelete = await getOverlayByIndex(2) + ang = await u.getAngle(`[data-overlay-index="${2}"]`) + await expect(page.getByText('Added variable')).not.toBeVisible() + + const hoverPos = { x: segmentToDelete.x, y: segmentToDelete.y } + await page.mouse.move(0, 0) + await page.waitForTimeout(1000) + await page.mouse.move(hoverPos.x, hoverPos.y) + await wiggleMove( + page, + hoverPos.x, + hoverPos.y, + 20, + 30, + ang, + 10, + 5, + '[data-overlay-toolbar-index="2"]' + ) + + const codeToBeDeleted = 'lineTo([33, 11.5 + 0], %)' + await expect(page.locator('.cm-content')).toContainText(codeToBeDeleted) + + await page.getByTestId('overlay-menu').click() + await page.getByText('Delete Segment').click() + + await expect(page.locator('.cm-content')).not.toContainText( + codeToBeDeleted + ) + + segmentToDelete = await getOverlayByIndex(1) + ang = await u.getAngle(`[data-overlay-index="${1}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)', + stdLibFnName: 'angledLine', + ang: ang + 180, + locator: '[data-overlay-toolbar-index="1"]', + }) + + segmentToDelete = await getOverlayByIndex(0) + ang = await u.getAngle(`[data-overlay-index="${0}"]`) + await deleteSegmentSequence({ + hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, + codeToBeDeleted: 'line([0.5, -14 + 0], %)', + stdLibFnName: 'line', + ang: ang + 180, + }) + + await page.waitForTimeout(200) }) - - segmentToDelete = await getOverlayByIndex(10) - ang = await u.getAngle(`[data-overlay-index="${10}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', - stdLibFnName: 'angledLineToY', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="10"]', - }) - - segmentToDelete = await getOverlayByIndex(9) - ang = await u.getAngle(`[data-overlay-index="${9}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)', - stdLibFnName: 'angledLineToX', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="9"]', - }) - - segmentToDelete = await getOverlayByIndex(8) - ang = await u.getAngle(`[data-overlay-index="${8}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: - 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', - stdLibFnName: 'angledLineOfYLength', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="8"]', - }) - - segmentToDelete = await getOverlayByIndex(7) - ang = await u.getAngle(`[data-overlay-index="${7}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: - 'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', - stdLibFnName: 'angledLineOfXLength', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="7"]', - }) - - segmentToDelete = await getOverlayByIndex(6) - ang = await u.getAngle(`[data-overlay-index="${6}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'yLine(21.14 + 0, %)', - stdLibFnName: 'yLine', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="6"]', - }) - - segmentToDelete = await getOverlayByIndex(5) - ang = await u.getAngle(`[data-overlay-index="${5}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'xLine(26.04, %)', - stdLibFnName: 'xLine', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="5"]', - }) - - segmentToDelete = await getOverlayByIndex(4) - ang = await u.getAngle(`[data-overlay-index="${4}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'yLineTo(-10.77, %, $a)', - stdLibFnName: 'yLineTo', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="4"]', - }) - - segmentToDelete = await getOverlayByIndex(3) - ang = await u.getAngle(`[data-overlay-index="${3}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'xLineTo(9 - 5, %)', - stdLibFnName: 'xLineTo', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="3"]', - }) - - segmentToDelete = await getOverlayByIndex(2) - ang = await u.getAngle(`[data-overlay-index="${2}"]`) - await expect(page.getByText('Added variable')).not.toBeVisible() - - const hoverPos = { x: segmentToDelete.x, y: segmentToDelete.y } - await page.mouse.move(0, 0) - await page.waitForTimeout(1000) - await page.mouse.move(hoverPos.x, hoverPos.y) - await wiggleMove( - page, - hoverPos.x, - hoverPos.y, - 20, - 30, - ang, - 10, - 5, - '[data-overlay-toolbar-index="2"]' - ) - - const codeToBeDeleted = 'lineTo([33, 11.5 + 0], %)' - await expect(page.locator('.cm-content')).toContainText(codeToBeDeleted) - - await page.getByTestId('overlay-menu').click() - await page.getByText('Delete Segment').click() - - await expect(page.locator('.cm-content')).not.toContainText( - codeToBeDeleted - ) - - segmentToDelete = await getOverlayByIndex(1) - ang = await u.getAngle(`[data-overlay-index="${1}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)', - stdLibFnName: 'angledLine', - ang: ang + 180, - locator: '[data-overlay-toolbar-index="1"]', - }) - - segmentToDelete = await getOverlayByIndex(0) - ang = await u.getAngle(`[data-overlay-index="${0}"]`) - await deleteSegmentSequence({ - hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, - codeToBeDeleted: 'line([0.5, -14 + 0], %)', - stdLibFnName: 'line', - ang: ang + 180, - }) - - await page.waitForTimeout(200) }) }) test.describe('Testing delete with dependent segments', () => { const cases = [ @@ -1107,96 +1127,98 @@ test.describe('Testing segment overlays', () => { const isObj = lineOfInterest.includes('{ angle = 3,') test(`${lineOfInterest.split('(')[0]}${isObj ? '-[obj-input]' : ''}${ doesHaveTagOutsideSketch ? '-[tagOutsideSketch]' : '' - }`, async ({ page, homePage }) => { await page.addInitScript( - async ({ lineToBeDeleted, extraLine }) => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + }`, async ({ page, homePage }) => { + await page.addInitScript( + async ({ lineToBeDeleted, extraLine }) => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([5, 6], %) |> ${lineToBeDeleted} |> line([-10, -15], %) |> angledLine([-176, segLen(seg01)], %) ${extraLine ? 'myVar = segLen(seg01)' : ''}` - ) - }, - { - lineToBeDeleted: lineOfInterest, - extraLine: doesHaveTagOutsideSketch, + ) + }, + { + lineToBeDeleted: lineOfInterest, + extraLine: doesHaveTagOutsideSketch, + } + ) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + await page.waitForTimeout(300) + + await page.getByText(lineOfInterest).click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(3) + const segmentToDelete = await u.getBoundingBox( + `[data-overlay-index="0"]` + ) + + const isYLine = lineOfInterest.toLowerCase().includes('yline') + const hoverPos = { + x: segmentToDelete.x + (isYLine ? 0 : -20), + y: segmentToDelete.y + (isYLine ? -20 : 0), } - ) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - await page.waitForTimeout(300) - - await page.getByText(lineOfInterest).click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(3) - const segmentToDelete = await u.getBoundingBox( - `[data-overlay-index="0"]` - ) - - const isYLine = lineOfInterest.toLowerCase().includes('yline') - const hoverPos = { - x: segmentToDelete.x + (isYLine ? 0 : -20), - y: segmentToDelete.y + (isYLine ? -20 : 0), - } - await expect(page.getByText('Added variable')).not.toBeVisible() - const ang = isYLine ? 45 : -45 - 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: 5 }) - - await expect(page.locator('.cm-content')).toContainText( - lineOfInterest - ) - - await page.getByTestId('overlay-menu').click() - await page.waitForTimeout(100) - await page.getByText('Delete Segment').click() - - await page.getByText('Cancel').click() - - await page.mouse.move(hoverPos.x + x, hoverPos.y + y) - await page.mouse.move(hoverPos.x, hoverPos.y, { steps: 5 }) - - await expect(page.locator('.cm-content')).toContainText( - lineOfInterest - ) - - await page.getByTestId('overlay-menu').click() - await page.waitForTimeout(100) - await page.getByText('Delete Segment').click() - - await page.getByText('Continue and unconstrain').last().click() - - if (doesHaveTagOutsideSketch) { - // eslint-disable-next-line jest/no-conditional-expect - await expect( - page.getByText( - 'Segment tag used outside of current Sketch. Could not delete.' - ) - ).toBeTruthy() - // eslint-disable-next-line jest/no-conditional-expect + await expect(page.getByText('Added variable')).not.toBeVisible() + const ang = isYLine ? 45 : -45 + 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: 5 }) + await expect(page.locator('.cm-content')).toContainText( lineOfInterest ) - } else { - // eslint-disable-next-line jest/no-conditional-expect - await expect(page.locator('.cm-content')).not.toContainText( + + await page.getByTestId('overlay-menu').click() + await page.waitForTimeout(100) + await page.getByText('Delete Segment').click() + + await page.getByText('Cancel').click() + + await page.mouse.move(hoverPos.x + x, hoverPos.y + y) + await page.mouse.move(hoverPos.x, hoverPos.y, { steps: 5 }) + + await expect(page.locator('.cm-content')).toContainText( lineOfInterest ) - // eslint-disable-next-line jest/no-conditional-expect - await expect(page.locator('.cm-content')).not.toContainText('seg01') - } }) + + await page.getByTestId('overlay-menu').click() + await page.waitForTimeout(100) + await page.getByText('Delete Segment').click() + + await page.getByText('Continue and unconstrain').last().click() + + if (doesHaveTagOutsideSketch) { + // eslint-disable-next-line jest/no-conditional-expect + await expect( + page.getByText( + 'Segment tag used outside of current Sketch. Could not delete.' + ) + ).toBeTruthy() + // eslint-disable-next-line jest/no-conditional-expect + await expect(page.locator('.cm-content')).toContainText( + lineOfInterest + ) + } else { + // eslint-disable-next-line jest/no-conditional-expect + await expect(page.locator('.cm-content')).not.toContainText( + lineOfInterest + ) + // eslint-disable-next-line jest/no-conditional-expect + await expect(page.locator('.cm-content')).not.toContainText('seg01') + } + }) } } }) @@ -1263,68 +1285,73 @@ test.describe('Testing segment overlays', () => { for (const { before, after } of cases) { const isObj = before.includes('{ angle: 3') - test(`${before.split('(')[0]}${isObj ? '-[obj-input]' : ''}`, async ({ page, homePage }) => { await page.addInitScript( - async ({ lineToBeDeleted }) => { - localStorage.setItem( - 'persistCode', - `part001 = startSketchOn('XZ') + test(`${before.split('(')[0]}${isObj ? '-[obj-input]' : ''}`, async ({ + page, + homePage, + }) => { + await page.addInitScript( + async ({ lineToBeDeleted }) => { + localStorage.setItem( + 'persistCode', + `part001 = startSketchOn('XZ') |> startProfileAt([5, 6], %) |> ${lineToBeDeleted} |> line([-10, -15], %) |> angledLine([-176, segLen(seg01)], %)` - ) - }, - { - lineToBeDeleted: before, - } - ) - const u = await getUtils(page) - await page.setViewportSize({ width: 1200, height: 500 }) - - await homePage.goToModelingScene() - await page.waitForTimeout(300) - - await page.getByText(before).click() - await page.waitForTimeout(100) - await page.getByRole('button', { name: 'Edit Sketch' }).click() - await page.waitForTimeout(500) - - await expect(page.getByTestId('segment-overlay')).toHaveCount(3) - await expect(page.getByText('Added variable')).not.toBeVisible() - - const hoverPos = await u.getBoundingBox(`[data-overlay-index="0"]`) - let ang = await u.getAngle(`[data-overlay-index="${0}"]`) - ang += 180 - - 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, - '[data-overlay-toolbar-index="0"]' - ) - - await expect(page.locator('.cm-content')).toContainText(before) - - await page.getByTestId('overlay-menu').click() - await page.waitForTimeout(100) - await page.getByText('Remove constraints').click() - - await expect(page.locator('.cm-content')).toContainText(after) - // check the cursor was left in the correct place after transform - await expect(page.locator('.cm-activeLine')).toHaveText('|> ' + after) - await expect(page.getByTestId('segment-overlay')).toHaveCount(3) }) + ) + }, + { + lineToBeDeleted: before, + } + ) + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + + await homePage.goToModelingScene() + await page.waitForTimeout(300) + + await page.getByText(before).click() + await page.waitForTimeout(100) + await page.getByRole('button', { name: 'Edit Sketch' }).click() + await page.waitForTimeout(500) + + await expect(page.getByTestId('segment-overlay')).toHaveCount(3) + await expect(page.getByText('Added variable')).not.toBeVisible() + + const hoverPos = await u.getBoundingBox(`[data-overlay-index="0"]`) + let ang = await u.getAngle(`[data-overlay-index="${0}"]`) + ang += 180 + + 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, + '[data-overlay-toolbar-index="0"]' + ) + + await expect(page.locator('.cm-content')).toContainText(before) + + await page.getByTestId('overlay-menu').click() + await page.waitForTimeout(100) + await page.getByText('Remove constraints').click() + + await expect(page.locator('.cm-content')).toContainText(after) + // check the cursor was left in the correct place after transform + await expect(page.locator('.cm-activeLine')).toHaveText('|> ' + after) + await expect(page.getByTestId('segment-overlay')).toHaveCount(3) + }) } }) }) diff --git a/e2e/playwright/testing-selections.spec.ts b/e2e/playwright/testing-selections.spec.ts index e3d6a7042..1847ccc2b 100644 --- a/e2e/playwright/testing-selections.spec.ts +++ b/e2e/playwright/testing-selections.spec.ts @@ -5,10 +5,6 @@ import { Coords2d } from 'lang/std/sketch' import { KCL_DEFAULT_LENGTH } from 'lib/constants' import { uuidv4 } from 'lib/utils' - - - - test.describe('Testing selections', () => { test.setTimeout(90_000) test('Selections work on fresh and edited sketch', { tag: ['@skipWin'] }, async ({ page, homePage }) => { // Skip on windows its being weird. diff --git a/to-electron.sh b/to-electron.sh new file mode 100755 index 000000000..9c741ae42 --- /dev/null +++ b/to-electron.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +FILE="$1" + +sg run --update-all \ +--pattern 'await $_A.waitForAuthSkipAppStart()' \ +--rewrite 'await homePage.goToModelingScene()' \ +"$FILE" + +sg --update-all \ +--pattern 'test($DESC, async ({ page, $$$ARGS }) => { $$$BODY })' \ +--rewrite 'test($DESC, async ({ page, $$$ARGS homePage }) => { $$$BODY })' \ +"$FILE" + +sg --update-all \ +--pattern 'test($DESC, async ({ page }) => { $$$BODY })' \ +--rewrite 'test($DESC, async ({ page, homePage }) => { $$$BODY })' \ +"$FILE" + +sg --update-all \ +--pattern 'test($DESC, $OPT, async ({ page }) => { $$$BODY })' \ +--rewrite 'test($DESC, $OPT, async ({ page, homePage }) => { $$$BODY })' \ +"$FILE" + +sg --update-all --pattern 'test.beforeEach($$$)' --rewrite '' "$FILE" +sg --update-all --pattern 'test.afterEach($$$)' --rewrite '' "$FILE" + +# Unfortunately some tests are tied to the viewport size. +# sg --update-all --pattern 'await page.setViewportSize($$$ARGS)' --rewrite '' "$FILE" +sg --update-all --pattern "await page.goto('/')" --rewrite '' "$FILE" + +sg --update-all --pattern 'await page.setViewportSize($$$ARGS)' --rewrite 'await page.setBodyDimensions($$$ARGS)' "$FILE" + +sed -i -e 's/@playwright\/test/.\/zoo-test/' "$FILE" +sed -i -e 's/, setup, tearDown,//' "$FILE" +sed -i -e 's/setup, tearDown,//' "$FILE" +sed -i -e 's/setup, tearDown//' "$FILE"