context.spec.ts 3.0 KB

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