sidebar.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { test, expect } from "../fixtures"
  2. import { openSidebar, toggleSidebar, withSession } from "../actions"
  3. test("sidebar can be collapsed and expanded", async ({ page, gotoSession }) => {
  4. await gotoSession()
  5. await openSidebar(page)
  6. const button = page.getByRole("button", { name: /toggle sidebar/i }).first()
  7. await expect(button).toHaveAttribute("aria-expanded", "true")
  8. await toggleSidebar(page)
  9. await expect(button).toHaveAttribute("aria-expanded", "false")
  10. await toggleSidebar(page)
  11. await expect(button).toHaveAttribute("aria-expanded", "true")
  12. })
  13. test("sidebar collapsed state persists across navigation and reload", async ({ page, sdk, gotoSession }) => {
  14. await withSession(sdk, "sidebar persist session 1", async (session1) => {
  15. await withSession(sdk, "sidebar persist session 2", async (session2) => {
  16. await gotoSession(session1.id)
  17. await openSidebar(page)
  18. const button = page.getByRole("button", { name: /toggle sidebar/i }).first()
  19. await toggleSidebar(page)
  20. await expect(button).toHaveAttribute("aria-expanded", "false")
  21. await gotoSession(session2.id)
  22. await expect(button).toHaveAttribute("aria-expanded", "false")
  23. await page.reload()
  24. await expect(button).toHaveAttribute("aria-expanded", "false")
  25. const opened = await page.evaluate(
  26. () => JSON.parse(localStorage.getItem("opencode.global.dat:layout") ?? "{}").sidebar?.opened,
  27. )
  28. await expect(opened).toBe(false)
  29. })
  30. })
  31. })