refactor: share sampled entry summary formatting

This commit is contained in:
Peter Steinberger
2026-03-08 00:03:02 +00:00
parent cc03c097c5
commit 990fc36cbd
5 changed files with 77 additions and 28 deletions

View File

@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { summarizeStringEntries } from "./string-sample.js";
describe("summarizeStringEntries", () => {
it("returns emptyText for empty lists", () => {
expect(summarizeStringEntries({ entries: [], emptyText: "any" })).toBe("any");
});
it("joins short lists without a suffix", () => {
expect(summarizeStringEntries({ entries: ["a", "b"], limit: 4 })).toBe("a, b");
});
it("adds a remainder suffix when truncating", () => {
expect(
summarizeStringEntries({
entries: ["a", "b", "c", "d", "e"],
limit: 4,
}),
).toBe("a, b, c, d (+1)");
});
});