Add sorting to detail breakdown tables
This commit is contained in:
23
lib/detail-sort.test.ts
Normal file
23
lib/detail-sort.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { sortDetailBreakdown } from "./detail-sort";
|
||||
|
||||
describe("sortDetailBreakdown", () => {
|
||||
const rows = [
|
||||
{ name: "beta", calls: 2, total_tokens: 100, quota: 500 },
|
||||
{ name: "alpha", calls: 5, total_tokens: 100, quota: 300 },
|
||||
{ name: "gamma", calls: 1, total_tokens: 300, quota: 100 },
|
||||
];
|
||||
|
||||
test("sorts by the selected numeric field without mutating the source rows", () => {
|
||||
const sorted = sortDetailBreakdown(rows, "quota", false);
|
||||
|
||||
expect(sorted.map((row) => row.name)).toEqual(["beta", "alpha", "gamma"]);
|
||||
expect(rows.map((row) => row.name)).toEqual(["beta", "alpha", "gamma"]);
|
||||
});
|
||||
|
||||
test("uses name as a stable tie-breaker", () => {
|
||||
const sorted = sortDetailBreakdown(rows, "total_tokens", false);
|
||||
|
||||
expect(sorted.map((row) => row.name)).toEqual(["gamma", "alpha", "beta"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user