mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
187 lines
9 KiB
TypeScript
187 lines
9 KiB
TypeScript
import { expect, story } from "../../storybook/playwright/story"
|
|
|
|
story("resizes the dock to fit different answer counts", async ({ mount }) => {
|
|
const component = await mount("app-current-session-surface--question-answer-counts")
|
|
const question = component.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
const next = question.getByRole("button", { name: "Next", exact: true })
|
|
await expect(question.getByRole("radio", { name: /Focused/ })).toBeFocused()
|
|
await expect(next).toBeEnabled()
|
|
|
|
const height = () => question.evaluate((element) => element.getBoundingClientRect().height)
|
|
const initial = await height()
|
|
await next.click()
|
|
await expect.poll(height).toBeGreaterThan(initial)
|
|
await expect(question.getByRole("checkbox", { name: "Diagnostics", exact: true })).toBeVisible()
|
|
|
|
const expanded = await height()
|
|
const back = question.getByRole("button", { name: "Back", exact: true })
|
|
await expect(back).toBeEnabled()
|
|
await back.click()
|
|
await expect.poll(height).toBeLessThan(expanded)
|
|
await expect(question.getByRole("radio", { name: /Focused/ })).toBeVisible()
|
|
})
|
|
|
|
story("selects single answers and toggles multiple answers with number keys", async ({ mount }) => {
|
|
const component = await mount("app-current-session-surface--question-request")
|
|
const question = component.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
const focused = question.getByRole("radio", { name: /Focused/ })
|
|
const wide = question.getByRole("radio", { name: /Wide/ })
|
|
const customRadio = question.getByRole("radio", { name: "Type your own answer…", exact: true })
|
|
const input = question.getByRole("textbox", { name: "Type your own answer…", exact: true })
|
|
const next = question.getByRole("button", { name: "Next", exact: true })
|
|
await expect(focused).toBeFocused()
|
|
|
|
await focused.press("2")
|
|
await expect(wide).toBeChecked()
|
|
await expect(focused).not.toBeChecked()
|
|
await expect(wide).toBeFocused()
|
|
await next.press("1")
|
|
await expect(focused).toBeChecked()
|
|
await expect(wide).not.toBeChecked()
|
|
await focused.press("3")
|
|
await expect(customRadio).toBeChecked()
|
|
await expect(input).toBeFocused()
|
|
await expect(focused).not.toBeChecked()
|
|
await expect(wide).not.toBeChecked()
|
|
await input.press("Enter")
|
|
await expect(customRadio).toBeFocused()
|
|
await customRadio.press("2")
|
|
await expect(wide).toBeChecked()
|
|
await expect(customRadio).not.toBeChecked()
|
|
|
|
await next.click()
|
|
const files = question.getByRole("checkbox", { name: "Changed files", exact: true })
|
|
const terminal = question.getByRole("checkbox", { name: "Terminal", exact: true })
|
|
const customCheckbox = question.getByRole("checkbox", { name: "Type your own answer…", exact: true })
|
|
await expect(files).toBeFocused()
|
|
await files.press("1")
|
|
await expect(files).toBeChecked()
|
|
await files.press("2")
|
|
await expect(terminal).toBeChecked()
|
|
await expect(files).toBeChecked()
|
|
await terminal.press("2")
|
|
await expect(terminal).not.toBeChecked()
|
|
await expect(files).toBeChecked()
|
|
|
|
await terminal.press("4")
|
|
await expect(customCheckbox).toBeChecked()
|
|
await expect(input).toBeFocused()
|
|
await expect(files).toBeChecked()
|
|
await expect(terminal).not.toBeChecked()
|
|
await input.press("Enter")
|
|
await expect(customCheckbox).toBeFocused()
|
|
await customCheckbox.press("4")
|
|
await expect(customCheckbox).not.toBeChecked()
|
|
await expect(files).toBeChecked()
|
|
await expect(terminal).not.toBeChecked()
|
|
})
|
|
|
|
story("ignores modified, out-of-range, and repeated number shortcuts", async ({ mount, page }) => {
|
|
const component = await mount("app-current-session-surface--question-request")
|
|
const question = component.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
const focused = question.getByRole("radio", { name: /Focused/ })
|
|
const wide = question.getByRole("radio", { name: /Wide/ })
|
|
await expect(focused).toBeFocused()
|
|
await focused.press("1")
|
|
await focused.press("9")
|
|
await focused.press("Alt+2")
|
|
await expect(focused).toBeChecked()
|
|
await expect(wide).not.toBeChecked()
|
|
|
|
await question.getByRole("button", { name: "Next", exact: true }).click()
|
|
const terminal = question.getByRole("checkbox", { name: "Terminal", exact: true })
|
|
await expect(question.getByRole("checkbox", { name: "Changed files", exact: true })).toBeFocused()
|
|
await page.keyboard.down("2")
|
|
await expect(terminal).toBeChecked()
|
|
await page.keyboard.down("2")
|
|
await expect(terminal).toBeChecked()
|
|
await page.keyboard.up("2")
|
|
})
|
|
|
|
story("types digits into the custom answer without selecting numbered options", async ({ mount }) => {
|
|
const component = await mount("app-current-session-surface--question-request")
|
|
const question = component.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
const focused = question.getByRole("radio", { name: /Focused/ })
|
|
const custom = question.getByRole("radio", { name: "Type your own answer…", exact: true })
|
|
const input = question.getByRole("textbox", { name: "Type your own answer…", exact: true })
|
|
await expect(focused).toBeFocused()
|
|
await focused.press("3")
|
|
await expect(input).toBeFocused()
|
|
await input.press("1")
|
|
await input.press("2")
|
|
await input.press("3")
|
|
await expect(input).toHaveValue("123")
|
|
await expect(custom).toBeChecked()
|
|
await expect(focused).not.toBeChecked()
|
|
await expect(question.getByRole("radio", { name: /Wide/ })).not.toBeChecked()
|
|
})
|
|
|
|
story("shows question navigation shortcuts in buttons and tooltips", async ({ mount, page }) => {
|
|
const component = await mount("app-current-session-surface--question-request")
|
|
const mac = await page.evaluate(() => /Mac|iPhone|iPad|iPod/.test(navigator.platform))
|
|
const shortcut = mac ? "⌘⏎" : "Ctrl+⏎"
|
|
const next = component.getByRole("button", { name: "Next", exact: true })
|
|
await expect(next.locator('[data-slot="question-submit-shortcut"]')).toBeVisible()
|
|
await expect(next.locator('[data-slot="question-submit-shortcut"]')).toHaveText(shortcut)
|
|
await expect(next).toHaveAttribute("aria-keyshortcuts", "Meta+Enter Control+Enter")
|
|
await next.hover()
|
|
await expect(page.getByRole("tooltip")).toContainText("Next")
|
|
await expect(page.getByRole("tooltip")).toContainText(shortcut)
|
|
await next.press(mac ? "Meta+Enter" : "Control+Enter")
|
|
const submit = component.getByRole("button", { name: "Submit", exact: true })
|
|
await expect(submit.locator('[data-slot="question-submit-shortcut"]')).toBeVisible()
|
|
await expect(submit.locator('[data-slot="question-submit-shortcut"]')).toHaveText(shortcut)
|
|
await expect(submit).toHaveAttribute("aria-keyshortcuts", "Meta+Enter Control+Enter")
|
|
await submit.hover()
|
|
await expect(page.getByRole("tooltip")).toContainText("Submit")
|
|
await expect(page.getByRole("tooltip")).toContainText(shortcut)
|
|
const back = component.getByRole("button", { name: "Back", exact: true })
|
|
await expect(back).toHaveText("Back")
|
|
await expect(back).toHaveAttribute("aria-keyshortcuts", mac ? "Meta+[" : "Alt+ArrowLeft")
|
|
await back.hover()
|
|
await expect(page.getByRole("tooltip")).toContainText(mac ? "⌘[" : "Alt+←")
|
|
await back.press(mac ? "Meta+[" : "Alt+ArrowLeft")
|
|
await expect(next).toBeVisible()
|
|
})
|
|
|
|
story("keeps the custom answer input and dock geometry stable while editing", async ({ mount }) => {
|
|
const component = await mount("app-current-session-surface--question-request")
|
|
const question = component.locator('[data-component="dock-prompt"][data-kind="question"]')
|
|
const row = question.locator('[data-slot="question-option"][data-custom="true"]')
|
|
const input = question.getByRole("textbox", { name: "Type your own answer…", exact: true })
|
|
const toggle = question.getByRole("radio", { name: "Type your own answer…", exact: true })
|
|
await expect(question.getByRole("radio", { name: /Focused/ })).toBeFocused()
|
|
await expect(input).toBeEditable()
|
|
await expect(input).toHaveValue("")
|
|
const node = await input.evaluateHandle((element) => element)
|
|
const height = () => question.evaluate((element) => element.getBoundingClientRect().height)
|
|
const initial = await height()
|
|
const draft = "A custom answer long enough to wrap if the editor becomes multiline instead of staying single-line"
|
|
|
|
const predefined = question.getByRole("radio", { name: /Focused/ })
|
|
await predefined.click()
|
|
await input.focus()
|
|
await expect(input).toBeFocused()
|
|
await expect(predefined).toBeChecked()
|
|
await expect(toggle).not.toBeChecked()
|
|
await row.click({ position: { x: 4, y: 4 } })
|
|
await expect(toggle).toBeChecked()
|
|
await expect(input).toBeFocused()
|
|
await expect(input).toHaveValue("")
|
|
await expect(predefined).not.toBeChecked()
|
|
await input.fill(draft)
|
|
await expect(input).toHaveValue(draft)
|
|
await expect(toggle).toBeChecked()
|
|
await expect(predefined).not.toBeChecked()
|
|
await expect.poll(height).toBe(initial)
|
|
await input.press("Enter")
|
|
await expect(toggle).toBeFocused()
|
|
await expect(input).toHaveValue(draft)
|
|
await row.click({ position: { x: 30, y: 20 } })
|
|
await expect(input).toBeFocused()
|
|
await expect(input).toHaveValue(draft)
|
|
await expect
|
|
.poll(() => input.evaluate((element, original) => element === original && original.isConnected, node))
|
|
.toBe(true)
|
|
await node.dispose()
|
|
})
|