src/features/reports/progress-sort.test.ts
Linked repository file from this build.
import { expect, test } from "bun:test";
import {
nextCountyChartSort,
nextMonthChartSort,
sortCountyGroups,
sortMonthGroups,
} from "./progress-sort";
const groups = [
{ key: "2025-10", label: "October 2025", total: 100, completed: 100, error: 0 },
{ key: "2026-06", label: "June 2026", total: 100, completed: 30, error: 10 },
{ key: "2026-09", label: "September 2026", total: 100, completed: 0, error: 4 },
{ key: "2026-01", label: "January 2026", total: 100, completed: 100, error: 0 },
];
const counties = [
{ key: "02", label: "Allegheny", total: 18, completed: 10, error: 11 },
{ key: "01", label: "Adams", total: 16, completed: 8, error: 5 },
{ key: "15", label: "Chester", total: 15, completed: 9, error: 8 },
{ key: "51", label: "Philadelphia", total: 18, completed: 12, error: 4 },
];
test("sample month sort button walks newest, oldest, then completeness", () => {
expect(nextMonthChartSort("newest")).toBe("oldest");
expect(nextMonthChartSort("oldest")).toBe("least-complete");
expect(nextMonthChartSort("least-complete")).toBe("most-complete");
expect(nextMonthChartSort("most-complete")).toBe("newest");
});
test("sample month sorts keep chronological ties on completeness", () => {
expect(sortMonthGroups(groups, "newest").map((group) => group.key)).toEqual([
"2026-09",
"2026-06",
"2026-01",
"2025-10",
]);
expect(sortMonthGroups(groups, "oldest").map((group) => group.key)).toEqual([
"2025-10",
"2026-01",
"2026-06",
"2026-09",
]);
expect(sortMonthGroups(groups, "least-complete").map((group) => group.key)).toEqual([
"2026-09",
"2026-06",
"2026-01",
"2025-10",
]);
expect(sortMonthGroups(groups, "most-complete").map((group) => group.key)).toEqual([
"2025-10",
"2026-01",
"2026-06",
"2026-09",
]);
});
test("county sort button walks name, totals, then error counts", () => {
expect(nextCountyChartSort("name-asc")).toBe("name-desc");
expect(nextCountyChartSort("name-desc")).toBe("total-asc");
expect(nextCountyChartSort("total-asc")).toBe("total-desc");
expect(nextCountyChartSort("total-desc")).toBe("error-asc");
expect(nextCountyChartSort("error-asc")).toBe("error-desc");
expect(nextCountyChartSort("error-desc")).toBe("name-asc");
});
test("county sorts use name as the tie-break on counts", () => {
expect(sortCountyGroups(counties, "name-asc").map((group) => group.label)).toEqual([
"Adams",
"Allegheny",
"Chester",
"Philadelphia",
]);
expect(sortCountyGroups(counties, "name-desc").map((group) => group.label)).toEqual([
"Philadelphia",
"Chester",
"Allegheny",
"Adams",
]);
expect(sortCountyGroups(counties, "total-asc").map((group) => group.label)).toEqual([
"Chester",
"Adams",
"Allegheny",
"Philadelphia",
]);
expect(sortCountyGroups(counties, "total-desc").map((group) => group.label)).toEqual([
"Allegheny",
"Philadelphia",
"Adams",
"Chester",
]);
expect(sortCountyGroups(counties, "error-asc").map((group) => group.label)).toEqual([
"Philadelphia",
"Adams",
"Chester",
"Allegheny",
]);
expect(sortCountyGroups(counties, "error-desc").map((group) => group.label)).toEqual([
"Allegheny",
"Chester",
"Adams",
"Philadelphia",
]);
});