import type { AutopilotRecent } from "@rakazo/contracts"; import { describe, expect, it, vi } from "vitest"; import { autopilotSummary, autopilotTimeOfDay } from "./autopilot"; vi.mock("./i18n", () => ({ t: (message: string, values?: Record) => message.replace(/\{(\w+)\}/g, (_, key: string) => String(values?.[key] ?? "")), })); function autopilot(patch: Partial = {}): AutopilotRecent { return { id: "autopilot-1", botId: "bot-1", threadId: "thread-1", spaceId: "space-1", groupId: null, goal: "Tidy the tickets", focus: null, until: null, status: "active", pauseReason: null, lastCheckpoint: null, nextStep: null, result: null, stepCount: 0, startedAt: "2026-10-05T00:00:00.000Z", endedAt: null, ...patch, }; } describe("autopilot on mobile", () => { it("hands the picked time to autopilotUntil as HH:MM", () => { expect(autopilotTimeOfDay(new Date(2026, 9, 5, 6, 5))).toBe("06:05"); expect(autopilotTimeOfDay(new Date(2026, 9, 5, 23, 30))).toBe("23:30"); }); it("sums up the night like Today on web", () => { expect( autopilotSummary(autopilot({ stepCount: 2, lastCheckpoint: "Ticket 2 tidied" })), ).toEqual({ detail: "last: Ticket 2 tidied", trail: "2 steps" }); expect( autopilotSummary(autopilot({ status: "finished", stepCount: 1, result: "All tidy." })), ).toEqual({ detail: "All tidy.", trail: "1 step" }); expect( autopilotSummary(autopilot({ status: "paused", stepCount: 3, pauseReason: "Need a key." })), ).toEqual({ detail: "Need a key.", trail: "Paused" }); expect(autopilotSummary(autopilot())).toEqual({ detail: "", trail: "0 steps" }); }); });