AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
import { describe, expect, it } from "vitest";
import type { HomeDashboardResponse } from "@/app/api/__generated__/models/homeDashboardResponse";
import {
formatCurrency,
formatDuration,
formatHeaderDate,
formatWeeklySpend,
getHomeStatusLine,
getTimeOfDayGreeting,
} from "./helpers";
describe("getTimeOfDayGreeting", () => {
it("maps hours to greetings", () => {
expect(getTimeOfDayGreeting(8)).toBe("Good morning");
expect(getTimeOfDayGreeting(14)).toBe("Good afternoon");
expect(getTimeOfDayGreeting(21)).toBe("Good evening");
});
});
describe("getHomeStatusLine", () => {
const dashboard = {
attention: [{}, {}],
active_tasks: [{}],
} as HomeDashboardResponse;
it("leads with decisions and active work", () => {
expect(getHomeStatusLine(dashboard)).toBe(
"2 decisions waiting · 1 workflow is running now",
);
});
it("says how many workflows are running when nothing needs you", () => {
expect(getHomeStatusLine({ ...dashboard, attention: [] })).toBe(
"All clear · 1 workflow is running now",
);
expect(
getHomeStatusLine({
...dashboard,
attention: [],
active_tasks: [...dashboard.active_tasks, ...dashboard.active_tasks],
}),
).toBe("All clear · 2 workflows are running now");
});
it("reports an all-clear state", () => {
expect(
getHomeStatusLine({
...dashboard,
attention: [],
active_tasks: [],
}),
).toBe("Nothing needs you right now");
});
});
describe("formatters", () => {
it("formats the briefing day in its configured timezone", () => {
expect(
formatHeaderDate(
new Date("2026-08-09T23:30:00Z"),
"Asia/Kolkata",
"en-US",
),
).toEqual({ weekday: "Monday", calendarDate: "August 10" });
});
it("formats measured runtime and cost", () => {
expect(formatDuration(18_120)).toBe("5h 2m");
expect(formatDuration(120)).toBe("2m");
expect(formatCurrency(367)).toBe("$3.67");
});
it("drops the weekly spend line when nothing was attributed", () => {
expect(formatWeeklySpend(1_250)).toBe("$12.50 this week");
expect(formatWeeklySpend(0)).toBeNull();
expect(formatWeeklySpend(undefined)).toBeNull();
});
});