返回 DeepSeek-Reasonix
font-availability.test.ts
根目录 / desktop / frontend / src / __tests__ / font-availability.test.ts
1 // Run: tsx src/__tests__/font-availability.test.ts
2
3 import { getAvailableFontFamilies, getAvailableMonoFontFamilies } from "../lib/fontAvailability";
4
5 let passed = 0;
6 let failed = 0;
7
8 function eq(a: unknown, b: unknown, label: string) {
9 if (JSON.stringify(a) === JSON.stringify(b)) {
10 process.stdout.write(` PASS ${label}\n`);
11 passed += 1;
12 } else {
13 process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(b)}, got ${JSON.stringify(a)}\n`);
14 failed += 1;
15 }
16 }
17
18 const noneInstalled = () => false;
19 const hasFont = (name: string) => (names: readonly string[]) => names.includes(name);
20
21 console.log("\nfont availability");
22
23 eq(
24 getAvailableFontFamilies("system", "darwin", noneInstalled),
25 ["system", "pingfang", "custom"],
26 "macOS shows native UI font plus stable choices",
27 );
28 eq(
29 getAvailableFontFamilies("system", "windows", noneInstalled),
30 ["system", "yahei", "custom"],
31 "Windows shows native UI font plus stable choices",
32 );
33 eq(
34 getAvailableFontFamilies("system", "linux", noneInstalled),
35 ["system", "noto", "custom"],
36 "Linux shows Noto-style UI font plus stable choices",
37 );
38 eq(
39 getAvailableFontFamilies("system", "darwin", hasFont("Microsoft YaHei")),
40 ["system", "yahei", "pingfang", "custom"],
41 "detected cross-platform UI fonts are included",
42 );
43 eq(
44 getAvailableFontFamilies("yahei", "darwin", noneInstalled),
45 ["system", "yahei", "pingfang", "custom"],
46 "current UI font remains visible even when it is not native",
47 );
48
49 eq(
50 getAvailableMonoFontFamilies("system", "darwin", noneInstalled),
51 ["system", "sfmono", "custom"],
52 "macOS shows native mono font plus stable choices",
53 );
54 eq(
55 getAvailableMonoFontFamilies("system", "windows", noneInstalled),
56 ["system", "cascadia", "custom"],
57 "Windows shows native mono font plus stable choices",
58 );
59 eq(
60 getAvailableMonoFontFamilies("system", "linux", hasFont("JetBrains Mono")),
61 ["system", "jetbrains", "custom"],
62 "detected mono fonts are included on Linux",
63 );
64 eq(
65 getAvailableMonoFontFamilies("sfmono", "windows", noneInstalled),
66 ["system", "cascadia", "sfmono", "custom"],
67 "current mono font remains visible even when it is not native",
68 );
69
70 console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`);
71 if (failed > 0) process.exit(1);
72
72 lines TYPESCRIPT