diff --git a/e2e/playwright/projects.spec.ts b/e2e/playwright/projects.spec.ts index f9ead40d3..96eeccfb5 100644 --- a/e2e/playwright/projects.spec.ts +++ b/e2e/playwright/projects.spec.ts @@ -2116,3 +2116,74 @@ test( }) } ) + +test( + 'segment position changes persist after dragging and reopening project', + { tag: '@desktop' }, + async ({ scene, cmdBar, context, page, editor, toolbar }, testInfo) => { + const projectName = 'segment-drag-test' + + await context.folderSetupFn(async (dir) => { + const projectDir = path.join(dir, projectName) + await fsp.mkdir(projectDir, { recursive: true }) + await fsp.writeFile( + path.join(projectDir, 'main.kcl'), + `sketch001 = startSketchOn(XZ) +profile001 = startProfile(sketch001, at = [0, 0]) + |> line(end = [0, 6]) + |> line(end = [10, 0]) + |> line(end = [-8, -5]) +` + ) + }) + + await page.setBodyDimensions({ width: 1200, height: 600 }) + const u = await getUtils(page) + + await test.step('Opening the project and entering sketch mode', async () => { + await expect(page.getByText(projectName)).toBeVisible() + await page.getByText(projectName).click() + + await scene.settled(cmdBar) + + // go to sketch mode + await (await toolbar.getFeatureTreeOperation('Sketch', 0)).dblclick() + + // Without this, "add axis n grid" action runs after editing the sketch and invokes codeManager.writeToFile() + // so we wait for that action to run first before we start editing the sketch and making sure it's saving + // because of those edits. + await page.waitForTimeout(2000) + }) + + const changedLine = 'line(end = [-6.54, -4.99])' + + await test.step('Dragging the line endpoint to modify it', async () => { + // Get the last line's endpoint position + const lineEnd = await u.getBoundingBox('[data-overlay-index="3"]') + + await page.mouse.move(lineEnd.x, lineEnd.y - 5) + await page.mouse.down() + await page.mouse.move(lineEnd.x + 80, lineEnd.y) + await page.mouse.up() + + await editor.expectEditor.toContain(changedLine) + + // Exit sketch mode + await page.keyboard.press('Escape') + await page.waitForTimeout(100) + }) + + await test.step('Going back to dashboard', async () => { + await page.getByTestId('app-logo').click() + await page.waitForTimeout(1000) + }) + + await test.step('Reopening the project and verifying changes are saved', async () => { + await page.getByText(projectName).click() + await scene.settled(cmdBar) + + // Check if new line coordinates were saved + await editor.expectEditor.toContain(changedLine) + }) + } +) diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index 28e0a457b..7ca195257 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -2504,8 +2504,8 @@ export class SceneEntities { forward, position, }) - await this.codeManager.writeToFile() } + await this.codeManager.writeToFile() }, onDrag: async ({ selected,