Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

UsageLimitRecoveryBanner.test.tsx

39 lines1.3 KB

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 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 }).description;
23​
24describe("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(bannerDescription(new Date(2026, 9, 20, 17, 30), timestampFormat)).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(bannerDescription(new Date(2026, 9, 21, 17, 30), "24-hour")).toBe(
36 "Resets tomorrow at 17:30",
37 );
38 });
39});