Skip to content

Commit

Permalink
fix: command palette e2e tests (#3588)
Browse files Browse the repository at this point in the history
Also adds a helper for pressing shortcut keys like `CMD+k`
  • Loading branch information
wesbillman authored Nov 29, 2024
1 parent 3a1193b commit a98f447
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
28 changes: 28 additions & 0 deletions frontend/console/e2e/command-palette.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, test } from '@playwright/test'
import { pressShortcut } from './helpers'

test('shows command palette results', async ({ page }) => {
await page.goto('http://localhost:8892')

await page.click('#command-palette-search')
await page.fill('#command-palette-search-input', 'echo')

// Command palette should be showing the echo parts
await expect(page.locator('[role="listbox"]').getByText('echo.EchoRequest', { exact: true })).toBeVisible()
await expect(page.locator('[role="listbox"]').getByText('echo.EchoResponse', { exact: true })).toBeVisible()
await expect(page.locator('[role="listbox"]').getByText('echo.echo', { exact: true })).toBeVisible()
})

test('opens command palette with keyboard shortcut', async ({ page }) => {
await page.goto('http://localhost:8892')

await pressShortcut(page, 'k')

await expect(page.locator('#command-palette-search-input')).toBeVisible()
await page.fill('#command-palette-search-input', 'echo')

// Command palette should be showing the echo parts
await expect(page.locator('[role="listbox"]').getByText('echo.EchoRequest', { exact: true })).toBeVisible()
await expect(page.locator('[role="listbox"]').getByText('echo.EchoResponse', { exact: true })).toBeVisible()
await expect(page.locator('[role="listbox"]').getByText('echo.echo', { exact: true })).toBeVisible()
})
13 changes: 0 additions & 13 deletions frontend/console/e2e/command-palette.ts

This file was deleted.

10 changes: 10 additions & 0 deletions frontend/console/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ export async function navigateToDecl(page: Page, moduleName: string, declName: s
await page.locator(`a#decl-${declName}`).click()
await expect(page).toHaveURL(new RegExp(`/modules/${moduleName}/verb/${declName}`))
}

export async function pressShortcut(page: Page, key: string) {
// Get the platform-specific modifier key
const isMac = await page.evaluate(() => navigator.userAgent.includes('Mac'))
const modifier = isMac ? 'Meta' : 'Control'

await page.keyboard.down(modifier)
await page.keyboard.press(key)
await page.keyboard.up(modifier)
}

0 comments on commit a98f447

Please sign in to comment.