test(app): e2e utilities

This commit is contained in:
Adam
2026-01-18 05:43:34 -06:00
parent f5eb90514a
commit dd19c3d8f2
6 changed files with 69 additions and 87 deletions

View File

@@ -1,33 +1,17 @@
import { test, expect } from "@playwright/test"
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
import { base64Encode } from "@opencode-ai/util/encode"
const host = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
const port = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
const url = `http://${host}:${port}`
async function getWorktree() {
const sdk = createOpencodeClient({ baseUrl: url, throwOnError: true })
const result = await sdk.path.get()
const data = result.data
if (!data?.worktree) throw new Error(`Failed to resolve a worktree from ${url}/path`)
return data.worktree
}
import { gotoSession, promptSelector, terminalSelector, terminalToggleKey } from "./utils"
test("terminal panel can be toggled", async ({ page }) => {
const directory = await getWorktree()
const slug = base64Encode(directory)
await gotoSession(page)
await expect(page.locator(promptSelector)).toBeVisible()
await page.goto(`/${slug}/session`)
await expect(page.locator('[data-component="prompt-input"]')).toBeVisible()
const terminal = page.locator('[data-component="terminal"]')
const terminal = page.locator(terminalSelector)
const initiallyOpen = await terminal.isVisible()
if (initiallyOpen) {
await page.keyboard.press("Control+Backquote")
await page.keyboard.press(terminalToggleKey)
await expect(terminal).toHaveCount(0)
}
await page.keyboard.press("Control+Backquote")
await page.keyboard.press(terminalToggleKey)
await expect(terminal).toBeVisible()
})