Open History to see the last commit
1import { RunId } from "@t3tools/contracts";
2import type { TimestampFormat } from "@t3tools/contracts/settings";
3import { describe, expect, it, vi } from "vite-plus/test";
4
5import { usageLimitRecoveryBannerItem } from "./UsageLimitRecoveryBanner";
6
7const stoppedAt = new Date(2026, 9, 20, 12, 0);
8
9function bannerDescription(resetAt: Date, timestampFormat: TimestampFormat) {
10 return usageLimitRecoveryBannerItem({
11 runId: RunId.make("run-1"),
12 resetAt: resetAt.toISOString(),
13 stoppedAt: stoppedAt.toISOString(),
14 snoozedUntil: null,
15 recovery: null,
16 timestampFormat,
17 onChange: async () => {},
18 }).description;
19}
20
21describe("usageLimitRecoveryBannerItem", () => {
22 it.each([
23 ["12-hour", "Resets 5:30 PM"],
24 ["24-hour", "Resets 17:30"],
25 ] as const)("formats a same-day reset with the %s setting", (timestampFormat, expected) => {
26 using _now = vi.spyOn(Date, "now").mockReturnValue(stoppedAt.getTime());
27 expect(bannerDescription(new Date(2026, 9, 20, 17, 30), timestampFormat)).toBe(expected);
28 });
29
30 it("names the day when the reset is tomorrow", () => {
31 using _now = vi.spyOn(Date, "now").mockReturnValue(stoppedAt.getTime());
32 expect(bannerDescription(new Date(2026, 9, 21, 17, 30), "24-hour")).toBe(
33 "Resets tomorrow at 17:30",
34 );
35 });
36});