file-viewer.spec.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. })
  82. test("cmd+f opens text viewer search while prompt is not focused", async ({ page, gotoSession }) => {
  83. await gotoSession()
  84. await page.locator(promptSelector).click()
  85. await page.keyboard.type("/open")
  86. const command = page.locator('[data-slash-id="file.open"]').first()
  87. await expect(command).toBeVisible()
  88. await page.keyboard.press("Enter")
  89. const dialog = page
  90. .getByRole("dialog")
  91. .filter({ has: page.getByPlaceholder(/search files/i) })
  92. .first()
  93. await expect(dialog).toBeVisible()
  94. const input = dialog.getByRole("textbox").first()
  95. await input.fill("package.json")
  96. const items = dialog.locator('[data-slot="list-item"][data-key^="file:"]')
  97. let index = -1
  98. await expect
  99. .poll(
  100. async () => {
  101. const keys = await items.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-key") ?? ""))
  102. index = keys.findIndex((key) => /packages[\\/]+app[\\/]+package\.json$/i.test(key.replace(/^file:/, "")))
  103. return index >= 0
  104. },
  105. { timeout: 30_000 },
  106. )
  107. .toBe(true)
  108. const item = items.nth(index)
  109. await expect(item).toBeVisible()
  110. await item.click()
  111. await expect(dialog).toHaveCount(0)
  112. const tab = page.getByRole("tab", { name: "package.json" })
  113. await expect(tab).toBeVisible()
  114. await tab.click()
  115. const viewer = page.locator('[data-component="file"][data-mode="text"]').first()
  116. await expect(viewer).toBeVisible()
  117. await viewer.click()
  118. await page.keyboard.press(`${modKey}+f`)
  119. const findInput = page.getByPlaceholder("Find")
  120. await expect(findInput).toBeVisible()
  121. await expect(findInput).toBeFocused()
  122. })