| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | for (const [platform, system, version, edition] of [ |
| 4 | ["darwin", "macos", "26.5", ""], |
| 5 | ["windows", "windows-11", "25H2", "Professional"], |
| 6 | ["linux", "ubuntu-22.04", "22.04", ""], |
| 7 | ["linux", "ubuntu-24.04", "24.04", ""], |
| 8 | ]) { |
| 9 | let planRequests = 0; |
| 10 | const fixture = await createWorkbench({ |
| 11 | clientContext: { |
| 12 | mode: "local", |
| 13 | connection_id: "local", |
| 14 | client_platform: platform, |
| 15 | server_platform: platform, |
| 16 | }, |
| 17 | beforeNavigate: async (page, state) => { |
| 18 | state.status.local_vm_storage = true; |
| 19 | await page.route("**/api/environment/guest-systems", (route) => |
| 20 | route.fulfill({ json: { fresh: true, available: true, system } }), |
| 21 | ); |
| 22 | await page.route("**/api/environment/guest-systems/clone", (route) => { |
| 23 | planRequests++; |
| 24 | return route.fulfill({ |
| 25 | json: { |
| 26 | key: "source-key", |
| 27 | enough_space: true, |
| 28 | minimum_free_gib: 64, |
| 29 | free_gib: 100, |
| 30 | download_bytes: 5000000000, |
| 31 | plan: { |
| 32 | host: { |
| 33 | system, |
| 34 | version, |
| 35 | build: "host-build", |
| 36 | edition, |
| 37 | language: "zh-CN", |
| 38 | }, |
| 39 | version, |
| 40 | build: "image-build", |
| 41 | format: system === "macos" ? "ipsw" : "esd", |
| 42 | }, |
| 43 | }, |
| 44 | }); |
| 45 | }); |
| 46 | }, |
| 47 | }); |
| 48 | try { |
| 49 | const { page } = fixture; |
| 50 | const region = page.locator(".guest-system-picker"); |
| 51 | const picker = region.getByRole("combobox"); |
| 52 | await picker.waitFor(); |
| 53 | const initialHeight = (await region.boundingBox()).height; |
| 54 | await picker.focus(); |
| 55 | await picker.press("ArrowDown"); |
| 56 | const option = page.getByRole("option", { |
| 57 | name: "自动匹配本机系统版本", |
| 58 | exact: true, |
| 59 | }); |
| 60 | await option.waitFor(); |
| 61 | assert.ok( |
| 62 | Math.abs((await region.boundingBox()).height - initialHeight) < 1, |
| 63 | "floating options must not change layout height", |
| 64 | ); |
| 65 | await picker.press("Home"); |
| 66 | await picker.press("Enter"); |
| 67 | assert.equal(await picker.getAttribute("aria-expanded"), "false"); |
| 68 | await region |
| 69 | .getByText("本机构建号 host-build · 镜像构建号 image-build") |
| 70 | .waitFor(); |
| 71 | if (system === "windows-11") await region.getByRole("checkbox").check(); |
| 72 | const submit = page.waitForRequest( |
| 73 | (request) => |
| 74 | request.url().endsWith("/api/start") && request.method() === "POST", |
| 75 | ); |
| 76 | await page |
| 77 | .getByRole("button", { |
| 78 | name: "安装客户机", |
| 79 | exact: true, |
| 80 | }) |
| 81 | .click(); |
| 82 | const body = (await submit).postDataJSON(); |
| 83 | assert.equal(body.clone_key, "source-key"); |
| 84 | assert.equal(body.guest_system, system); |
| 85 | assert.equal(planRequests, 1); |
| 86 | assert.deepEqual(fixture.errors, []); |
| 87 | console.log(platform, "host clone selection and submission passed"); |
| 88 | } finally { |
| 89 | await fixture.browser.close(); |
| 90 | } |
| 91 | } |