|
| 1 | +import { expect, test } from "@playwright/test" |
| 2 | +import { base64Encode } from "@opencode-ai/core/util/encode" |
| 3 | +import { mockOpenCodeServer } from "../utils/mock-server" |
| 4 | +import { expectAppVisible } from "../utils/waits" |
| 5 | + |
| 6 | +const directory = "C:/OpenCode/PromptShellModeButtonRegression" |
| 7 | +const projectID = "proj_prompt_shell_mode_button_regression" |
| 8 | +const sessionID = "ses_prompt_shell_mode_button_regression" |
| 9 | + |
| 10 | +const baseConfig = { |
| 11 | + directory, |
| 12 | + project: { |
| 13 | + id: projectID, |
| 14 | + worktree: directory, |
| 15 | + vcs: "git", |
| 16 | + name: "prompt-shell-mode-button-regression", |
| 17 | + time: { created: 1700000000000, updated: 1700000000000 }, |
| 18 | + sandboxes: [], |
| 19 | + }, |
| 20 | + provider: { |
| 21 | + all: [ |
| 22 | + { |
| 23 | + id: "opencode", |
| 24 | + name: "OpenCode", |
| 25 | + models: { |
| 26 | + "test-model": { |
| 27 | + id: "test-model", |
| 28 | + name: "Test Model", |
| 29 | + limit: { context: 200_000 }, |
| 30 | + variants: {}, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + ], |
| 35 | + connected: ["opencode"], |
| 36 | + default: { providerID: "opencode", modelID: "test-model" }, |
| 37 | + }, |
| 38 | + sessions: [ |
| 39 | + { |
| 40 | + id: sessionID, |
| 41 | + slug: "prompt-shell-mode-button-regression", |
| 42 | + projectID, |
| 43 | + directory, |
| 44 | + title: "Prompt shell mode button regression", |
| 45 | + version: "dev", |
| 46 | + time: { created: 1700000000000, updated: 1700000000000 }, |
| 47 | + }, |
| 48 | + ], |
| 49 | + pageMessages: () => ({ items: [] }), |
| 50 | +} |
| 51 | + |
| 52 | +test.describe("regression: shell mode toggle button in v2 composer", () => { |
| 53 | + test.beforeEach(async ({ page }) => { |
| 54 | + await mockOpenCodeServer(page, baseConfig) |
| 55 | + await page.addInitScript(() => { |
| 56 | + localStorage.setItem("settings.v3", JSON.stringify({ general: { newLayoutDesigns: true } })) |
| 57 | + }) |
| 58 | + await page.goto(`/${base64Encode(directory)}/session/${sessionID}`) |
| 59 | + await expectAppVisible(page.locator('[data-component="session-composer"]')) |
| 60 | + }) |
| 61 | + |
| 62 | + test("shell mode button is visible in v2 composer toolbar", async ({ page }) => { |
| 63 | + const button = page.locator('[data-action="prompt-shell-mode"]') |
| 64 | + await expect(button).toBeVisible() |
| 65 | + }) |
| 66 | + |
| 67 | + test("shell mode button enters shell mode on click", async ({ page }) => { |
| 68 | + const button = page.locator('[data-action="prompt-shell-mode"]') |
| 69 | + const input = page.locator('[data-component="prompt-input"]') |
| 70 | + |
| 71 | + await button.click() |
| 72 | + |
| 73 | + // aria-pressed reflects active shell mode |
| 74 | + await expect(button).toHaveAttribute("aria-pressed", "true") |
| 75 | + // input switches to monospace font in shell mode (font-mono! class) |
| 76 | + await expect(input).toHaveClass(/font-mono/) |
| 77 | + }) |
| 78 | + |
| 79 | + test("shell mode button exits shell mode on second click", async ({ page }) => { |
| 80 | + const button = page.locator('[data-action="prompt-shell-mode"]') |
| 81 | + const input = page.locator('[data-component="prompt-input"]') |
| 82 | + |
| 83 | + await button.click() |
| 84 | + await expect(button).toHaveAttribute("aria-pressed", "true") |
| 85 | + |
| 86 | + await button.click() |
| 87 | + await expect(button).toHaveAttribute("aria-pressed", "false") |
| 88 | + await expect(input).not.toHaveClass(/font-mono/) |
| 89 | + }) |
| 90 | + |
| 91 | + test("Escape exits shell mode entered via button", async ({ page }) => { |
| 92 | + const button = page.locator('[data-action="prompt-shell-mode"]') |
| 93 | + const input = page.locator('[data-component="prompt-input"]') |
| 94 | + |
| 95 | + await button.click() |
| 96 | + await expect(button).toHaveAttribute("aria-pressed", "true") |
| 97 | + |
| 98 | + await input.focus() |
| 99 | + await page.keyboard.press("Escape") |
| 100 | + await expect(button).toHaveAttribute("aria-pressed", "false") |
| 101 | + }) |
| 102 | + |
| 103 | + test("! shortcut still enters shell mode and button reflects state", async ({ page }) => { |
| 104 | + const button = page.locator('[data-action="prompt-shell-mode"]') |
| 105 | + const input = page.locator('[data-component="prompt-input"]') |
| 106 | + |
| 107 | + await input.focus() |
| 108 | + await page.keyboard.press("!") |
| 109 | + await expect(button).toHaveAttribute("aria-pressed", "true") |
| 110 | + }) |
| 111 | +}) |
0 commit comments