The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 86 lines 2.92 KB
Raw
1 import { RunId } from "@t3tools/contracts";
2 import type { TimestampFormat } from "@t3tools/contracts/settings";
3 import { describe, expect, it, vi } from "vite-plus/test";
4
5 import { usageLimitRecoveryBannerItem } from "./UsageLimitRecoveryBanner";
6
7 const stoppedAt = new Date(2026, 9, 20, 12, 0);
8
9 function bannerItem(resetAt: Date, timestampFormat: TimestampFormat = "24-hour") {
10 return usageLimitRecoveryBannerItem({
11 runId: RunId.make("run-1"),
12 errorCode: null,
13 resetAt: resetAt.toISOString(),
14 stoppedAt: stoppedAt.toISOString(),
15 settled: false,
16 requestPending: false,
17 snoozedUntil: null,
18 recovery: null,
19 timestampFormat,
20 onChange: async () => {},
21 });
22 }
23
24 describe("usageLimitRecoveryBannerItem", () => {
25 it.each([
26 ["12-hour", "Resets 5:30 PM"],
27 ["24-hour", "Resets 17:30"],
28 ] as const)("formats a same-day reset with the %s setting", (timestampFormat, expected) => {
29 using _now = vi.spyOn(Date, "now").mockReturnValue(stoppedAt.getTime());
30 expect(bannerItem(new Date(2026, 9, 20, 17, 30), timestampFormat).description).toBe(expected);
31 });
32
33 it("names the day when the reset is tomorrow", () => {
34 using _now = vi.spyOn(Date, "now").mockReturnValue(stoppedAt.getTime());
35 expect(bannerItem(new Date(2026, 9, 21, 17, 30)).description).toBe("Resets tomorrow at 17:30");
36 });
37
38 it("uses past-tense copy after the reset time has passed", () => {
39 const resetAt = new Date(2026, 9, 20, 15, 0);
40 {
41 using _before = vi
42 .spyOn(Date, "now")
43 .mockReturnValue(new Date(2026, 9, 20, 14, 57).getTime());
44 expect(bannerItem(resetAt).description).toBe("Resets 15:00");
45 }
46 {
47 using _after = vi.spyOn(Date, "now").mockReturnValue(new Date(2026, 9, 20, 15, 14).getTime());
48 expect(bannerItem(resetAt).description).toBe("Reset 15:00");
49 }
50 });
51
52 it("keeps Resumes copy until a later snooze wake time, then falls back to Reset", () => {
53 const resetAt = new Date(2026, 9, 20, 15, 0);
54 const snoozedUntil = new Date(2026, 9, 20, 16, 0);
55 const runId = RunId.make("run-1");
56 const makeScheduled = () =>
57 usageLimitRecoveryBannerItem({
58 runId,
59 errorCode: null,
60 resetAt: resetAt.toISOString(),
61 stoppedAt: stoppedAt.toISOString(),
62 settled: false,
63 requestPending: false,
64 snoozedUntil: snoozedUntil.toISOString(),
65 recovery: {
66 runId,
67 resetAt: resetAt.toISOString(),
68 autoResume: true,
69 },
70 timestampFormat: "24-hour",
71 onChange: async () => {},
72 });
73 {
74 using _between = vi
75 .spyOn(Date, "now")
76 .mockReturnValue(new Date(2026, 9, 20, 15, 14).getTime());
77 expect(makeScheduled().description).toBe("Resumes 16:00");
78 }
79 {
80 using _afterSnooze = vi
81 .spyOn(Date, "now")
82 .mockReturnValue(new Date(2026, 9, 20, 16, 5).getTime());
83 expect(makeScheduled().description).toBe("Reset 15:00");
84 }
85 });
86 });