fix(harmony): guide official HDC setup and recheck tool availability
This commit is contained in:
@@ -59,6 +59,9 @@ async function app(t) {
|
||||
screenControl: false,
|
||||
screenFrameWait: null,
|
||||
screenFrameError: null,
|
||||
openedUrls: [],
|
||||
selectedDirectory: "/fixture/folder",
|
||||
configureError: null,
|
||||
};
|
||||
const { createMockBridge } = await import(
|
||||
pathToFileURL(path.join(directory, "sdk/index.js"))
|
||||
@@ -120,6 +123,18 @@ async function app(t) {
|
||||
version: "HDC test",
|
||||
path: "/fixture/hdc",
|
||||
})),
|
||||
handler("hdc.configure", () => {
|
||||
if (model.configureError) throw model.configureError;
|
||||
model.hdcAvailable = true;
|
||||
return { available: true, version: "HDC test", path: "/fixture/hdc" };
|
||||
}),
|
||||
[
|
||||
"host.runtime.openUrl",
|
||||
({ url }) => {
|
||||
model.openedUrls.push(url);
|
||||
return { ok: true };
|
||||
},
|
||||
],
|
||||
handler("hdc.devices", () => ({
|
||||
devices: model.hdcConnected
|
||||
? [{ id: "phone", transport: "USB", state: "Connected" }]
|
||||
@@ -152,7 +167,7 @@ async function app(t) {
|
||||
})),
|
||||
handler("hdc.start", () => ({ id: 9 })),
|
||||
["host.dialog.confirm", () => ({ confirmed: model.confirmed })],
|
||||
["host.dialog.openDirectory", () => ({ path: "/fixture/folder" })],
|
||||
["host.dialog.openDirectory", () => ({ path: model.selectedDirectory })],
|
||||
handler("info", () => ({ connection: model.connection, busy: false })),
|
||||
handler("devices", () => ({ devices: model.attached ? [device] : [] })),
|
||||
handler("connect", () => (model.connection = { device, storages })),
|
||||
@@ -374,6 +389,57 @@ test("management is optional and missing HDC does not disable file transfers", a
|
||||
await connect();
|
||||
assert.equal($("browser").hidden, false);
|
||||
});
|
||||
test("missing HDC guides official download and configuring an extracted toolkit", async (t) => {
|
||||
const { $, click, model } = await app(t);
|
||||
await click("tab-management");
|
||||
assert.equal($("hdc-setup")?.hidden, false);
|
||||
assert.match($("hdc-setup").textContent, /Mac.*ARM64/);
|
||||
assert.match($("hdc-setup").textContent, /解压/);
|
||||
assert.match($("hdc-setup").textContent.replace(/\s+/g, " "), /USB 调试/);
|
||||
await click("hdc-download");
|
||||
assert.deepEqual(model.openedUrls, [
|
||||
"https://developer.huawei.com/consumer/cn/download/command-line-tools-for-hmos",
|
||||
]);
|
||||
assert.equal($("hdc-setup").hidden, false);
|
||||
assert.ok(!model.calls.includes("hdc.devices"));
|
||||
await click("hdc-directory");
|
||||
assert.deepEqual(
|
||||
model.parameters.find(([name]) => name === "hdc.configure")[1],
|
||||
{
|
||||
path: "/fixture/folder",
|
||||
},
|
||||
);
|
||||
assert.equal($("hdc-setup").hidden, true);
|
||||
assert.equal($("hdc-target").options.length, 1);
|
||||
});
|
||||
test("refresh rechecks tool availability and clears stale devices if the tool disappears", async (t) => {
|
||||
const { $, click, model } = await app(t);
|
||||
await click("tab-management");
|
||||
await click("hdc-refresh");
|
||||
assert.ok(!model.calls.includes("hdc.devices"));
|
||||
model.hdcAvailable = true;
|
||||
await click("hdc-refresh");
|
||||
assert.equal($("hdc-setup").hidden, true);
|
||||
assert.equal($("screen-start").disabled, false);
|
||||
model.hdcAvailable = false;
|
||||
await click("hdc-refresh");
|
||||
assert.equal($("hdc-setup").hidden, false);
|
||||
assert.equal($("hdc-target").options.length, 0);
|
||||
assert.equal($("screen-start").disabled, true);
|
||||
});
|
||||
test("cancelled or invalid toolkit selection preserves installation guidance", async (t) => {
|
||||
const { $, click, model } = await app(t);
|
||||
await click("tab-management");
|
||||
model.selectedDirectory = null;
|
||||
await click("hdc-directory");
|
||||
assert.ok(!model.calls.includes("hdc.configure"));
|
||||
model.selectedDirectory = "/fixture/wrong";
|
||||
model.configureError = new Error("未找到 HDC,请选择解压后的工具目录。");
|
||||
await click("hdc-directory");
|
||||
assert.equal($("hdc-setup").hidden, false);
|
||||
assert.ok(!model.calls.includes("hdc.devices"));
|
||||
assert.match(document.body.textContent, /未找到 HDC/);
|
||||
});
|
||||
test("application installation requires confirmation and pins the reviewed package hash", async (t) => {
|
||||
const { $, click, model } = await app(t);
|
||||
model.hdcAvailable = true;
|
||||
|
||||
Reference in New Issue
Block a user