Skip to content

Commit 3373340

Browse files
neriousybalcsida
authored andcommitted
feat(desktop): more e2e tests (anomalyco#13975)
1 parent 7988c51 commit 3373340

7 files changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector } from "../selectors"
3+
4+
test("ctrl+l focuses the prompt", async ({ page, gotoSession }) => {
5+
await gotoSession()
6+
7+
const prompt = page.locator(promptSelector)
8+
await expect(prompt).toBeVisible()
9+
10+
await page.locator("main").click({ position: { x: 5, y: 5 } })
11+
await expect(prompt).not.toBeFocused()
12+
13+
await page.keyboard.press("Control+L")
14+
await expect(prompt).toBeFocused()
15+
})
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { test, expect } from "../fixtures"
2+
import { modKey } from "../utils"
3+
4+
const expanded = async (el: { getAttribute: (name: string) => Promise<string | null> }) => {
5+
const value = await el.getAttribute("aria-expanded")
6+
if (value !== "true" && value !== "false") throw new Error(`Expected aria-expanded to be true|false, got: ${value}`)
7+
return value === "true"
8+
}
9+
10+
test("review panel can be toggled via keybind", async ({ page, gotoSession }) => {
11+
await gotoSession()
12+
13+
const treeToggle = page.getByRole("button", { name: "Toggle file tree" }).first()
14+
await expect(treeToggle).toBeVisible()
15+
if (await expanded(treeToggle)) await treeToggle.click()
16+
await expect(treeToggle).toHaveAttribute("aria-expanded", "false")
17+
18+
const reviewToggle = page.getByRole("button", { name: "Toggle review" }).first()
19+
await expect(reviewToggle).toBeVisible()
20+
if (await expanded(reviewToggle)) await reviewToggle.click()
21+
await expect(reviewToggle).toHaveAttribute("aria-expanded", "false")
22+
await expect(page.locator("#review-panel")).toHaveCount(0)
23+
24+
await page.keyboard.press(`${modKey}+Shift+R`)
25+
await expect(reviewToggle).toHaveAttribute("aria-expanded", "true")
26+
await expect(page.locator("#review-panel")).toBeVisible()
27+
28+
await page.keyboard.press(`${modKey}+Shift+R`)
29+
await expect(reviewToggle).toHaveAttribute("aria-expanded", "false")
30+
await expect(page.locator("#review-panel")).toHaveCount(0)
31+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector } from "../selectors"
3+
import { modKey } from "../utils"
4+
5+
test("mod+w closes the active file tab", async ({ page, gotoSession }) => {
6+
await gotoSession()
7+
8+
await page.locator(promptSelector).click()
9+
await page.keyboard.type("/open")
10+
await expect(page.locator('[data-slash-id="file.open"]').first()).toBeVisible()
11+
await page.keyboard.press("Enter")
12+
13+
const dialog = page
14+
.getByRole("dialog")
15+
.filter({ has: page.getByPlaceholder(/search files/i) })
16+
.first()
17+
await expect(dialog).toBeVisible()
18+
19+
await dialog.getByRole("textbox").first().fill("package.json")
20+
const item = dialog.locator('[data-slot="list-item"][data-key^="file:"]').first()
21+
await expect(item).toBeVisible({ timeout: 30_000 })
22+
await item.click()
23+
await expect(dialog).toHaveCount(0)
24+
25+
const tab = page.getByRole("tab", { name: "package.json" }).first()
26+
await expect(tab).toBeVisible()
27+
await tab.click()
28+
await expect(tab).toHaveAttribute("aria-selected", "true")
29+
30+
await page.keyboard.press(`${modKey}+W`)
31+
await expect(page.getByRole("tab", { name: "package.json" })).toHaveCount(0)
32+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector } from "../selectors"
3+
4+
test("dropping text/plain file: uri inserts a file pill", async ({ page, gotoSession }) => {
5+
await gotoSession()
6+
7+
const prompt = page.locator(promptSelector)
8+
await prompt.click()
9+
10+
const path = process.platform === "win32" ? "C:\\opencode-e2e-drop.txt" : "/tmp/opencode-e2e-drop.txt"
11+
const dt = await page.evaluateHandle((text) => {
12+
const dt = new DataTransfer()
13+
dt.setData("text/plain", text)
14+
return dt
15+
}, `file:${path}`)
16+
17+
await page.dispatchEvent("body", "drop", { dataTransfer: dt })
18+
19+
const pill = page.locator(`${promptSelector} [data-type="file"]`).first()
20+
await expect(pill).toBeVisible()
21+
await expect(pill).toHaveAttribute("data-path", path)
22+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector } from "../selectors"
3+
4+
test("dropping an image file adds an attachment", async ({ page, gotoSession }) => {
5+
await gotoSession()
6+
7+
const prompt = page.locator(promptSelector)
8+
await prompt.click()
9+
10+
const png = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO3+4uQAAAAASUVORK5CYII="
11+
const dt = await page.evaluateHandle((b64) => {
12+
const dt = new DataTransfer()
13+
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
14+
const file = new File([bytes], "drop.png", { type: "image/png" })
15+
dt.items.add(file)
16+
return dt
17+
}, png)
18+
19+
await page.dispatchEvent("body", "drop", { dataTransfer: dt })
20+
21+
const img = page.locator('img[alt="drop.png"]').first()
22+
await expect(img).toBeVisible()
23+
24+
const remove = page.getByRole("button", { name: "Remove attachment" }).first()
25+
await expect(remove).toBeVisible()
26+
27+
await img.hover()
28+
await remove.click()
29+
await expect(page.locator('img[alt="drop.png"]')).toHaveCount(0)
30+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector } from "../selectors"
3+
4+
test("shift+enter inserts a newline without submitting", async ({ page, gotoSession }) => {
5+
await gotoSession()
6+
7+
await expect(page).toHaveURL(/\/session\/?$/)
8+
9+
const prompt = page.locator(promptSelector)
10+
await prompt.click()
11+
await page.keyboard.type("line one")
12+
await page.keyboard.press("Shift+Enter")
13+
await page.keyboard.type("line two")
14+
15+
await expect(page).toHaveURL(/\/session\/?$/)
16+
await expect(prompt).toContainText("line one")
17+
await expect(prompt).toContainText("line two")
18+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { test, expect } from "../fixtures"
2+
import { promptSelector, terminalSelector } from "../selectors"
3+
4+
test("/terminal toggles the terminal panel", async ({ page, gotoSession }) => {
5+
await gotoSession()
6+
7+
const prompt = page.locator(promptSelector)
8+
const terminal = page.locator(terminalSelector)
9+
10+
await expect(terminal).not.toBeVisible()
11+
12+
await prompt.click()
13+
await page.keyboard.type("/terminal")
14+
await expect(page.locator('[data-slash-id="terminal.toggle"]').first()).toBeVisible()
15+
await page.keyboard.press("Enter")
16+
await expect(terminal).toBeVisible()
17+
18+
await prompt.click()
19+
await page.keyboard.type("/terminal")
20+
await expect(page.locator('[data-slash-id="terminal.toggle"]').first()).toBeVisible()
21+
await page.keyboard.press("Enter")
22+
await expect(terminal).not.toBeVisible()
23+
})

0 commit comments

Comments
 (0)