| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | for (const [id, name, platform] of [["macos", "macOS", "darwin"], ["windows-11", "Windows 11", "windows"]]) { |
| 5 | let submitted; |
| 6 | const { page, browser } = await createWorkbench({ |
| 7 | clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform }, |
| 8 | nativeRequest: ({ action }) => action === "chooseGuestMedia" ? "C:\\media\\Windows11.iso" : null, |
| 9 | async beforeNavigate(page, state) { |
| 10 | state.status.local_vm_storage = true; |
| 11 | await page.route("**/api/environment/guest-systems", r => r.fulfill({ json: { fresh: true, available: true, system: id } })); |
| 12 | await page.route("**/api/start", r => { |
| 13 | submitted = r.request().postDataJSON(); |
| 14 | return r.fulfill({ json: { id: "native", running: true, kind: "guest-install" } }); |
| 15 | }); |
| 16 | }, |
| 17 | }); |
| 18 | try { |
| 19 | const picker = page.getByRole("combobox", { name: "客户机系统" }); |
| 20 | const storage = page.getByRole("button", { name: "选择环境存储位置" }); |
| 21 | const storageBefore = await storage.boundingBox(); |
| 22 | await picker.click(); |
| 23 | const option = page.getByRole("option", { name, exact: true }); |
| 24 | await option.waitFor(); |
| 25 | const row = await option.boundingBox(), below = await storage.boundingBox(); |
| 26 | assert.ok(Math.abs(below.y - storageBefore.y) < 1 && row.height > 0); |
| 27 | await picker.press("Escape"); |
| 28 | assert.equal((await storage.boundingBox()).y, storageBefore.y); |
| 29 | await picker.press("Enter"); await picker.press("End"); await picker.press("Enter"); |
| 30 | const button = page.getByRole("button", { name: "安装客户机" }); |
| 31 | if (platform === "darwin") { |
| 32 | assert.ok(await button.isEnabled()); |
| 33 | assert.equal(await page.getByLabel("客机账户密码",{exact:true}).count(),0); |
| 34 | } else { |
| 35 | assert.ok(await button.isDisabled()); |
| 36 | await page.getByRole("button", { name: "选择本机 ISO" }).click(); |
| 37 | await page.getByText("C:\\media\\Windows11.iso", { exact: true }).waitFor(); |
| 38 | await page.getByLabel("ISO 的 SHA-256").fill("a".repeat(64)); |
| 39 | assert.ok(await button.isDisabled()); |
| 40 | await page.getByRole("checkbox").check(); |
| 41 | } |
| 42 | await Promise.all([ |
| 43 | page.waitForResponse(response => response.url().endsWith("/api/start")), |
| 44 | button.click(), |
| 45 | ]); |
| 46 | assert.equal(submitted.guest_system, id); |
| 47 | if (platform === "windows") assert.ok(submitted.editor_terms && submitted.sha256.length === 64 && submitted.media.endsWith(".iso")); |
| 48 | else assert.equal(submitted.password, undefined); |
| 49 | console.log(platform, "inline picker, keyboard, validation and start request passed"); |
| 50 | } catch (error) { |
| 51 | console.error((await page.locator("body").innerText()).slice(-2300)); |
| 52 | throw error; |
| 53 | } finally { await browser.close(); } |
| 54 | } |
| 55 | |
| 56 | { |
| 57 | const calls=[]; |
| 58 | const {page,browser,errors}=await createWorkbench({ |
| 59 | nativeRequest: message=>{ calls.push(message.action); return null; }, |
| 60 | async beforeNavigate(page,state) { |
| 61 | state.status.local_vm_storage=true; |
| 62 | await page.route("**/api/environment/guest-systems",r=>r.fulfill({json:{fresh:false,available:true,system:"macos",pending:{system:"macos",id:"activation-fixture"},activate:true}})); |
| 63 | await page.route("**/api/environment/guest-systems/activate",r=>{ calls.push("activate"); return r.fulfill({json:{stopping:true}}); }); |
| 64 | } |
| 65 | }); |
| 66 | try { |
| 67 | for(let i=0; !calls.includes("reconnect") && i<150;i++) await new Promise(resolve=>setTimeout(resolve,20)); |
| 68 | assert.equal(calls.filter(action=>action==="activate").length,1); |
| 69 | assert.equal(calls.filter(action=>action==="reconnect").length,1); |
| 70 | assert.deepEqual(errors,[]); |
| 71 | console.log("installed guest automatically activated and reconnected"); |
| 72 | } finally { await browser.close(); } |
| 73 | } |