file-viewer.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { test, expect } from "../fixtures"
  2. import { promptSelector } from "../selectors"
  3. test("smoke file viewer renders real file content", async ({ page, gotoSession }) => {
  4. await gotoSession()
  5. await page.locator(promptSelector).click()
  6. await page.keyboard.type("/open")
  7. const command = page.locator('[data-slash-id="file.open"]').first()
  8. await expect(command).toBeVisible()
  9. await page.keyboard.press("Enter")
  10. const dialog = page
  11. .getByRole("dialog")
  12. .filter({ has: page.getByPlaceholder(/search files/i) })
  13. .first()
  14. await expect(dialog).toBeVisible()
  15. const input = dialog.getByRole("textbox").first()
  16. await input.fill("package.json")
  17. const items = dialog.locator('[data-slot="list-item"][data-key^="file:"]')
  18. let index = -1
  19. await expect
  20. .poll(
  21. async () => {
  22. const keys = await items.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-key") ?? ""))
  23. index = keys.findIndex((key) => /packages[\\/]+app[\\/]+package\.json$/i.test(key.replace(/^file:/, "")))
  24. return index >= 0
  25. },
  26. { timeout: 30_000 },
  27. )
  28. .toBe(true)
  29. const item = items.nth(index)
  30. await expect(item).toBeVisible()
  31. await item.click()
  32. await expect(dialog).toHaveCount(0)
  33. const tab = page.getByRole("tab", { name: "package.json" })
  34. await expect(tab).toBeVisible()
  35. await tab.click()
  36. const code = page.locator('[data-component="code"]').first()
  37. await expect(code).toBeVisible()
  38. await expect(code.getByText(/"name"\s*:\s*"@opencode-ai\/app"/)).toBeVisible()
  39. })