import { describe, expect, it } from "vitest";
import {
formatEndTime,
formatStartTime,
weekdaysLabel,
} from "@/lib/format/schedule";
/**
* 指示書M 4-4 / 4-5 の期待値表テスト。
*/
describe("weekdaysLabel", () => {
const cases: [string, string][] = [
["1111111", "毎日"],
["0111110", "平日のみ"],
["1000001", "土日のみ"],
["0101010", "月水金"],
["1010101", "日火木土"],
["0000000", "なし"],
["1000000", "日"],
["111", "日月火"],
];
it.each(cases)("%s → %s", (weeks, label) => {
expect(weekdaysLabel(weeks)).toBe(label);
});
});
describe("formatStartTime", () => {
it("0000〜2359 は HH:MM のまま", () => {
expect(formatStartTime("0200")).toBe("02:00");
expect(formatStartTime("2359")).toBe("23:59");
});
it("範囲外の時は例外を投げる", () => {
expect(() => formatStartTime("2400")).toThrow(RangeError);
});
});
describe("formatEndTime(D-060。24〜29時は翌日扱い)", () => {
const cases: [string, string][] = [
["0200", "02:00"],
["0300", "03:00"],
["2359", "23:59"],
["2430", "翌00:30"],
["2830", "翌04:30"],
["2900", "翌05:00"],
];
it.each(cases)("%s → %s", (hhmm, expected) => {
expect(formatEndTime(hhmm)).toBe(expected);
});
it("30〜99時(範囲外)は例外を投げる", () => {
expect(() => formatEndTime("3000")).toThrow(RangeError);
});
});