Completely fix code mirror text navigating for tests

This commit is contained in:
49lf
2024-11-25 12:50:09 -05:00
parent 4c28af615c
commit e50683af5b
3 changed files with 31 additions and 3 deletions

View File

@ -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')

View File

@ -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)
}
}

View File

@ -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) {