cm_whatsapp_bot_v1/apps/bot/src/reminders/time-parsing.test.ts
yiekheng a5bbf3a25d feat(bot): redesign reminder time picker (menu-driven)
Time picker UX changes after live testing:
- Add "🕐 Now" quick option (fires within 30s)
- Remove "🕐 In 1 hour" / "🕒 In 3 hours" — Now + Tomorrow 9 AM cover the
  practical fast-path
- Replace free-text custom date input with a 3-step menu picker:
  Day (Today, Tomorrow, +2d, +3d, +4d, +5d, +1w, +2w, +1m)
  → Hour (24-hour grid, daytime first)
  → Minute (5-min increments)
- Validate the chosen day+hour+minute against "now" and reject if past

Drops parseFreeText path entirely; the wizard's set_time step is gone.
2026-05-09 17:45:08 +08:00

37 lines
1.2 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { quickToDate, buildCustomDate, formatCustomDay } from "./time-parsing.js";
describe("quickToDate", () => {
it("now returns ~30s ahead", () => {
const d = quickToDate("now");
const diffMs = d.getTime() - Date.now();
expect(diffMs).toBeGreaterThan(20 * 1000);
expect(diffMs).toBeLessThan(40 * 1000);
});
it("tomorrow_9am returns a future Date", () => {
const d = quickToDate("tomorrow_9am");
expect(d.getTime()).toBeGreaterThan(Date.now());
});
});
describe("buildCustomDate", () => {
it("rejects in-past day/hour/minute", () => {
const r = buildCustomDate(-1, 9, 0, "Asia/Kuala_Lumpur");
expect(r.ok).toBe(false);
if (!r.ok) expect(r.reason).toMatch(/past/i);
});
it("accepts a far-future combination", () => {
const r = buildCustomDate(7, 23, 45, "Asia/Kuala_Lumpur");
expect(r.ok).toBe(true);
});
});
describe("formatCustomDay", () => {
it("returns 'Today (...)' for offset 0", () => {
expect(formatCustomDay(0, "Asia/Kuala_Lumpur")).toMatch(/^Today/);
});
it("returns 'Tomorrow (...)' for offset 1", () => {
expect(formatCustomDay(1, "Asia/Kuala_Lumpur")).toMatch(/^Tomorrow/);
});
});