返回 DeepSeek-Reasonix
icons.test.ts
根目录 / desktop / electron / src / main / icons.test.ts
1 import assert from "node:assert/strict";
2 import { dirname, join, resolve } from "node:path";
3 import { test } from "node:test";
4 import { fileURLToPath } from "node:url";
5 import { firstExisting, iconCandidates } from "./icons.js";
6
7 const appPath = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
8
9 test("development Dock uses the macOS artwork and never a full-canvas fallback", () => {
10 const icons = iconCandidates({ platform: "darwin", appPath, resourcesPath: "/unused", packaged: false });
11 const macIcon = resolve(appPath, "../build/darwin/appicon.png");
12 assert.deepEqual(icons.dock, [macIcon]);
13 assert.equal(firstExisting(icons.dock), macIcon);
14 assert.ok(!icons.window.includes(macIcon));
15 });
16
17 test("packaged macOS preserves the bundle icon and other platforms do not set a Dock icon", () => {
18 for (const platform of ["darwin", "win32", "linux"] as const) {
19 for (const packaged of [false, true]) {
20 if (platform === "darwin" && !packaged) continue;
21 const icons = iconCandidates({ platform, appPath, resourcesPath: "/unused", packaged });
22 assert.equal(firstExisting(icons.dock), null, `${platform}, packaged=${packaged}`);
23 }
24 }
25 });
26
27 test("macOS tray resolves the dedicated template asset and never the full-canvas appicon", () => {
28 // The color artwork stays in the candidate list as a last-resort fallback
29 // (TrayHost renders it as a small color icon, never template-izes it); what
30 // must hold is that resolution lands on the template while it exists.
31 const dev = iconCandidates({ platform: "darwin", appPath, resourcesPath: "/unused", packaged: false });
32 assert.ok(dev.tray[0].endsWith("trayTemplate.png"));
33 assert.equal(firstExisting(dev.tray), resolve(appPath, "../build/trayTemplate.png"));
34 const packagedIcons = iconCandidates({ platform: "darwin", appPath, resourcesPath: "/unused", packaged: true });
35 assert.ok(packagedIcons.tray[0].endsWith("trayTemplate.png"));
36 });
37
38 test("non-macOS platforms keep the color tray candidates", () => {
39 for (const platform of ["win32", "linux"] as const) {
40 const icons = iconCandidates({ platform, appPath, resourcesPath: "/unused", packaged: false });
41 assert.ok(icons.tray[0].endsWith(join("hicolor", "32x32", "apps", "reasonix-desktop.png")), platform);
42 assert.ok(!icons.tray.some((path) => path.includes("trayTemplate")), platform);
43 }
44 });
45
45 lines TYPESCRIPT