file-viewer.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { test, expect } from "../fixtures"
  2. import { promptSelector } from "../selectors"
  3. import { modKey } from "../utils"
  4. test("smoke file viewer renders real file content", async ({ page, gotoSession }) => {
  5. await gotoSession()
  6. await page.locator(promptSelector).click()
  7. await page.keyboard.type("/open")
  8. const command = page.locator('[data-slash-id="file.open"]').first()
  9. await expect(command).toBeVisible()
  10. await page.keyboard.press("Enter")
  11. const dialog = page
  12. .getByRole("dialog")
  13. .filter({ has: page.getByPlaceholder(/search files/i) })
  14. .first()
  15. await expect(dialog).toBeVisible()
  16. const input = dialog.getByRole("textbox").first()
  17. await input.fill("package.json")
  18. const items = dialog.locator('[data-slot="list-item"][data-key^="file:"]')
  19. let index = -1
  20. await expect
  21. .poll(
  22. async () => {
  23. const keys = await items.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-key") ?? ""))
  24. index = keys.findIndex((key) => /packages[\\/]+app[\\/]+package\.json$/i.test(key.replace(/^file:/, "")))
  25. return index >= 0
  26. },
  27. { timeout: 30_000 },
  28. )
  29. .toBe(true)
  30. const item = items.nth(index)
  31. await expect(item).toBeVisible()
  32. await item.click()
  33. await expect(dialog).toHaveCount(0)
  34. const tab = page.getByRole("tab", { name: "package.json" })
  35. await expect(tab).toBeVisible()
  36. await tab.click()
  37. const viewer = page.locator('[data-component="file"][data-mode="text"]').first()
  38. await expect(viewer).toBeVisible()
  39. await expect(viewer.getByText(/"name"\s*:\s*"@opencode-ai\/app"/)).toBeVisible()
  40. })
  41. test("cmd+f opens text viewer search while prompt is focused", async ({ page, gotoSession }) => {
  42. await gotoSession()
  43. await page.locator(promptSelector).click()
  44. await page.keyboard.type("/open")
  45. const command = page.locator('[data-slash-id="file.open"]').first()
  46. await expect(command).toBeVisible()
  47. await page.keyboard.press("Enter")
  48. const dialog = page
  49. .getByRole("dialog")
  50. .filter({ has: page.getByPlaceholder(/search files/i) })
  51. .first()
  52. await expect(dialog).toBeVisible()
  53. const input = dialog.getByRole("textbox").first()
  54. await input.fill("package.json")
  55. const items = dialog.locator('[data-slot="list-item"][data-key^="file:"]')
  56. let index = -1
  57. await expect
  58. .poll(
  59. async () => {
  60. const keys = await items.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-key") ?? ""))
  61. index = keys.findIndex((key) => /packages[\\/]+app[\\/]+package\.json$/i.test(key.replace(/^file:/, "")))
  62. return index >= 0
  63. },
  64. { timeout: 30_000 },
  65. )
  66. .toBe(true)
  67. const item = items.nth(index)
  68. await expect(item).toBeVisible()
  69. await item.click()
  70. await expect(dialog).toHaveCount(0)
  71. const tab = page.getByRole("tab", { name: "package.json" })
  72. await expect(tab).toBeVisible()
  73. await tab.click()
  74. const viewer = page.locator('[data-component="file"][data-mode="text"]').first()
  75. await expect(viewer).toBeVisible()
  76. await page.locator(promptSelector).click()
  77. await page.keyboard.press(`${modKey}+f`)
  78. const findInput = page.getByPlaceholder("Find")
  79. await expect(findInput).toBeVisible()
  80. await expect(findInput).toBeFocused()
  81. })