projects-close.spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { test, expect } from "../fixtures"
  2. import { createTestProject, cleanupTestProject, openSidebar, clickMenuItem, openProjectMenu } from "../actions"
  3. import { projectCloseHoverSelector, projectSwitchSelector } from "../selectors"
  4. import { dirSlug } from "../utils"
  5. test("can close a project via hover card close button", 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 () => {
  12. await openSidebar(page)
  13. const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
  14. await expect(otherButton).toBeVisible()
  15. await otherButton.hover()
  16. const close = page.locator(projectCloseHoverSelector(otherSlug)).first()
  17. await expect(close).toBeVisible()
  18. await close.click()
  19. await expect(otherButton).toHaveCount(0)
  20. },
  21. { extra: [other] },
  22. )
  23. } finally {
  24. await cleanupTestProject(other)
  25. }
  26. })
  27. test("closing active project navigates to another open project", async ({ page, withProject }) => {
  28. await page.setViewportSize({ width: 1400, height: 800 })
  29. const other = await createTestProject()
  30. const otherSlug = dirSlug(other)
  31. try {
  32. await withProject(
  33. async ({ slug }) => {
  34. await openSidebar(page)
  35. const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
  36. await expect(otherButton).toBeVisible()
  37. await otherButton.click()
  38. await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
  39. const menu = await openProjectMenu(page, otherSlug)
  40. await clickMenuItem(menu, /^Close$/i, { force: true })
  41. await expect
  42. .poll(() => {
  43. const pathname = new URL(page.url()).pathname
  44. if (new RegExp(`^/${slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
  45. if (pathname === "/") return "home"
  46. return ""
  47. })
  48. .toMatch(/^(project|home)$/)
  49. await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
  50. await expect(otherButton).toHaveCount(0)
  51. },
  52. { extra: [other] },
  53. )
  54. } finally {
  55. await cleanupTestProject(other)
  56. }
  57. })