Skip to content

Commit cffcf55

Browse files
committed
test(web-evals): cover formatters; memoize statusLabels
1 parent e1b1b5b commit cffcf55

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

apps/web-evals/src/app/runs/[id]/run.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -554,20 +554,23 @@ export function Run({ run }: { run: Run }) {
554554
return groups
555555
}, [tasks, groupByStatus, getTaskStatusCategory])
556556

557-
const statusLabels: Record<TaskStatusCategory, { label: string; className: string; count: number }> = {
558-
failed: { label: "Failed", className: "text-red-500", count: groupedTasks?.failed.length ?? 0 },
559-
in_progress: {
560-
label: "In Progress",
561-
className: "text-yellow-500",
562-
count: groupedTasks?.in_progress.length ?? 0,
563-
},
564-
passed: { label: "Passed", className: "text-green-500", count: groupedTasks?.passed.length ?? 0 },
565-
not_started: {
566-
label: "Not Started",
567-
className: "text-muted-foreground",
568-
count: groupedTasks?.not_started.length ?? 0,
569-
},
570-
}
557+
const statusLabels = useMemo(
558+
(): Record<TaskStatusCategory, { label: string; className: string; count: number }> => ({
559+
failed: { label: "Failed", className: "text-red-500", count: groupedTasks?.failed.length ?? 0 },
560+
in_progress: {
561+
label: "In Progress",
562+
className: "text-yellow-500",
563+
count: groupedTasks?.in_progress.length ?? 0,
564+
},
565+
passed: { label: "Passed", className: "text-green-500", count: groupedTasks?.passed.length ?? 0 },
566+
not_started: {
567+
label: "Not Started",
568+
className: "text-muted-foreground",
569+
count: groupedTasks?.not_started.length ?? 0,
570+
},
571+
}),
572+
[groupedTasks],
573+
)
571574

572575
const statusOrder: TaskStatusCategory[] = ["failed", "in_progress", "passed", "not_started"]
573576

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { formatDuration, formatTokens } from "../formatters"
2+
3+
describe("formatDuration()", () => {
4+
it("formats as H:MM:SS", () => {
5+
expect(formatDuration(0)).toBe("0:00:00")
6+
expect(formatDuration(1_000)).toBe("0:00:01")
7+
expect(formatDuration(61_000)).toBe("0:01:01")
8+
expect(formatDuration(3_661_000)).toBe("1:01:01")
9+
})
10+
})
11+
12+
describe("formatTokens()", () => {
13+
it("formats small numbers without suffix", () => {
14+
expect(formatTokens(0)).toBe("0")
15+
expect(formatTokens(999)).toBe("999")
16+
})
17+
18+
it("formats thousands without decimals and clamps to 1.0M at boundary", () => {
19+
expect(formatTokens(1_000)).toBe("1k")
20+
expect(formatTokens(72_500)).toBe("73k")
21+
expect(formatTokens(999_499)).toBe("999k")
22+
expect(formatTokens(999_500)).toBe("1.0M")
23+
})
24+
25+
it("formats millions with one decimal and clamps to 1.0B at boundary", () => {
26+
expect(formatTokens(1_000_000)).toBe("1.0M")
27+
expect(formatTokens(3_240_000)).toBe("3.2M")
28+
expect(formatTokens(999_950_000)).toBe("1.0B")
29+
})
30+
})

0 commit comments

Comments
 (0)