Skip to content

Commit 06b919f

Browse files
committed
test(infra): move duration cases to the formatter owner
1 parent fa0f9e7 commit 06b919f

2 files changed

Lines changed: 22 additions & 36 deletions

File tree

‎src/infra/format-time/format-time.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveTimeZoneDayStartMs,
99
resolveTimezone,
1010
} from "./format-datetime.js";
11+
import { formatSingleUnitDuration } from "./format-duration-internal.js";
1112
import {
1213
formatDurationCompact,
1314
formatDurationHuman,
@@ -97,6 +98,27 @@ describe("format-duration", () => {
9798
});
9899
});
99100

101+
describe("formatSingleUnitDuration", () => {
102+
it.each([
103+
[59_500, "60 seconds", "1 minute"],
104+
[3_570_000, "60 minutes", "1 hour"],
105+
[86_370_000, "24 hours", "1 day"],
106+
])("rolls over %dms to the next unit instead of %s", (input, _buggyOutput, expected) => {
107+
expect(formatSingleUnitDuration(input, true)).toBe(expected);
108+
});
109+
110+
it.each([
111+
[30_000, "30 seconds"],
112+
[89_500, "1 minute"],
113+
[1_800_000, "30 minutes"],
114+
[5_370_000, "1 hour"],
115+
[43_200_000, "12 hours"],
116+
[129_570_000, "1 day"],
117+
])("keeps %dms in its own unit as %s", (input, expected) => {
118+
expect(formatSingleUnitDuration(input, true)).toBe(expected);
119+
});
120+
});
121+
100122
describe("formatDurationPrecise", () => {
101123
it.each([
102124
{ input: 500, expected: "500ms" },

‎src/infra/session-maintenance-warning.test.ts‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -199,42 +199,6 @@ describe("deliverSessionMaintenanceWarning", () => {
199199
]);
200200
});
201201

202-
it.each([
203-
[59_500, "60 seconds", "1 minute"],
204-
[3_570_000, "60 minutes", "1 hour"],
205-
[86_370_000, "24 hours", "1 day"],
206-
])(
207-
"formatDuration rolls over %dms to next unit instead of %s",
208-
async (pruneAfterMs, _buggyOutput, expected) => {
209-
mocks.deliverOutboundPayloads.mockRejectedValueOnce(new Error("force system event"));
210-
const params = createParams({
211-
warning: { pruneAfterMs, wouldPrune: true, wouldCap: false, maxEntries: 100 } as never,
212-
});
213-
214-
await deliverSessionMaintenanceWarning(params);
215-
216-
expect(firstSystemEventCall()?.[0]).toContain(`older than ${expected}`);
217-
},
218-
);
219-
220-
it.each([
221-
[30_000, "30 seconds"],
222-
[89_500, "1 minute"],
223-
[1_800_000, "30 minutes"],
224-
[5_370_000, "1 hour"],
225-
[43_200_000, "12 hours"],
226-
[129_570_000, "1 day"],
227-
])("formatDuration keeps %dms in its own unit as %s", async (pruneAfterMs, expected) => {
228-
mocks.deliverOutboundPayloads.mockRejectedValueOnce(new Error("force system event"));
229-
const params = createParams({
230-
warning: { pruneAfterMs, wouldPrune: true, wouldCap: false, maxEntries: 100 } as never,
231-
});
232-
233-
await deliverSessionMaintenanceWarning(params);
234-
235-
expect(firstSystemEventCall()?.[0]).toContain(`older than ${expected}`);
236-
});
237-
238202
it("keeps a recently used context while evicting the least-recently-used entry", async () => {
239203
const maxEntries = 4096;
240204
const createSessionParams = (sessionKey: string) =>

0 commit comments

Comments
 (0)