返回 DeepSeek-Reasonix
workspace-change-status.test.ts
根目录 / desktop / frontend / src / __tests__ / workspace-change-status.test.ts
1 // Run: tsx src/__tests__/workspace-change-status.test.ts
2
3 import { workspaceGitStatusLabel, workspaceGitStatusLabelKey } from "../lib/workspaceChanges";
4 import { en } from "../locales/en";
5 import { zh } from "../locales/zh";
6 import { zhTW } from "../locales/zh-TW";
7
8 let passed = 0;
9 let failed = 0;
10
11 function eq<T>(actual: T, expected: T, label: string) {
12 if (Object.is(actual, expected)) {
13 process.stdout.write(` PASS ${label}\n`);
14 passed += 1;
15 } else {
16 process.stdout.write(` FAIL ${label}\n expected: ${String(expected)}\n actual: ${String(actual)}\n`);
17 failed += 1;
18 }
19 }
20
21 const t = ((key: string) => (en as Record<string, string>)[key] ?? key) as never;
22
23 console.log("\nworkspace git status labels");
24
25 eq(workspaceGitStatusLabel("??", t), "Untracked", "?? reads as untracked instead of leaking porcelain");
26 eq(workspaceGitStatusLabel(" M", t), "Modified", "unstaged modification");
27 eq(workspaceGitStatusLabel("A ", t), "Added", "staged addition");
28 eq(workspaceGitStatusLabel("D ", t), "Deleted", "deletion");
29 eq(workspaceGitStatusLabel("R ", t), "Renamed", "rename");
30 eq(workspaceGitStatusLabel("UU", t), "Conflict", "unmerged conflict");
31 eq(workspaceGitStatusLabel("MM", t), "Modified", "staged and unstaged modification");
32
33 eq(workspaceGitStatusLabel(undefined, t), "", "missing status renders nothing");
34 eq(workspaceGitStatusLabel(" ", t), "", "blank status renders nothing");
35 eq(workspaceGitStatusLabel("!!", t), "!!", "an unmapped code passes through rather than vanishing");
36
37 eq(workspaceGitStatusLabelKey("DD"), "workspace.gitStatusUnmerged", "DD is a merge conflict, not a plain deletion");
38 eq(workspaceGitStatusLabelKey("AA"), "workspace.gitStatusUnmerged", "AA is a merge conflict, not a plain addition");
39 eq(workspaceGitStatusLabelKey("UD"), "workspace.gitStatusUnmerged", "UD is a merge conflict");
40
41 for (const [name, dict] of [["zh", zh], ["zh-TW", zhTW]] as const) {
42 const missing = Object.keys(en)
43 .filter((key) => key.startsWith("workspace.gitStatus"))
44 .filter((key) => !(key in (dict as Record<string, string>)));
45 eq(missing.length, 0, `${name} translates every git status label (${missing.join(", ")})`);
46 }
47
48 console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`);
49 if (failed > 0) process.exit(1);
50
50 lines TYPESCRIPT