refactor(e2e): faster tests (#12021)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { test as base, expect } from "@playwright/test"
|
import { test as base, expect, type Page } from "@playwright/test"
|
||||||
import { seedProjects } from "./actions"
|
import { cleanupTestProject, createTestProject, seedProjects } from "./actions"
|
||||||
import { promptSelector } from "./selectors"
|
import { promptSelector } from "./selectors"
|
||||||
import { createSdk, dirSlug, getWorktree, sessionPath } from "./utils"
|
import { createSdk, dirSlug, getWorktree, sessionPath } from "./utils"
|
||||||
|
|
||||||
@@ -8,6 +8,14 @@ export const settingsKey = "settings.v3"
|
|||||||
type TestFixtures = {
|
type TestFixtures = {
|
||||||
sdk: ReturnType<typeof createSdk>
|
sdk: ReturnType<typeof createSdk>
|
||||||
gotoSession: (sessionID?: string) => Promise<void>
|
gotoSession: (sessionID?: string) => Promise<void>
|
||||||
|
withProject: <T>(
|
||||||
|
callback: (project: {
|
||||||
|
directory: string
|
||||||
|
slug: string
|
||||||
|
gotoSession: (sessionID?: string) => Promise<void>
|
||||||
|
}) => Promise<T>,
|
||||||
|
options?: { extra?: string[] },
|
||||||
|
) => Promise<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkerFixtures = {
|
type WorkerFixtures = {
|
||||||
@@ -33,17 +41,7 @@ export const test = base.extend<TestFixtures, WorkerFixtures>({
|
|||||||
await use(createSdk(directory))
|
await use(createSdk(directory))
|
||||||
},
|
},
|
||||||
gotoSession: async ({ page, directory }, use) => {
|
gotoSession: async ({ page, directory }, use) => {
|
||||||
await seedProjects(page, { directory })
|
await seedStorage(page, { directory })
|
||||||
await page.addInitScript(() => {
|
|
||||||
localStorage.setItem(
|
|
||||||
"opencode.global.dat:model",
|
|
||||||
JSON.stringify({
|
|
||||||
recent: [{ providerID: "opencode", modelID: "big-pickle" }],
|
|
||||||
user: [],
|
|
||||||
variant: {},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const gotoSession = async (sessionID?: string) => {
|
const gotoSession = async (sessionID?: string) => {
|
||||||
await page.goto(sessionPath(directory, sessionID))
|
await page.goto(sessionPath(directory, sessionID))
|
||||||
@@ -51,6 +49,39 @@ export const test = base.extend<TestFixtures, WorkerFixtures>({
|
|||||||
}
|
}
|
||||||
await use(gotoSession)
|
await use(gotoSession)
|
||||||
},
|
},
|
||||||
|
withProject: async ({ page }, use) => {
|
||||||
|
await use(async (callback, options) => {
|
||||||
|
const directory = await createTestProject()
|
||||||
|
const slug = dirSlug(directory)
|
||||||
|
await seedStorage(page, { directory, extra: options?.extra })
|
||||||
|
|
||||||
|
const gotoSession = async (sessionID?: string) => {
|
||||||
|
await page.goto(sessionPath(directory, sessionID))
|
||||||
|
await expect(page.locator(promptSelector)).toBeVisible()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await gotoSession()
|
||||||
|
return await callback({ directory, slug, gotoSession })
|
||||||
|
} finally {
|
||||||
|
await cleanupTestProject(directory)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function seedStorage(page: Page, input: { directory: string; extra?: string[] }) {
|
||||||
|
await seedProjects(page, input)
|
||||||
|
await page.addInitScript(() => {
|
||||||
|
localStorage.setItem(
|
||||||
|
"opencode.global.dat:model",
|
||||||
|
JSON.stringify({
|
||||||
|
recent: [{ providerID: "opencode", modelID: "big-pickle" }],
|
||||||
|
user: [],
|
||||||
|
variant: {},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export { expect }
|
export { expect }
|
||||||
|
|||||||
@@ -1,52 +1,53 @@
|
|||||||
import { test, expect } from "../fixtures"
|
import { test, expect } from "../fixtures"
|
||||||
import { openSidebar } from "../actions"
|
import { openSidebar } from "../actions"
|
||||||
|
|
||||||
test("dialog edit project updates name and startup script", async ({ page, gotoSession }) => {
|
test("dialog edit project updates name and startup script", async ({ page, withProject }) => {
|
||||||
await gotoSession()
|
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
await openSidebar(page)
|
await withProject(async () => {
|
||||||
|
await openSidebar(page)
|
||||||
|
|
||||||
|
const open = async () => {
|
||||||
|
const header = page.locator(".group\\/project").first()
|
||||||
|
await header.hover()
|
||||||
|
const trigger = header.getByRole("button", { name: "More options" }).first()
|
||||||
|
await expect(trigger).toBeVisible()
|
||||||
|
await trigger.click({ force: true })
|
||||||
|
|
||||||
|
const menu = page.locator('[data-component="dropdown-menu-content"]').first()
|
||||||
|
await expect(menu).toBeVisible()
|
||||||
|
|
||||||
|
const editItem = menu.getByRole("menuitem", { name: "Edit" }).first()
|
||||||
|
await expect(editItem).toBeVisible()
|
||||||
|
await editItem.click({ force: true })
|
||||||
|
|
||||||
|
const dialog = page.getByRole("dialog")
|
||||||
|
await expect(dialog).toBeVisible()
|
||||||
|
await expect(dialog.getByRole("heading", { level: 2 })).toHaveText("Edit project")
|
||||||
|
return dialog
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = `e2e project ${Date.now()}`
|
||||||
|
const startup = `echo e2e_${Date.now()}`
|
||||||
|
|
||||||
|
const dialog = await open()
|
||||||
|
|
||||||
|
const nameInput = dialog.getByLabel("Name")
|
||||||
|
await nameInput.fill(name)
|
||||||
|
|
||||||
|
const startupInput = dialog.getByLabel("Workspace startup script")
|
||||||
|
await startupInput.fill(startup)
|
||||||
|
|
||||||
|
await dialog.getByRole("button", { name: "Save" }).click()
|
||||||
|
await expect(dialog).toHaveCount(0)
|
||||||
|
|
||||||
const open = async () => {
|
|
||||||
const header = page.locator(".group\\/project").first()
|
const header = page.locator(".group\\/project").first()
|
||||||
await header.hover()
|
await expect(header).toContainText(name)
|
||||||
const trigger = header.getByRole("button", { name: "More options" }).first()
|
|
||||||
await expect(trigger).toBeVisible()
|
|
||||||
await trigger.click({ force: true })
|
|
||||||
|
|
||||||
const menu = page.locator('[data-component="dropdown-menu-content"]').first()
|
const reopened = await open()
|
||||||
await expect(menu).toBeVisible()
|
await expect(reopened.getByLabel("Name")).toHaveValue(name)
|
||||||
|
await expect(reopened.getByLabel("Workspace startup script")).toHaveValue(startup)
|
||||||
const editItem = menu.getByRole("menuitem", { name: "Edit" }).first()
|
await reopened.getByRole("button", { name: "Cancel" }).click()
|
||||||
await expect(editItem).toBeVisible()
|
await expect(reopened).toHaveCount(0)
|
||||||
await editItem.click({ force: true })
|
})
|
||||||
|
|
||||||
const dialog = page.getByRole("dialog")
|
|
||||||
await expect(dialog).toBeVisible()
|
|
||||||
await expect(dialog.getByRole("heading", { level: 2 })).toHaveText("Edit project")
|
|
||||||
return dialog
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = `e2e project ${Date.now()}`
|
|
||||||
const startup = `echo e2e_${Date.now()}`
|
|
||||||
|
|
||||||
const dialog = await open()
|
|
||||||
|
|
||||||
const nameInput = dialog.getByLabel("Name")
|
|
||||||
await nameInput.fill(name)
|
|
||||||
|
|
||||||
const startupInput = dialog.getByLabel("Workspace startup script")
|
|
||||||
await startupInput.fill(startup)
|
|
||||||
|
|
||||||
await dialog.getByRole("button", { name: "Save" }).click()
|
|
||||||
await expect(dialog).toHaveCount(0)
|
|
||||||
|
|
||||||
const header = page.locator(".group\\/project").first()
|
|
||||||
await expect(header).toContainText(name)
|
|
||||||
|
|
||||||
const reopened = await open()
|
|
||||||
await expect(reopened.getByLabel("Name")).toHaveValue(name)
|
|
||||||
await expect(reopened.getByLabel("Workspace startup script")).toHaveValue(startup)
|
|
||||||
await reopened.getByRole("button", { name: "Cancel" }).click()
|
|
||||||
await expect(reopened).toHaveCount(0)
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,69 +1,73 @@
|
|||||||
import { test, expect } from "../fixtures"
|
import { test, expect } from "../fixtures"
|
||||||
import { createTestProject, seedProjects, cleanupTestProject, openSidebar, clickMenuItem } from "../actions"
|
import { createTestProject, cleanupTestProject, openSidebar, clickMenuItem } from "../actions"
|
||||||
import { projectCloseHoverSelector, projectCloseMenuSelector, projectSwitchSelector } from "../selectors"
|
import { projectCloseHoverSelector, projectCloseMenuSelector, projectSwitchSelector } from "../selectors"
|
||||||
import { dirSlug } from "../utils"
|
import { dirSlug } from "../utils"
|
||||||
|
|
||||||
test("can close a project via hover card close button", async ({ page, directory, gotoSession }) => {
|
test("can close a project via hover card close button", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const other = await createTestProject()
|
const other = await createTestProject()
|
||||||
const otherSlug = dirSlug(other)
|
const otherSlug = dirSlug(other)
|
||||||
await seedProjects(page, { directory, extra: [other] })
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await gotoSession()
|
await withProject(
|
||||||
|
async () => {
|
||||||
|
await openSidebar(page)
|
||||||
|
|
||||||
await openSidebar(page)
|
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
||||||
|
await expect(otherButton).toBeVisible()
|
||||||
|
await otherButton.hover()
|
||||||
|
|
||||||
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
const close = page.locator(projectCloseHoverSelector(otherSlug)).first()
|
||||||
await expect(otherButton).toBeVisible()
|
await expect(close).toBeVisible()
|
||||||
await otherButton.hover()
|
await close.click()
|
||||||
|
|
||||||
const close = page.locator(projectCloseHoverSelector(otherSlug)).first()
|
await expect(otherButton).toHaveCount(0)
|
||||||
await expect(close).toBeVisible()
|
},
|
||||||
await close.click()
|
{ extra: [other] },
|
||||||
|
)
|
||||||
await expect(otherButton).toHaveCount(0)
|
|
||||||
} finally {
|
} finally {
|
||||||
await cleanupTestProject(other)
|
await cleanupTestProject(other)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can close a project via project header more options menu", async ({ page, directory, gotoSession }) => {
|
test("can close a project via project header more options menu", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const other = await createTestProject()
|
const other = await createTestProject()
|
||||||
const otherName = other.split("/").pop() ?? other
|
const otherName = other.split("/").pop() ?? other
|
||||||
const otherSlug = dirSlug(other)
|
const otherSlug = dirSlug(other)
|
||||||
await seedProjects(page, { directory, extra: [other] })
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await gotoSession()
|
await withProject(
|
||||||
|
async () => {
|
||||||
|
await openSidebar(page)
|
||||||
|
|
||||||
await openSidebar(page)
|
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
||||||
|
await expect(otherButton).toBeVisible()
|
||||||
|
await otherButton.click()
|
||||||
|
|
||||||
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
|
||||||
await expect(otherButton).toBeVisible()
|
|
||||||
await otherButton.click()
|
|
||||||
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
|
const header = page
|
||||||
|
.locator(".group\\/project")
|
||||||
|
.filter({ has: page.locator(`[data-action="project-menu"][data-project="${otherSlug}"]`) })
|
||||||
|
.first()
|
||||||
|
await expect(header).toContainText(otherName)
|
||||||
|
|
||||||
const header = page
|
const trigger = header.locator(`[data-action="project-menu"][data-project="${otherSlug}"]`).first()
|
||||||
.locator(".group\\/project")
|
await expect(trigger).toHaveCount(1)
|
||||||
.filter({ has: page.locator(`[data-action="project-menu"][data-project="${otherSlug}"]`) })
|
await trigger.focus()
|
||||||
.first()
|
await page.keyboard.press("Enter")
|
||||||
await expect(header).toContainText(otherName)
|
|
||||||
|
|
||||||
const trigger = header.locator(`[data-action="project-menu"][data-project="${otherSlug}"]`).first()
|
const menu = page.locator('[data-component="dropdown-menu-content"]').first()
|
||||||
await expect(trigger).toHaveCount(1)
|
await expect(menu).toBeVisible({ timeout: 10_000 })
|
||||||
await trigger.focus()
|
|
||||||
await page.keyboard.press("Enter")
|
|
||||||
|
|
||||||
const menu = page.locator('[data-component="dropdown-menu-content"]').first()
|
await clickMenuItem(menu, /^Close$/i, { force: true })
|
||||||
await expect(menu).toBeVisible({ timeout: 10_000 })
|
await expect(otherButton).toHaveCount(0)
|
||||||
|
},
|
||||||
await clickMenuItem(menu, /^Close$/i, { force: true })
|
{ extra: [other] },
|
||||||
await expect(otherButton).toHaveCount(0)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
await cleanupTestProject(other)
|
await cleanupTestProject(other)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,34 @@
|
|||||||
import { test, expect } from "../fixtures"
|
import { test, expect } from "../fixtures"
|
||||||
import { defocus, createTestProject, seedProjects, cleanupTestProject } from "../actions"
|
import { defocus, createTestProject, cleanupTestProject } from "../actions"
|
||||||
import { projectSwitchSelector } from "../selectors"
|
import { projectSwitchSelector } from "../selectors"
|
||||||
import { dirSlug } from "../utils"
|
import { dirSlug } from "../utils"
|
||||||
|
|
||||||
test("can switch between projects from sidebar", async ({ page, directory, gotoSession }) => {
|
test("can switch between projects from sidebar", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const other = await createTestProject()
|
const other = await createTestProject()
|
||||||
const otherSlug = dirSlug(other)
|
const otherSlug = dirSlug(other)
|
||||||
|
|
||||||
await seedProjects(page, { directory, extra: [other] })
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await gotoSession()
|
await withProject(
|
||||||
|
async ({ directory }) => {
|
||||||
|
await defocus(page)
|
||||||
|
|
||||||
await defocus(page)
|
const currentSlug = dirSlug(directory)
|
||||||
|
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
||||||
|
await expect(otherButton).toBeVisible()
|
||||||
|
await otherButton.click()
|
||||||
|
|
||||||
const currentSlug = dirSlug(directory)
|
await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
|
||||||
const otherButton = page.locator(projectSwitchSelector(otherSlug)).first()
|
|
||||||
await expect(otherButton).toBeVisible()
|
|
||||||
await otherButton.click()
|
|
||||||
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${otherSlug}/session`))
|
const currentButton = page.locator(projectSwitchSelector(currentSlug)).first()
|
||||||
|
await expect(currentButton).toBeVisible()
|
||||||
|
await currentButton.click()
|
||||||
|
|
||||||
const currentButton = page.locator(projectSwitchSelector(currentSlug)).first()
|
await expect(page).toHaveURL(new RegExp(`/${currentSlug}/session`))
|
||||||
await expect(currentButton).toBeVisible()
|
},
|
||||||
await currentButton.click()
|
{ extra: [other] },
|
||||||
|
)
|
||||||
await expect(page).toHaveURL(new RegExp(`/${currentSlug}/session`))
|
|
||||||
} finally {
|
} finally {
|
||||||
await cleanupTestProject(other)
|
await cleanupTestProject(other)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,33 +10,20 @@ import {
|
|||||||
cleanupTestProject,
|
cleanupTestProject,
|
||||||
clickMenuItem,
|
clickMenuItem,
|
||||||
confirmDialog,
|
confirmDialog,
|
||||||
createTestProject,
|
|
||||||
openSidebar,
|
openSidebar,
|
||||||
openWorkspaceMenu,
|
openWorkspaceMenu,
|
||||||
seedProjects,
|
|
||||||
setWorkspacesEnabled,
|
setWorkspacesEnabled,
|
||||||
} from "../actions"
|
} from "../actions"
|
||||||
import { inlineInputSelector, projectSwitchSelector, workspaceItemSelector } from "../selectors"
|
import { inlineInputSelector, workspaceItemSelector } from "../selectors"
|
||||||
import { dirSlug } from "../utils"
|
|
||||||
|
|
||||||
function slugFromUrl(url: string) {
|
function slugFromUrl(url: string) {
|
||||||
return /\/([^/]+)\/session(?:\/|$)/.exec(url)?.[1] ?? ""
|
return /\/([^/]+)\/session(?:\/|$)/.exec(url)?.[1] ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupWorkspaceTest(page: Page, directory: string, gotoSession: () => Promise<void>) {
|
async function setupWorkspaceTest(page: Page, project: { slug: string }) {
|
||||||
const project = await createTestProject()
|
const rootSlug = project.slug
|
||||||
const rootSlug = dirSlug(project)
|
|
||||||
await seedProjects(page, { directory, extra: [project] })
|
|
||||||
|
|
||||||
await gotoSession()
|
|
||||||
await openSidebar(page)
|
await openSidebar(page)
|
||||||
|
|
||||||
const target = page.locator(projectSwitchSelector(rootSlug)).first()
|
|
||||||
await expect(target).toBeVisible()
|
|
||||||
await target.click()
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${rootSlug}/session`))
|
|
||||||
|
|
||||||
await openSidebar(page)
|
|
||||||
await setWorkspacesEnabled(page, rootSlug, true)
|
await setWorkspacesEnabled(page, rootSlug, true)
|
||||||
|
|
||||||
await page.getByRole("button", { name: "New workspace" }).first().click()
|
await page.getByRole("button", { name: "New workspace" }).first().click()
|
||||||
@@ -70,25 +57,13 @@ async function setupWorkspaceTest(page: Page, directory: string, gotoSession: ()
|
|||||||
)
|
)
|
||||||
.toBe(true)
|
.toBe(true)
|
||||||
|
|
||||||
return { project, rootSlug, slug, directory: dir }
|
return { rootSlug, slug, directory: dir }
|
||||||
}
|
}
|
||||||
|
|
||||||
test("can enable and disable workspaces from project menu", async ({ page, directory, gotoSession }) => {
|
test("can enable and disable workspaces from project menu", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const project = await createTestProject()
|
await withProject(async ({ slug }) => {
|
||||||
const slug = dirSlug(project)
|
|
||||||
await seedProjects(page, { directory, extra: [project] })
|
|
||||||
|
|
||||||
try {
|
|
||||||
await gotoSession()
|
|
||||||
await openSidebar(page)
|
|
||||||
|
|
||||||
const target = page.locator(projectSwitchSelector(slug)).first()
|
|
||||||
await expect(target).toBeVisible()
|
|
||||||
await target.click()
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
|
|
||||||
|
|
||||||
await openSidebar(page)
|
await openSidebar(page)
|
||||||
|
|
||||||
await expect(page.getByRole("button", { name: "New session" }).first()).toBeVisible()
|
await expect(page.getByRole("button", { name: "New session" }).first()).toBeVisible()
|
||||||
@@ -101,27 +76,13 @@ test("can enable and disable workspaces from project menu", async ({ page, direc
|
|||||||
await setWorkspacesEnabled(page, slug, false)
|
await setWorkspacesEnabled(page, slug, false)
|
||||||
await expect(page.getByRole("button", { name: "New session" }).first()).toBeVisible()
|
await expect(page.getByRole("button", { name: "New session" }).first()).toBeVisible()
|
||||||
await expect(page.locator(workspaceItemSelector(slug))).toHaveCount(0)
|
await expect(page.locator(workspaceItemSelector(slug))).toHaveCount(0)
|
||||||
} finally {
|
})
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can create a workspace", async ({ page, directory, gotoSession }) => {
|
test("can create a workspace", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const project = await createTestProject()
|
await withProject(async ({ slug }) => {
|
||||||
const slug = dirSlug(project)
|
|
||||||
await seedProjects(page, { directory, extra: [project] })
|
|
||||||
|
|
||||||
try {
|
|
||||||
await gotoSession()
|
|
||||||
await openSidebar(page)
|
|
||||||
|
|
||||||
const target = page.locator(projectSwitchSelector(slug)).first()
|
|
||||||
await expect(target).toBeVisible()
|
|
||||||
await target.click()
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
|
|
||||||
|
|
||||||
await openSidebar(page)
|
await openSidebar(page)
|
||||||
await setWorkspacesEnabled(page, slug, true)
|
await setWorkspacesEnabled(page, slug, true)
|
||||||
|
|
||||||
@@ -162,17 +123,15 @@ test("can create a workspace", async ({ page, directory, gotoSession }) => {
|
|||||||
await expect(page.locator(workspaceItemSelector(workspaceSlug)).first()).toBeVisible()
|
await expect(page.locator(workspaceItemSelector(workspaceSlug)).first()).toBeVisible()
|
||||||
|
|
||||||
await cleanupTestProject(workspaceDir)
|
await cleanupTestProject(workspaceDir)
|
||||||
} finally {
|
})
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can rename a workspace", async ({ page, directory, gotoSession }) => {
|
test("can rename a workspace", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const { project, slug } = await setupWorkspaceTest(page, directory, gotoSession)
|
await withProject(async (project) => {
|
||||||
|
const { slug } = await setupWorkspaceTest(page, project)
|
||||||
|
|
||||||
try {
|
|
||||||
const rename = `e2e workspace ${Date.now()}`
|
const rename = `e2e workspace ${Date.now()}`
|
||||||
const menu = await openWorkspaceMenu(page, slug)
|
const menu = await openWorkspaceMenu(page, slug)
|
||||||
await clickMenuItem(menu, /^Rename$/i, { force: true })
|
await clickMenuItem(menu, /^Rename$/i, { force: true })
|
||||||
@@ -186,17 +145,15 @@ test("can rename a workspace", async ({ page, directory, gotoSession }) => {
|
|||||||
await input.fill(rename)
|
await input.fill(rename)
|
||||||
await input.press("Enter")
|
await input.press("Enter")
|
||||||
await expect(item).toContainText(rename)
|
await expect(item).toContainText(rename)
|
||||||
} finally {
|
})
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can reset a workspace", async ({ page, directory, sdk, gotoSession }) => {
|
test("can reset a workspace", async ({ page, sdk, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const { project, slug, directory: createdDir } = await setupWorkspaceTest(page, directory, gotoSession)
|
await withProject(async (project) => {
|
||||||
|
const { slug, directory: createdDir } = await setupWorkspaceTest(page, project)
|
||||||
|
|
||||||
try {
|
|
||||||
const readme = path.join(createdDir, "README.md")
|
const readme = path.join(createdDir, "README.md")
|
||||||
const extra = path.join(createdDir, `e2e_reset_${Date.now()}.txt`)
|
const extra = path.join(createdDir, `e2e_reset_${Date.now()}.txt`)
|
||||||
const original = await fs.readFile(readme, "utf8")
|
const original = await fs.readFile(readme, "utf8")
|
||||||
@@ -250,17 +207,15 @@ test("can reset a workspace", async ({ page, directory, sdk, gotoSession }) => {
|
|||||||
.catch(() => false)
|
.catch(() => false)
|
||||||
})
|
})
|
||||||
.toBe(false)
|
.toBe(false)
|
||||||
} finally {
|
})
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can delete a workspace", async ({ page, directory, gotoSession }) => {
|
test("can delete a workspace", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
|
||||||
const { project, rootSlug, slug } = await setupWorkspaceTest(page, directory, gotoSession)
|
await withProject(async (project) => {
|
||||||
|
const { rootSlug, slug } = await setupWorkspaceTest(page, project)
|
||||||
|
|
||||||
try {
|
|
||||||
const menu = await openWorkspaceMenu(page, slug)
|
const menu = await openWorkspaceMenu(page, slug)
|
||||||
await clickMenuItem(menu, /^Delete$/i, { force: true })
|
await clickMenuItem(menu, /^Delete$/i, { force: true })
|
||||||
await confirmDialog(page, /^Delete workspace$/i)
|
await confirmDialog(page, /^Delete workspace$/i)
|
||||||
@@ -268,124 +223,111 @@ test("can delete a workspace", async ({ page, directory, gotoSession }) => {
|
|||||||
await expect(page).toHaveURL(new RegExp(`/${rootSlug}/session`))
|
await expect(page).toHaveURL(new RegExp(`/${rootSlug}/session`))
|
||||||
await expect(page.locator(workspaceItemSelector(slug))).toHaveCount(0)
|
await expect(page.locator(workspaceItemSelector(slug))).toHaveCount(0)
|
||||||
await expect(page.locator(workspaceItemSelector(rootSlug)).first()).toBeVisible()
|
await expect(page.locator(workspaceItemSelector(rootSlug)).first()).toBeVisible()
|
||||||
} finally {
|
})
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("can reorder workspaces by drag and drop", async ({ page, directory, gotoSession }) => {
|
test("can reorder workspaces by drag and drop", async ({ page, withProject }) => {
|
||||||
await page.setViewportSize({ width: 1400, height: 800 })
|
await page.setViewportSize({ width: 1400, height: 800 })
|
||||||
|
await withProject(async ({ slug: rootSlug }) => {
|
||||||
|
const workspaces = [] as { directory: string; slug: string }[]
|
||||||
|
|
||||||
const project = await createTestProject()
|
const listSlugs = async () => {
|
||||||
const rootSlug = dirSlug(project)
|
const nodes = page.locator('[data-component="sidebar-nav-desktop"] [data-component="workspace-item"]')
|
||||||
await seedProjects(page, { directory, extra: [project] })
|
const slugs = await nodes.evaluateAll((els) => {
|
||||||
|
return els.map((el) => el.getAttribute("data-workspace") ?? "").filter((x) => x.length > 0)
|
||||||
|
})
|
||||||
|
return slugs
|
||||||
|
}
|
||||||
|
|
||||||
const workspaces = [] as { directory: string; slug: string }[]
|
const waitReady = async (slug: string) => {
|
||||||
|
|
||||||
const listSlugs = async () => {
|
|
||||||
const nodes = page.locator('[data-component="sidebar-nav-desktop"] [data-component="workspace-item"]')
|
|
||||||
const slugs = await nodes.evaluateAll((els) => {
|
|
||||||
return els.map((el) => el.getAttribute("data-workspace") ?? "").filter((x) => x.length > 0)
|
|
||||||
})
|
|
||||||
return slugs
|
|
||||||
}
|
|
||||||
|
|
||||||
const waitReady = async (slug: string) => {
|
|
||||||
await expect
|
|
||||||
.poll(
|
|
||||||
async () => {
|
|
||||||
const item = page.locator(workspaceItemSelector(slug)).first()
|
|
||||||
try {
|
|
||||||
await item.hover({ timeout: 500 })
|
|
||||||
return true
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ timeout: 60_000 },
|
|
||||||
)
|
|
||||||
.toBe(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const drag = async (from: string, to: string) => {
|
|
||||||
const src = page.locator(workspaceItemSelector(from)).first()
|
|
||||||
const dst = page.locator(workspaceItemSelector(to)).first()
|
|
||||||
|
|
||||||
await src.scrollIntoViewIfNeeded()
|
|
||||||
await dst.scrollIntoViewIfNeeded()
|
|
||||||
|
|
||||||
const a = await src.boundingBox()
|
|
||||||
const b = await dst.boundingBox()
|
|
||||||
if (!a || !b) throw new Error("Failed to resolve workspace drag bounds")
|
|
||||||
|
|
||||||
await page.mouse.move(a.x + a.width / 2, a.y + a.height / 2)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(b.x + b.width / 2, b.y + b.height / 2, { steps: 12 })
|
|
||||||
await page.mouse.up()
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await gotoSession()
|
|
||||||
await openSidebar(page)
|
|
||||||
|
|
||||||
const target = page.locator(projectSwitchSelector(rootSlug)).first()
|
|
||||||
await expect(target).toBeVisible()
|
|
||||||
await target.click()
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${rootSlug}/session`))
|
|
||||||
|
|
||||||
await openSidebar(page)
|
|
||||||
await setWorkspacesEnabled(page, rootSlug, true)
|
|
||||||
|
|
||||||
for (const _ of [0, 1]) {
|
|
||||||
const prev = slugFromUrl(page.url())
|
|
||||||
await page.getByRole("button", { name: "New workspace" }).first().click()
|
|
||||||
await expect
|
await expect
|
||||||
.poll(
|
.poll(
|
||||||
() => {
|
async () => {
|
||||||
const slug = slugFromUrl(page.url())
|
const item = page.locator(workspaceItemSelector(slug)).first()
|
||||||
return slug.length > 0 && slug !== rootSlug && slug !== prev
|
try {
|
||||||
|
await item.hover({ timeout: 500 })
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ timeout: 45_000 },
|
{ timeout: 60_000 },
|
||||||
)
|
)
|
||||||
.toBe(true)
|
.toBe(true)
|
||||||
|
}
|
||||||
|
|
||||||
const slug = slugFromUrl(page.url())
|
const drag = async (from: string, to: string) => {
|
||||||
const dir = base64Decode(slug)
|
const src = page.locator(workspaceItemSelector(from)).first()
|
||||||
workspaces.push({ slug, directory: dir })
|
const dst = page.locator(workspaceItemSelector(to)).first()
|
||||||
|
|
||||||
|
await src.scrollIntoViewIfNeeded()
|
||||||
|
await dst.scrollIntoViewIfNeeded()
|
||||||
|
|
||||||
|
const a = await src.boundingBox()
|
||||||
|
const b = await dst.boundingBox()
|
||||||
|
if (!a || !b) throw new Error("Failed to resolve workspace drag bounds")
|
||||||
|
|
||||||
|
await page.mouse.move(a.x + a.width / 2, a.y + a.height / 2)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(b.x + b.width / 2, b.y + b.height / 2, { steps: 12 })
|
||||||
|
await page.mouse.up()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await openSidebar(page)
|
await openSidebar(page)
|
||||||
|
|
||||||
|
await setWorkspacesEnabled(page, rootSlug, true)
|
||||||
|
|
||||||
|
for (const _ of [0, 1]) {
|
||||||
|
const prev = slugFromUrl(page.url())
|
||||||
|
await page.getByRole("button", { name: "New workspace" }).first().click()
|
||||||
|
await expect
|
||||||
|
.poll(
|
||||||
|
() => {
|
||||||
|
const slug = slugFromUrl(page.url())
|
||||||
|
return slug.length > 0 && slug !== rootSlug && slug !== prev
|
||||||
|
},
|
||||||
|
{ timeout: 45_000 },
|
||||||
|
)
|
||||||
|
.toBe(true)
|
||||||
|
|
||||||
|
const slug = slugFromUrl(page.url())
|
||||||
|
const dir = base64Decode(slug)
|
||||||
|
workspaces.push({ slug, directory: dir })
|
||||||
|
|
||||||
|
await openSidebar(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (workspaces.length !== 2) throw new Error("Expected two created workspaces")
|
||||||
|
|
||||||
|
const a = workspaces[0].slug
|
||||||
|
const b = workspaces[1].slug
|
||||||
|
|
||||||
|
await waitReady(a)
|
||||||
|
await waitReady(b)
|
||||||
|
|
||||||
|
const list = async () => {
|
||||||
|
const slugs = await listSlugs()
|
||||||
|
return slugs.filter((s) => s !== rootSlug && (s === a || s === b)).slice(0, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect
|
||||||
|
.poll(async () => {
|
||||||
|
const slugs = await list()
|
||||||
|
return slugs.length === 2
|
||||||
|
})
|
||||||
|
.toBe(true)
|
||||||
|
|
||||||
|
const before = await list()
|
||||||
|
const from = before[1]
|
||||||
|
const to = before[0]
|
||||||
|
if (!from || !to) throw new Error("Failed to resolve initial workspace order")
|
||||||
|
|
||||||
|
await drag(from, to)
|
||||||
|
|
||||||
|
await expect.poll(async () => await list()).toEqual([from, to])
|
||||||
|
} finally {
|
||||||
|
await Promise.all(workspaces.map((w) => cleanupTestProject(w.directory)))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
if (workspaces.length !== 2) throw new Error("Expected two created workspaces")
|
|
||||||
|
|
||||||
const a = workspaces[0].slug
|
|
||||||
const b = workspaces[1].slug
|
|
||||||
|
|
||||||
await waitReady(a)
|
|
||||||
await waitReady(b)
|
|
||||||
|
|
||||||
const list = async () => {
|
|
||||||
const slugs = await listSlugs()
|
|
||||||
return slugs.filter((s) => s !== rootSlug && (s === a || s === b)).slice(0, 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
await expect
|
|
||||||
.poll(async () => {
|
|
||||||
const slugs = await list()
|
|
||||||
return slugs.length === 2
|
|
||||||
})
|
|
||||||
.toBe(true)
|
|
||||||
|
|
||||||
const before = await list()
|
|
||||||
const from = before[1]
|
|
||||||
const to = before[0]
|
|
||||||
if (!from || !to) throw new Error("Failed to resolve initial workspace order")
|
|
||||||
|
|
||||||
await drag(from, to)
|
|
||||||
|
|
||||||
await expect.poll(async () => await list()).toEqual([from, to])
|
|
||||||
} finally {
|
|
||||||
await Promise.all(workspaces.map((w) => cleanupTestProject(w.directory)))
|
|
||||||
await cleanupTestProject(project)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const serverHost = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
|
|||||||
const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
|
const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
|
||||||
const command = `bun run dev -- --host 0.0.0.0 --port ${port}`
|
const command = `bun run dev -- --host 0.0.0.0 --port ${port}`
|
||||||
const reuse = !process.env.CI
|
const reuse = !process.env.CI
|
||||||
const win = process.platform === "win32"
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: "./e2e",
|
testDir: "./e2e",
|
||||||
@@ -15,8 +14,7 @@ export default defineConfig({
|
|||||||
expect: {
|
expect: {
|
||||||
timeout: 10_000,
|
timeout: 10_000,
|
||||||
},
|
},
|
||||||
fullyParallel: !win,
|
fullyParallel: true,
|
||||||
workers: win ? 1 : undefined,
|
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
retries: process.env.CI ? 2 : 0,
|
retries: process.env.CI ? 2 : 0,
|
||||||
reporter: [["html", { outputFolder: "e2e/playwright-report", open: "never" }], ["line"]],
|
reporter: [["html", { outputFolder: "e2e/playwright-report", open: "never" }], ["line"]],
|
||||||
|
|||||||
Reference in New Issue
Block a user