file-tree.spec.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { test, expect } from "../fixtures"
  2. test("file tree can expand folders and open a file", async ({ page, gotoSession }) => {
  3. await gotoSession()
  4. const toggle = page.getByRole("button", { name: "Toggle file tree" })
  5. const panel = page.locator("#file-tree-panel")
  6. const treeTabs = panel.locator('[data-component="tabs"][data-variant="pill"][data-scope="filetree"]')
  7. await expect(toggle).toBeVisible()
  8. if ((await toggle.getAttribute("aria-expanded")) !== "true") await toggle.click()
  9. await expect(toggle).toHaveAttribute("aria-expanded", "true")
  10. await expect(panel).toBeVisible()
  11. await expect(treeTabs).toBeVisible()
  12. const allTab = treeTabs.getByRole("tab", { name: /^all files$/i })
  13. await expect(allTab).toBeVisible()
  14. await allTab.click()
  15. await expect(allTab).toHaveAttribute("aria-selected", "true")
  16. const tree = treeTabs.locator('[data-slot="tabs-content"]:not([hidden])')
  17. await expect(tree).toBeVisible()
  18. const expand = async (name: string) => {
  19. const folder = tree.getByRole("button", { name, exact: true }).first()
  20. await expect(folder).toBeVisible()
  21. await expect(folder).toHaveAttribute("aria-expanded", /true|false/)
  22. if ((await folder.getAttribute("aria-expanded")) === "false") await folder.click()
  23. await expect(folder).toHaveAttribute("aria-expanded", "true")
  24. }
  25. await expand("packages")
  26. await expand("app")
  27. await expand("src")
  28. await expand("components")
  29. const file = tree.getByRole("button", { name: "file-tree.tsx", exact: true }).first()
  30. await expect(file).toBeVisible()
  31. await file.click()
  32. const tab = page.getByRole("tab", { name: "file-tree.tsx" })
  33. await expect(tab).toBeVisible()
  34. await tab.click()
  35. await expect(tab).toHaveAttribute("aria-selected", "true")
  36. const viewer = page.locator('[data-component="file"][data-mode="text"]').first()
  37. await expect(viewer).toBeVisible()
  38. await expect(viewer).toContainText("export default function FileTree")
  39. })