| 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 [host, accountSystem, statusSystem, label] of [ |
| 12 | ["windows", "macos", undefined, "macOS"], |
| 13 | ["darwin", "windows-11", "windows-11", "Windows"], |
| 14 | ["darwin", undefined, undefined, "Linux"], |
| 15 | ]) { |
| 16 | const { browser, page, state, errors } = await createWorkbench({ |
| 17 | url, |
| 18 | clientContext: { mode: "local", connection_id: "local", client_platform: host, server_platform: host }, |
| 19 | }); |
| 20 | try { |
| 21 | state.account.guest_system = accountSystem; |
| 22 | state.status.guest_system = statusSystem; |
| 23 | await page.reload(); |
| 24 | const sidebar = page.getByRole("complementary", { name: "项目与终端" }); |
| 25 | const icon = sidebar.getByRole("img", { name: `客户机系统:${label}` }); |
| 26 | await icon.waitFor(); |
| 27 | assert.equal(await icon.getAttribute("title"), `客户机系统:${label}`); |
| 28 | const iconBox = await icon.boundingBox(); |
| 29 | const brandBox = await sidebar.locator(".sidebar-brand").boundingBox(); |
| 30 | const collapseBox = await sidebar.getByRole("button", { name: "收起侧栏" }).boundingBox(); |
| 31 | assert.ok(iconBox.x > brandBox.x && iconBox.x + iconBox.width < collapseBox.x); |
| 32 | if (process.env.CAGE_TEST_CAPTURE) await page.screenshot({ path: `${process.env.CAGE_TEST_CAPTURE}-${label}.png` }); |
| 33 | await page.reload(); |
| 34 | await icon.waitFor(); |
| 35 | assert.deepEqual(errors, []); |
| 36 | console.log(`PASS 客机 ${label},客户端 ${host}`); |
| 37 | } finally { await browser.close(); } |
| 38 | } |
| 39 | const fixture = await createWorkbench({ |
| 40 | url, |
| 41 | beforeNavigate: async (page, state) => { |
| 42 | state.status.local_vm_storage = true; |
| 43 | await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, system: "macos", available: true } })); |
| 44 | }, |
| 45 | }); |
| 46 | try { |
| 47 | const { page } = fixture; |
| 48 | await page.getByRole("img", { name: "客户机系统:Linux" }).waitFor(); |
| 49 | await page.getByRole("combobox", { name: "客户机系统" }).click(); |
| 50 | await page.getByRole("option", { name: "macOS", exact: true }).click(); |
| 51 | await page.getByRole("img", { name: "客户机系统:macOS" }).waitFor(); |
| 52 | assert.deepEqual(fixture.errors, []); |
| 53 | console.log("PASS 首次安装选择时图标随客机系统变化"); |
| 54 | } finally { await fixture.browser.close(); } |
| 55 | } finally { await vite.close(); } |