/**
* エラー一覧の「紐づく予定」ラベル `errorScheduleLabel()` の期待値表(指示書AW §3 表3 / 段階1-3)
*
* ★表3 は指示書AW で導いたもの(監督確認済み・正)★
* | # | schedule_link / precheck_minutes | JP | EN(暫定) |
* |----|----------------------------------|------------------------|------------|
* | S1 | main / null | 本清掃 | Main run |
* | S2 | precheck / 30 | 事前チェック(30分前) | Pre-check (30 min before) |
* | S3 | precheck / 10 | 事前チェック(10分前) | Pre-check (10 min before) |
* | S4 | none / null | 予定なし | No schedule |
* | S5 | unknown / null | 予定不明 | Unknown schedule |
* | S6 | precheck / null(契約では起きない)| 事前チェック | Pre-check |
*
* ★`t` は恒等関数と EN 辞書の2通り★。
* ★EN は本物の辞書(`translate("en", …)`。`lib/i18n.ts`)で確かめる★ — 段階5-5 でキーを足したので、
* 段階1・2 で使っていたテスト内の対訳表(`EN_PLANNED`)から差し替えた。
* ★これで辞書のキーの綴り(全角括弧・`{n}`)も固定される★ — 1文字でも違うと `translate()` は
* 未登録キーとして日本語のまま返し(fail-silent)、EN の期待値と食い違って落ちる。
*/
import { describe, expect, it } from "vitest";
import { PRECHECK_MINUTES_BEFORE } from "@/lib/config";
import { errorScheduleLabel } from "@/lib/error-reports/label";
import { translate } from "@/lib/i18n";
import type { ErrorScheduleLink } from "@/lib/types";
const identity = (text: string) => text;
/** `useTheme()` の `t` と同じ形(`components/theme/ThemeProvider.tsx` は `translate(lang, text)` を渡す) */
const en = (text: string) => translate("en", text);
const PRECHECK_30 = PRECHECK_MINUTES_BEFORE[1];
const TABLE3: [string, ErrorScheduleLink, number | null, string, string][] = [
["S1", "main", null, "本清掃", "Main run"],
["S2", "precheck", PRECHECK_30, `事前チェック(${PRECHECK_30}分前)`, `Pre-check (${PRECHECK_30} min before)`],
// ★10 は設定(60/30)に無い値であることが本題なので直書きする★
["S3", "precheck", 10, "事前チェック(10分前)", "Pre-check (10 min before)"],
["S4", "none", null, "予定なし", "No schedule"],
["S5", "unknown", null, "予定不明", "Unknown schedule"],
["S6", "precheck", null, "事前チェック", "Pre-check"],
];
describe("errorScheduleLabel(表3)", () => {
it.each(TABLE3)("%s JP", (_no, link, minutes, ja) => {
expect(errorScheduleLabel(identity, { schedule_link: link, precheck_minutes: minutes })).toBe(ja);
});
it.each(TABLE3)("%s EN", (_no, link, minutes, _ja, enLabel) => {
expect(errorScheduleLabel(en, { schedule_link: link, precheck_minutes: minutes })).toBe(enLabel);
});
it("★S6: 黙って「null分前」を出さない★", () => {
const label = errorScheduleLabel(identity, { schedule_link: "precheck", precheck_minutes: null });
expect(label).not.toContain("null");
expect(label).not.toContain("{n}");
});
});