diff --git a/e2e/playwright/code-pane-and-errors.spec.ts b/e2e/playwright/code-pane-and-errors.spec.ts index 0f30e02fe..eb63c9d8d 100644 --- a/e2e/playwright/code-pane-and-errors.spec.ts +++ b/e2e/playwright/code-pane-and-errors.spec.ts @@ -52,6 +52,7 @@ test.describe('Code pane and errors', () => { test('Opening and closing the code pane will consistently show error diagnostics', async ({ page, homePage, + editor, }) => { const u = await getUtils(page) @@ -77,8 +78,9 @@ test.describe('Code pane and errors', () => { await expect(codePaneButtonHolder).not.toContainText('notification') // Delete a character to break the KCL - await u.openKclCodePanel() - await page.getByText('thickness, bracketLeg1Sketch)').click() + await editor.openPane() + await editor.scrollToText('thickness, bracketLeg1Sketch)') + await page.getByText('extrude(thickness, bracketLeg1Sketch)').click() await page.keyboard.press('Backspace') // Ensure that a badge appears on the button @@ -102,7 +104,10 @@ test.describe('Code pane and errors', () => { await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() // Open the code pane - await u.openKclCodePanel() + await editor.openPane() + + // Go to our problematic code again (missing closing paren!) + await editor.scrollToText('extrude(thickness, bracketLeg1Sketch') // Ensure that a badge appears on the button await expect(codePaneButtonHolder).toContainText('notification') diff --git a/e2e/playwright/fixtures/editorFixture.ts b/e2e/playwright/fixtures/editorFixture.ts index 73718e251..b5767d81d 100644 --- a/e2e/playwright/fixtures/editorFixture.ts +++ b/e2e/playwright/fixtures/editorFixture.ts @@ -147,4 +147,16 @@ export class EditorFixture { openPane() { return openPane(this.page, this.paneButtonTestId) } + scrollToText(text: string) { + return this.page.evaluate((scrollToText: string) => { + // editorManager is available on the window object. + let index = editorManager._editorView.docView.view.state.doc.toString().indexOf(scrollToText) + editorManager._editorView.dispatch({ + selection: { + anchor: index + }, + scrollIntoView: true, + }) + }, text) + } } diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index f843503b0..b72e94a07 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -151,6 +151,17 @@ export async function closePane(page: Page, testId: string) { async function openKclCodePanel(page: Page) { await openPane(page, 'code-pane-button') + + // Code Mirror lazy loads text! Wowza! Let's force-load the text for tests. + await page.evaluate(() => { + // editorManager is available on the window object. + editorManager._editorView.dispatch({ + selection: { + anchor: editorManager._editorView.docView.length + }, + scrollIntoView: true, + }) + }) } async function closeKclCodePanel(page: Page) {