Files
openclaw/test/ui.presenter-next-run.test.ts
weiqinl bd6802ffb6 test(ui): make formatNextRun weekday assertion locale-portable (#125164)
The "includes weekday and relative time" test computed the expected
weekday with the ambient host locale (`toLocaleDateString(undefined, ...)`)
while `formatNextRun` formats the weekday through `i18n.getLocale()`
(default "en"). On hosts whose default locale is not English (e.g.
`LANG=zh_CN.UTF-8` -> "周一"), the two diverge and the slice assertion
fails: `expected 'Mon,' to be '周一, '`.

Mirror `i18n.getLocale()` in the test so the expected weekday always
matches the locale the presenter uses. No production behavior change.

Verified: passes under `LANG=zh_CN.UTF-8` and `LANG=C` via
`pnpm test:unit:fast -- test/ui.presenter-next-run.test.ts`.

AI-assisted.
2026-08-20 01:25:28 -07:00

24 lines
1008 B
TypeScript

// UI presenter next-run tests cover presenter scheduling output.
import { describe, expect, it } from "vitest";
import { i18n, t } from "../ui/src/i18n/index.ts";
import { formatNextRun } from "../ui/src/lib/presenter.ts";
describe("formatNextRun", () => {
it("returns localized n/a for nullish values", () => {
expect(formatNextRun(null)).toBe(t("common.na"));
expect(formatNextRun(undefined)).toBe(t("common.na"));
});
it("includes weekday and relative time", () => {
const ts = Date.UTC(2026, 1, 23, 15, 0, 0);
const out = formatNextRun(ts);
// formatNextRun formats the weekday through i18n.getLocale(); mirror that
// locale here instead of the ambient host locale so the assertion holds on
// non-en hosts (e.g. LANG=zh_CN.UTF-8).
const weekday = new Date(ts).toLocaleDateString(i18n.getLocale(), { weekday: "short" });
expect(out.slice(0, weekday.length + 2)).toBe(`${weekday}, `);
expect(out).toContain("(");
expect(out).toContain(")");
});
});