| 1 | import assert from "node:assert/strict"; |
| 2 | import { fileURLToPath } from "node:url"; |
| 3 | import { createServer } from "vite"; |
| 4 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 5 | |
| 6 | const root = fileURLToPath(new URL("..", import.meta.url)); |
| 7 | const vite = await createServer({ root, configFile: `${root}/vite.config.js`, server: { host: "127.0.0.1", port: 0 } }); |
| 8 | await vite.listen(); |
| 9 | const url = `http://127.0.0.1:${vite.httpServer.address().port}`; |
| 10 | try { |
| 11 | for (const platform of ["darwin", "windows", "linux"]) { |
| 12 | const { browser, page, state, errors } = await createWorkbench({ url, clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform, connection: { state: "disconnected" } } }); |
| 13 | try { |
| 14 | const defaultProject = state.status.environment_directory; |
| 15 | const project = "/projects/alpha"; |
| 16 | const other = "/projects/beta"; |
| 17 | Object.assign(state.status, { ready: true, vm_running: true, projects: [defaultProject, project, other], workspace: project }); |
| 18 | state.settings.workspace = project; |
| 19 | await page.reload(); |
| 20 | await page.getByRole("button", { name: "添加项目", exact: true }).click(); |
| 21 | let dialog = page.getByRole("dialog", { name: "打开项目", exact: true }); |
| 22 | await dialog.getByRole("radio", { name: /alpha/ }).check(); |
| 23 | await dialog.getByRole("button", { name: "从 Cage 移除此项目" }).click(); |
| 24 | await dialog.getByRole("button", { name: "取消移除" }).click(); |
| 25 | assert.ok(state.status.projects.includes(project)); |
| 26 | state.failRemove = true; |
| 27 | await dialog.getByRole("button", { name: "从 Cage 移除此项目" }).click(); |
| 28 | await dialog.getByRole("button", { name: "确认移除项目" }).click(); |
| 29 | await dialog.getByRole("alert").waitFor(); |
| 30 | assert.ok(state.status.projects.includes(project)); |
| 31 | state.failRemove = false; |
| 32 | await dialog.getByRole("button", { name: "确认移除项目" }).click(); |
| 33 | await dialog.getByRole("radio", { name: /alpha/ }).waitFor({ state: "detached" }); |
| 34 | assert.deepEqual(state.status.projects, [defaultProject, other]); |
| 35 | assert.equal(state.settings.workspace, defaultProject); |
| 36 | assert.equal(await dialog.getByRole("button", { name: "从 Cage 移除此项目" }).count(), 0); |
| 37 | await dialog.getByRole("button", { name: "取消", exact: true }).click(); |
| 38 | await page.getByRole("region", { name: "项目 alpha", exact: true }).waitFor({ state: "detached" }); |
| 39 | Object.assign(state.status, { ready: false, vm_running: false }); |
| 40 | await page.reload(); |
| 41 | await page.getByRole("button", { name: "添加项目", exact: true }).click(); |
| 42 | dialog = page.getByRole("dialog", { name: "打开项目", exact: true }); |
| 43 | await dialog.getByRole("radio", { name: /beta/ }).check(); |
| 44 | assert.equal(await dialog.getByRole("button", { name: "打开项目", exact: true }).isDisabled(), true); |
| 45 | await dialog.getByRole("button", { name: "从 Cage 移除此项目" }).click(); |
| 46 | await dialog.getByRole("button", { name: "确认移除项目" }).click(); |
| 47 | await dialog.getByRole("radio", { name: /beta/ }).waitFor({ state: "detached" }); |
| 48 | assert.deepEqual(state.status.projects, [defaultProject]); |
| 49 | assert.deepEqual(errors, []); |
| 50 | console.log(`PASS ${platform} project removal, cancellation, retry, default selection, stopped environment`); |
| 51 | } finally { await browser.close(); } |
| 52 | } |
| 53 | } finally { await vite.close(); } |