test: tighten shared singleton and sample coverage

This commit is contained in:
Peter Steinberger
2026-03-13 21:25:20 +00:00
parent 42ccee658d
commit 0c79c86b40
2 changed files with 40 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import { summarizeStringEntries } from "./string-sample.js";
describe("summarizeStringEntries", () => {
it("returns emptyText for empty lists", () => {
expect(summarizeStringEntries({ entries: [], emptyText: "any" })).toBe("any");
expect(summarizeStringEntries({ entries: null })).toBe("");
});
it("joins short lists without a suffix", () => {
@@ -18,4 +19,27 @@ describe("summarizeStringEntries", () => {
}),
).toBe("a, b, c, d (+1)");
});
it("uses a floored limit and clamps non-positive values to one entry", () => {
expect(
summarizeStringEntries({
entries: ["a", "b", "c"],
limit: 2.8,
}),
).toBe("a, b (+1)");
expect(
summarizeStringEntries({
entries: ["a", "b", "c"],
limit: 0,
}),
).toBe("a (+2)");
});
it("uses the default limit when none is provided", () => {
expect(
summarizeStringEntries({
entries: ["a", "b", "c", "d", "e", "f", "g"],
}),
).toBe("a, b, c, d, e, f (+1)");
});
});