Skip to content

Open-source, local-first AI agent for real work.

2.6 KB
Raw Blame
import { existsSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { APP_ICON_DEFAULT, APP_ICON_GROUPS, APP_ICON_IDS, isAppIconId, normalizeAppIconId } from "./app-icon.js";

describe("app-icon", () => {
	it("未知或非字符串回落默认,合法 id 原样保留", () => {
		expect(normalizeAppIconId("coding")).toBe("coding");
		expect(normalizeAppIconId("removed-icon")).toBe(APP_ICON_DEFAULT);
		expect(normalizeAppIconId(undefined)).toBe(APP_ICON_DEFAULT);
		expect(isAppIconId(42)).toBe(false);
	});

	it("蓝色版已并入出厂图标:存过 blue 的配置回落默认,深色版作为可选风格保留", () => {
		expect(isAppIconId("blue")).toBe(false);
		expect(normalizeAppIconId("blue")).toBe(APP_ICON_DEFAULT);
		expect(normalizeAppIconId("dark")).toBe("dark");
	});

	it("上一版出厂的水滴与同批 logo 方案都是可选风格,各自带 macOS 与圆角版本", () => {
		for (const id of ["droplet", "penguin", "mini", "strap", "rabbit", "prompt", "block"]) {
			expect(normalizeAppIconId(id)).toBe(id);
			for (const suffix of ["-mac", "-round"]) {
				expect(existsSync(join(__dirname, `../../build/app-icons/${id}${suffix}.png`)), `${id}${suffix}`).toBe(
					true,
				);
			}
		}
	});

	it("眼镜水滴的红、黑、浅色底版都是可选风格", () => {
		for (const id of ["red", "black", "light"]) expect(normalizeAppIconId(id)).toBe(id);
	});

	it("黑底毛绒动物头像都是可选风格,各自带 macOS 与圆角版本", () => {
		for (const id of [
			"router",
			"researcher",
			"architect",
			"executor",
			"auditor",
			"optimizer",
			"synthesizer",
			"translator",
		]) {
			expect(normalizeAppIconId(id)).toBe(id);
			for (const suffix of ["-mac", "-round"]) {
				expect(existsSync(join(__dirname, `../../build/app-icons/${id}${suffix}.png`)), `${id}${suffix}`).toBe(
					true,
				);
			}
		}
	});

	it("每个图标恰好属于一个分组,出厂图标在第一组打头", () => {
		const ids = APP_ICON_GROUPS.flatMap((group) => [...group.icons]);
		expect(new Set(ids).size).toBe(ids.length);
		expect(APP_ICON_GROUPS[0].icons[0]).toBe(APP_ICON_DEFAULT);
	});

	it("除默认外,每个图标都有打包进应用的图片和设置页预览图", () => {
		for (const id of APP_ICON_IDS) {
			if (id === APP_ICON_DEFAULT) continue;
			expect(existsSync(join(__dirname, `../../build/app-icons/${id}.png`)), `build/app-icons/${id}.png`).toBe(true);
		}
		for (const id of APP_ICON_IDS) {
			expect(
				existsSync(join(__dirname, `../renderer/domains/settings/assets/app-icons/${id}.png`)),
				`preview ${id}`,
			).toBe(true);
		}
	});
});