import { expect, test } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
const projectRoot = process.cwd();
const latestReviewedOfficialCommit =
"f2b345dbb56a851e10d8a742732ab73ee139f025";
test.describe("HiCAD embedded startup", () => {
test("pins the latest reviewed official Zoo Design Studio source", () => {
const vendorScript = fs.readFileSync(
path.join(projectRoot, "scripts/vendor-zoo-modeling-app.mjs"),
"utf8"
);
expect(vendorScript).toContain(latestReviewedOfficialCommit);
});
test("uses the website favicon across embedded browser surfaces", () => {
const vendorScript = fs.readFileSync(
path.join(projectRoot, "scripts/vendor-zoo-modeling-app.mjs"),
"utf8"
);
expect(vendorScript).toContain(
'const brandedFaviconUrl = "/api/favicon?surface=hicad"'
);
expect(vendorScript).toMatch(
/` {2}`/
);
expect(vendorScript).toMatch(
/` {2}`/
);
expect(vendorScript).toMatch(
/manifest\.icons = \[\s*\{\s*src: brandedFaviconUrl,\s*sizes: "any",/
);
});
test("suppresses the upstream onboarding chooser in embedded mode", () => {
const vendorScript = fs.readFileSync(
path.join(projectRoot, "scripts/vendor-zoo-modeling-app.mjs"),
"utf8"
);
const localization = fs.readFileSync(
path.join(projectRoot, "vendor/zoo-modeling-app/localization.ts"),
"utf8"
);
expect(vendorScript).toMatch(
/env\(\)\.VITE_ZOO_API_TOKEN !== '\$\{proxyToken\}'/
);
expect(localization).toContain("[data-testid='onboarding-toast']");
});
test("preloads and serves the CAD wasm using a precompressed asset", () => {
const vendorScript = fs.readFileSync(
path.join(projectRoot, "scripts/vendor-zoo-modeling-app.mjs"),
"utf8"
);
const nginxTemplate = fs.readFileSync(
path.join(projectRoot, "deploy/nginx-hicad-zoo-ws.conf.template"),
"utf8"
);
expect(vendorScript).toContain(
'rel="preload" href="./kcl_wasm_lib_bg.wasm"'
);
expect(vendorScript).toContain("/\\.(?:css|js|wasm)$/");
expect(vendorScript).toContain("precompressRootWasm(buildDir)");
expect(nginxTemplate).toMatch(
/location = \/vendor\/zoo-modeling-app\/kcl_wasm_lib_bg\.wasm \{[\s\S]*?gzip_static on;/
);
});
test("fits the complete generated model after selecting the isometric view", () => {
const vendorScript = fs.readFileSync(
path.join(projectRoot, "scripts/vendor-zoo-modeling-app.mjs"),
"utf8"
);
expect(vendorScript).toMatch(
/await engineViewIsometric\(\{[\s\S]*?await engineStreamZoomToFit\(\{\s*engineCommandManager,\s*padding,/
);
expect(vendorScript).toContain(
"Refit against every generated entity so newly"
);
});
});