opencode/packages/app/e2e/projects/projects-close.spec.ts

73 lines
2.2 KiB
TypeScript
Raw Normal View History

import { test, expect } from "../fixtures"
2026-02-11 23:11:41 +08:00
import { createTestProject, cleanupTestProject, openSidebar, clickMenuItem, openProjectMenu } from "../actions"
import { projectCloseHoverSelector, projectSwitchSelector } from "../selectors"
import { dirSlug } from "../utils"
2026-02-04 07:45:49 +08:00
test("can close a project via hover card close button", async ({ page, withProject }) => {
await page.setViewportSize({ width: 1400, height: 800 })
const other = await createTestProject()
const otherSlug = dirSlug(other)
try {
2026-02-04 07:45:49 +08:00
await withProject(
async () => {
await openSidebar(page)
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
await expect(otherButton).toBeVisible()
await otherButton.hover()
const close = page.locator(projectCloseHoverSelector(otherSlug)).first()
await expect(close).toBeVisible()
await close.click()
await expect(otherButton).toHaveCount(0)
},
{ extra: [other] },
)
} finally {
await cleanupTestProject(other)
}
})
2026-02-11 23:11:41 +08:00
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 {
2026-02-04 07:45:49 +08:00
await withProject(
2026-02-11 23:11:41 +08:00
async ({ slug }) => {
2026-02-04 07:45:49 +08:00
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`))
2026-02-11 23:11:41 +08:00
const menu = await openProjectMenu(page, otherSlug)
2026-02-04 07:45:49 +08:00
2026-02-11 23:11:41 +08:00
await clickMenuItem(menu, /^Close$/i, { force: true })
2026-02-04 07:45:49 +08:00
2026-02-11 23:11:41 +08:00
await expect
.poll(() => {
const pathname = new URL(page.url()).pathname
if (new RegExp(`^/${slug}/session(?:/[^/]+)?/?$`).test(pathname)) return "project"
if (pathname === "/") return "home"
return ""
})
.toMatch(/^(project|home)$/)
2026-02-04 07:45:49 +08:00
2026-02-11 23:11:41 +08:00
await expect(page).not.toHaveURL(new RegExp(`/${otherSlug}/session(?:[/?#]|$)`))
2026-02-04 07:45:49 +08:00
await expect(otherButton).toHaveCount(0)
},
{ extra: [other] },
)
} finally {
await cleanupTestProject(other)
}
})