|
1 | 1 | import { test, expect } from "../fixtures" |
| 2 | +import type { Page } from "@playwright/test" |
2 | 3 | import { promptSelector } from "../selectors" |
3 | 4 | import { withSession } from "../actions" |
4 | 5 |
|
| 6 | +function contextButton(page: Page) { |
| 7 | + return page |
| 8 | + .locator('[data-component="button"]') |
| 9 | + .filter({ has: page.locator('[data-component="progress-circle"]').first() }) |
| 10 | + .first() |
| 11 | +} |
| 12 | + |
| 13 | +async function seedContextSession(input: { sessionID: string; sdk: Parameters<typeof withSession>[0] }) { |
| 14 | + await input.sdk.session.promptAsync({ |
| 15 | + sessionID: input.sessionID, |
| 16 | + noReply: true, |
| 17 | + parts: [ |
| 18 | + { |
| 19 | + type: "text", |
| 20 | + text: "seed context", |
| 21 | + }, |
| 22 | + ], |
| 23 | + }) |
| 24 | + |
| 25 | + await expect |
| 26 | + .poll(async () => { |
| 27 | + const messages = await input.sdk.session |
| 28 | + .messages({ sessionID: input.sessionID, limit: 1 }) |
| 29 | + .then((r) => r.data ?? []) |
| 30 | + return messages.length |
| 31 | + }) |
| 32 | + .toBeGreaterThan(0) |
| 33 | +} |
| 34 | + |
5 | 35 | test("context panel can be opened from the prompt", async ({ page, sdk, gotoSession }) => { |
6 | 36 | const title = `e2e smoke context ${Date.now()}` |
7 | 37 |
|
8 | 38 | await withSession(sdk, title, async (session) => { |
9 | | - await sdk.session.promptAsync({ |
10 | | - sessionID: session.id, |
11 | | - noReply: true, |
12 | | - parts: [ |
13 | | - { |
14 | | - type: "text", |
15 | | - text: "seed context", |
16 | | - }, |
17 | | - ], |
18 | | - }) |
| 39 | + await seedContextSession({ sessionID: session.id, sdk }) |
19 | 40 |
|
20 | | - await expect |
21 | | - .poll(async () => { |
22 | | - const messages = await sdk.session.messages({ sessionID: session.id, limit: 1 }).then((r) => r.data ?? []) |
23 | | - return messages.length |
24 | | - }) |
25 | | - .toBeGreaterThan(0) |
| 41 | + await gotoSession(session.id) |
| 42 | + |
| 43 | + const trigger = contextButton(page) |
| 44 | + await expect(trigger).toBeVisible() |
| 45 | + await trigger.click() |
| 46 | + |
| 47 | + const tabs = page.locator('[data-component="tabs"][data-variant="normal"]') |
| 48 | + await expect(tabs.getByRole("tab", { name: "Context" })).toBeVisible() |
| 49 | + }) |
| 50 | +}) |
26 | 51 |
|
| 52 | +test("context panel can be closed from the context tab close action", async ({ page, sdk, gotoSession }) => { |
| 53 | + await withSession(sdk, `e2e context toggle ${Date.now()}`, async (session) => { |
| 54 | + await seedContextSession({ sessionID: session.id, sdk }) |
27 | 55 | await gotoSession(session.id) |
28 | 56 |
|
29 | | - const contextButton = page |
30 | | - .locator('[data-component="button"]') |
31 | | - .filter({ has: page.locator('[data-component="progress-circle"]').first() }) |
32 | | - .first() |
| 57 | + await page.locator(promptSelector).click() |
33 | 58 |
|
34 | | - await expect(contextButton).toBeVisible() |
35 | | - await contextButton.click() |
| 59 | + const trigger = contextButton(page) |
| 60 | + await expect(trigger).toBeVisible() |
| 61 | + await trigger.click() |
36 | 62 |
|
37 | 63 | const tabs = page.locator('[data-component="tabs"][data-variant="normal"]') |
38 | | - await expect(tabs.getByRole("tab", { name: "Context" })).toBeVisible() |
| 64 | + const context = tabs.getByRole("tab", { name: "Context" }) |
| 65 | + await expect(context).toBeVisible() |
| 66 | + |
| 67 | + await page.getByRole("button", { name: "Close tab" }).first().click() |
| 68 | + await expect(context).toHaveCount(0) |
| 69 | + }) |
| 70 | +}) |
| 71 | + |
| 72 | +test("context panel can open file picker from context actions", async ({ page, sdk, gotoSession }) => { |
| 73 | + await withSession(sdk, `e2e context tabs ${Date.now()}`, async (session) => { |
| 74 | + await seedContextSession({ sessionID: session.id, sdk }) |
| 75 | + await gotoSession(session.id) |
| 76 | + |
| 77 | + await page.locator(promptSelector).click() |
| 78 | + |
| 79 | + const trigger = contextButton(page) |
| 80 | + await expect(trigger).toBeVisible() |
| 81 | + await trigger.click() |
| 82 | + |
| 83 | + await expect(page.getByRole("tab", { name: "Context" })).toBeVisible() |
| 84 | + await page.getByRole("button", { name: "Open file" }).first().click() |
| 85 | + |
| 86 | + const dialog = page |
| 87 | + .getByRole("dialog") |
| 88 | + .filter({ has: page.getByPlaceholder(/search files/i) }) |
| 89 | + .first() |
| 90 | + await expect(dialog).toBeVisible() |
| 91 | + |
| 92 | + await page.keyboard.press("Escape") |
| 93 | + await expect(dialog).toHaveCount(0) |
39 | 94 | }) |
40 | 95 | }) |
0 commit comments