|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { |
| 3 | + MSG, |
| 4 | + CLI_REPORT, |
| 5 | + OPENCLAW_REPORT, |
| 6 | + WEB_REPORT, |
| 7 | + TRENDING_REPORT, |
| 8 | + HN_REPORT, |
| 9 | + WEEKLY_REPORT, |
| 10 | + MONTHLY_REPORT, |
| 11 | + ISSUE_LABELS, |
| 12 | + CLI_ISSUE_TITLE, |
| 13 | + OPENCLAW_ISSUE_TITLE, |
| 14 | + FOOTER, |
| 15 | + NOTIFY_LABELS, |
| 16 | +} from "../i18n.ts"; |
| 17 | + |
| 18 | +// --------------------------------------------------------------------------- |
| 19 | +// Static bilingual strings |
| 20 | +// --------------------------------------------------------------------------- |
| 21 | + |
| 22 | +describe("bilingual string maps", () => { |
| 23 | + const maps = [ |
| 24 | + { name: "MSG.noActivity", obj: MSG.noActivity }, |
| 25 | + { name: "MSG.summaryFailed", obj: MSG.summaryFailed }, |
| 26 | + { name: "MSG.skillsFailed", obj: MSG.skillsFailed }, |
| 27 | + { name: "MSG.trendingNoData", obj: MSG.trendingNoData }, |
| 28 | + { name: "MSG.trendingFailed", obj: MSG.trendingFailed }, |
| 29 | + { name: "CLI_REPORT.title", obj: CLI_REPORT.title }, |
| 30 | + { name: "CLI_REPORT.skillsHeading", obj: CLI_REPORT.skillsHeading }, |
| 31 | + { name: "CLI_REPORT.comparison", obj: CLI_REPORT.comparison }, |
| 32 | + { name: "CLI_REPORT.detail", obj: CLI_REPORT.detail }, |
| 33 | + { name: "OPENCLAW_REPORT.title", obj: OPENCLAW_REPORT.title }, |
| 34 | + { name: "OPENCLAW_REPORT.deepDive", obj: OPENCLAW_REPORT.deepDive }, |
| 35 | + { name: "WEB_REPORT.title", obj: WEB_REPORT.title }, |
| 36 | + { name: "WEB_REPORT.firstCrawl", obj: WEB_REPORT.firstCrawl }, |
| 37 | + { name: "TRENDING_REPORT.title", obj: TRENDING_REPORT.title }, |
| 38 | + { name: "HN_REPORT.title", obj: HN_REPORT.title }, |
| 39 | + { name: "WEEKLY_REPORT.title", obj: WEEKLY_REPORT.title }, |
| 40 | + { name: "MONTHLY_REPORT.title", obj: MONTHLY_REPORT.title }, |
| 41 | + { name: "FOOTER.autoGen", obj: FOOTER.autoGen }, |
| 42 | + ]; |
| 43 | + |
| 44 | + for (const { name, obj } of maps) { |
| 45 | + it(`${name} has both zh and en`, () => { |
| 46 | + expect(obj).toHaveProperty("zh"); |
| 47 | + expect(obj).toHaveProperty("en"); |
| 48 | + expect(obj.zh).toBeTruthy(); |
| 49 | + expect(obj.en).toBeTruthy(); |
| 50 | + expect(obj.zh).not.toBe(obj.en); |
| 51 | + }); |
| 52 | + } |
| 53 | +}); |
| 54 | + |
| 55 | +// --------------------------------------------------------------------------- |
| 56 | +// Dynamic title functions |
| 57 | +// --------------------------------------------------------------------------- |
| 58 | + |
| 59 | +describe("issue title functions", () => { |
| 60 | + it("CLI_ISSUE_TITLE produces zh and en titles", () => { |
| 61 | + expect(CLI_ISSUE_TITLE("2026-03-12", "zh")).toContain("AI CLI"); |
| 62 | + expect(CLI_ISSUE_TITLE("2026-03-12", "zh")).toContain("2026-03-12"); |
| 63 | + expect(CLI_ISSUE_TITLE("2026-03-12", "en")).toContain("AI CLI Tools Digest"); |
| 64 | + }); |
| 65 | + |
| 66 | + it("OPENCLAW_ISSUE_TITLE produces zh and en titles", () => { |
| 67 | + expect(OPENCLAW_ISSUE_TITLE("2026-03-12", "zh")).toContain("OpenClaw"); |
| 68 | + expect(OPENCLAW_ISSUE_TITLE("2026-03-12", "en")).toContain("OpenClaw Ecosystem Digest"); |
| 69 | + }); |
| 70 | + |
| 71 | + it("WEB_REPORT.issueTitle includes first crawl flag", () => { |
| 72 | + expect(WEB_REPORT.issueTitle("2026-03-12", true, "zh")).toContain("首次全量"); |
| 73 | + expect(WEB_REPORT.issueTitle("2026-03-12", false, "zh")).not.toContain("首次全量"); |
| 74 | + expect(WEB_REPORT.issueTitle("2026-03-12", true, "en")).toContain("First Crawl"); |
| 75 | + }); |
| 76 | + |
| 77 | + it("TRENDING_REPORT.issueTitle produces zh and en", () => { |
| 78 | + expect(TRENDING_REPORT.issueTitle("2026-03-12", "zh")).toContain("开源趋势"); |
| 79 | + expect(TRENDING_REPORT.issueTitle("2026-03-12", "en")).toContain("Open Source Trends"); |
| 80 | + }); |
| 81 | + |
| 82 | + it("HN_REPORT.issueTitle produces zh and en", () => { |
| 83 | + expect(HN_REPORT.issueTitle("2026-03-12", "zh")).toContain("Hacker News"); |
| 84 | + expect(HN_REPORT.issueTitle("2026-03-12", "en")).toContain("Hacker News"); |
| 85 | + }); |
| 86 | + |
| 87 | + it("WEEKLY_REPORT.issueTitle includes week string", () => { |
| 88 | + expect(WEEKLY_REPORT.issueTitle("2026-W11")).toContain("2026-W11"); |
| 89 | + }); |
| 90 | + |
| 91 | + it("MONTHLY_REPORT.issueTitle includes month string", () => { |
| 92 | + expect(MONTHLY_REPORT.issueTitle("2026-02")).toContain("2026-02"); |
| 93 | + }); |
| 94 | +}); |
| 95 | + |
| 96 | +// --------------------------------------------------------------------------- |
| 97 | +// Dynamic content functions |
| 98 | +// --------------------------------------------------------------------------- |
| 99 | + |
| 100 | +describe("dynamic content helpers", () => { |
| 101 | + it("CLI_REPORT.meta produces zh and en metadata", () => { |
| 102 | + const zh = CLI_REPORT.meta("12:00", 5, "zh"); |
| 103 | + expect(zh).toContain("12:00"); |
| 104 | + expect(zh).toContain("5 个"); |
| 105 | + |
| 106 | + const en = CLI_REPORT.meta("12:00", 5, "en"); |
| 107 | + expect(en).toContain("12:00"); |
| 108 | + expect(en).toContain("Tools covered: 5"); |
| 109 | + }); |
| 110 | + |
| 111 | + it("WEB_REPORT.newContent formats count", () => { |
| 112 | + expect(WEB_REPORT.newContent(10, "zh")).toContain("10 篇"); |
| 113 | + expect(WEB_REPORT.newContent(10, "en")).toContain("10 articles"); |
| 114 | + }); |
| 115 | + |
| 116 | + it("WEB_REPORT.generated formats timestamp", () => { |
| 117 | + expect(WEB_REPORT.generated("12:00", "zh")).toContain("12:00 UTC"); |
| 118 | + expect(WEB_REPORT.generated("12:00", "en")).toContain("12:00 UTC"); |
| 119 | + }); |
| 120 | +}); |
| 121 | + |
| 122 | +// --------------------------------------------------------------------------- |
| 123 | +// ISSUE_LABELS |
| 124 | +// --------------------------------------------------------------------------- |
| 125 | + |
| 126 | +describe("ISSUE_LABELS", () => { |
| 127 | + it("maps report types to label names", () => { |
| 128 | + expect(ISSUE_LABELS.cli.zh).toBe("digest"); |
| 129 | + expect(ISSUE_LABELS.cli.en).toBe("digest-en"); |
| 130 | + expect(ISSUE_LABELS.openclaw.zh).toBe("openclaw"); |
| 131 | + expect(ISSUE_LABELS.trending.en).toBe("trending-en"); |
| 132 | + expect(ISSUE_LABELS.hn.en).toBe("hn-en"); |
| 133 | + }); |
| 134 | +}); |
| 135 | + |
| 136 | +// --------------------------------------------------------------------------- |
| 137 | +// NOTIFY_LABELS |
| 138 | +// --------------------------------------------------------------------------- |
| 139 | + |
| 140 | +describe("NOTIFY_LABELS", () => { |
| 141 | + it("covers all report types", () => { |
| 142 | + const expected = ["ai-cli", "ai-agents", "ai-web", "ai-trending", "ai-hn", "ai-weekly", "ai-monthly"]; |
| 143 | + for (const key of expected) { |
| 144 | + expect(NOTIFY_LABELS[key]).toBeDefined(); |
| 145 | + expect(NOTIFY_LABELS[key]!.zh).toBeTruthy(); |
| 146 | + expect(NOTIFY_LABELS[key]!.en).toBeTruthy(); |
| 147 | + } |
| 148 | + }); |
| 149 | +}); |
0 commit comments