fix(desktop): format loading elapsed time
This commit is contained in:
1 parent
6b13564180
commit
8883a6b3b7
4 files changed
+45
-12
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatElapsedSeconds } from "@/lib/common/elapsedTime";
|
||||
|
||||
describe("formatElapsedSeconds", () => {
|
||||
it("formats elapsed milliseconds with two fractional second digits", () => {
|
||||
expect(formatElapsedSeconds(1234)).toBe("1.23");
|
||||
expect(formatElapsedSeconds(5)).toBe("0.01");
|
||||
expect(formatElapsedSeconds(0)).toBe("0.00");
|
||||
});
|
||||
|
||||
it("clamps invalid elapsed values to zero", () => {
|
||||
expect(formatElapsedSeconds(-100)).toBe("0.00");
|
||||
expect(formatElapsedSeconds(Number.NaN)).toBe("0.00");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
export function formatElapsedSeconds(ms: number): string {
|
||||
return (Math.max(0, Number.isFinite(ms) ? ms : 0) / 1000).toFixed(2);
|
||||
}
|
||||
Reference in new issue
Block a user