projects-close.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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, project }) => {
  6. await page.setViewportSize({ width: 1400, height: 800 })
  7. const other = await createTestProject()
  8. const otherSlug = dirSlug(other)
  9. try {
  10. await project.open({ extra: [other] })
  11. await openSidebar(page)
  12. const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
  13. await expect(otherButton).toBeVisible()
  14. await otherButton.click()
  15. await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
  16. const menu = await openProjectMenu(page, otherSlug)
  17. await clickMenuItem(menu, /^Close$/i, { force: true })
  18. await expect
  19. .poll(
  20. () => {
  21. const pathname = new URL(page.url()).pathname
  22. if (new RegExp(`^/${project.slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
  23. if (pathname === "/") return "home"
  24. return ""
  25. },
  26. { timeout: 15_000 },
  27. )
  28. .toMatch(/^(project|home)$/)
  29. await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
  30. await expect
  31. .poll(
  32. async () => {
  33. return await page.locator(projectSwitchSelector(otherSlug)).count()
  34. },
  35. { timeout: 15_000 },
  36. )
  37. .toBe(0)
  38. } finally {
  39. await cleanupTestProject(other)
  40. }
  41. })