projects-close.spec.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { test, expect } from "../fixtures"
  2. import { createTestProject, cleanupTestProject, openSidebar, clickMenuItem, openProjectMenu } from "../actions"
  3. import { projectSwitchSelector } from "../selectors"
  4. import { dirSlug } from "../utils"
  5. test("closing active project navigates to another open project", async ({ page, withProject }) => {
  6. await page.setViewportSize({ width: 1400, height: 800 })
  7. const other = await createTestProject()
  8. const otherSlug = dirSlug(other)
  9. try {
  10. await withProject(
  11. async ({ slug }) => {
  12. await openSidebar(page)
  13. const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
  14. await expect(otherButton).toBeVisible()
  15. await otherButton.click()
  16. await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
  17. const menu = await openProjectMenu(page, otherSlug)
  18. await clickMenuItem(menu, /^Close$/i, { force: true })
  19. await expect
  20. .poll(
  21. () => {
  22. const pathname = new URL(page.url()).pathname
  23. if (new RegExp(`^/${slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
  24. if (pathname === "/") return "home"
  25. return ""
  26. },
  27. { timeout: 15_000 },
  28. )
  29. .toMatch(/^(project|home)$/)
  30. await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
  31. await expect
  32. .poll(
  33. async () => {
  34. return await page.locator(projectSwitchSelector(otherSlug)).count()
  35. },
  36. { timeout: 15_000 },
  37. )
  38. .toBe(0)
  39. },
  40. { extra: [other] },
  41. )
  42. } finally {
  43. await cleanupTestProject(other)
  44. }
  45. })