projects-close.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. const pathname = new URL(page.url()).pathname
  22. if (new RegExp(`^/${slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
  23. if (pathname === "/") return "home"
  24. return ""
  25. })
  26. .toMatch(/^(project|home)$/)
  27. await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
  28. await expect(otherButton).toHaveCount(0)
  29. },
  30. { extra: [other] },
  31. )
  32. } finally {
  33. await cleanupTestProject(other)
  34. }
  35. })