summaryrefslogtreecommitdiffhomepage
path: root/packages/app/e2e/projects/projects-close.spec.ts
blob: 9454d683f021d4ed7fdf21be9cc8b5d0691521bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { test, expect } from "../fixtures"
import { createTestProject, cleanupTestProject, openSidebar, clickMenuItem, openProjectMenu } from "../actions"
import { projectSwitchSelector } from "../selectors"
import { dirSlug } from "../utils"

test("closing active project navigates to another open project", async ({ page, withProject }) => {
  await page.setViewportSize({ width: 1400, height: 800 })

  const other = await createTestProject()
  const otherSlug = dirSlug(other)

  try {
    await withProject(
      async ({ slug }) => {
        await openSidebar(page)

        const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
        await expect(otherButton).toBeVisible()
        await otherButton.click()

        await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))

        const menu = await openProjectMenu(page, otherSlug)

        await clickMenuItem(menu, /^Close$/i, { force: true })

        await expect
          .poll(
            () => {
              const pathname = new URL(page.url()).pathname
              if (new RegExp(`^/${slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
              if (pathname === "/") return "home"
              return ""
            },
            { timeout: 15_000 },
          )
          .toMatch(/^(project|home)$/)

        await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
        await expect
          .poll(
            async () => {
              return await page.locator(projectSwitchSelector(otherSlug)).count()
            },
            { timeout: 15_000 },
          )
          .toBe(0)
      },
      { extra: [other] },
    )
  } finally {
    await cleanupTestProject(other)
  }
})