test: table-drive sandbox formatter assertions

This commit is contained in:
Peter Steinberger
2026-02-18 23:19:33 +00:00
parent c8e02329cd
commit 1a030a544b

View File

@@ -13,134 +13,116 @@ const formatAge = (ms: number) => formatDurationCompact(ms, { spaced: true }) ??
describe("sandbox-formatters", () => { describe("sandbox-formatters", () => {
describe("formatStatus", () => { describe("formatStatus", () => {
it("should format running status", () => { it.each([
expect(formatStatus(true)).toBe("🟢 running"); { running: true, expected: "🟢 running" },
}); { running: false, expected: "⚫ stopped" },
])("formats running=$running", ({ running, expected }) => {
it("should format stopped status", () => { expect(formatStatus(running)).toBe(expected);
expect(formatStatus(false)).toBe("⚫ stopped");
}); });
}); });
describe("formatSimpleStatus", () => { describe("formatSimpleStatus", () => {
it("should format running status without emoji", () => { it.each([
expect(formatSimpleStatus(true)).toBe("running"); { running: true, expected: "running" },
}); { running: false, expected: "stopped" },
])("formats running=$running without emoji", ({ running, expected }) => {
it("should format stopped status without emoji", () => { expect(formatSimpleStatus(running)).toBe(expected);
expect(formatSimpleStatus(false)).toBe("stopped");
}); });
}); });
describe("formatImageMatch", () => { describe("formatImageMatch", () => {
it("should format matching image", () => { it.each([
expect(formatImageMatch(true)).toBe("✓"); { imageMatch: true, expected: "✓" },
}); { imageMatch: false, expected: "⚠️ mismatch" },
])("formats imageMatch=$imageMatch", ({ imageMatch, expected }) => {
it("should format mismatched image", () => { expect(formatImageMatch(imageMatch)).toBe(expected);
expect(formatImageMatch(false)).toBe("⚠️ mismatch");
}); });
}); });
describe("formatAge", () => { describe("formatAge", () => {
it("should format seconds", () => { it.each([
expect(formatAge(5000)).toBe("5s"); { ms: 0, expected: "0s" },
expect(formatAge(45000)).toBe("45s"); { ms: 5000, expected: "5s" },
}); { ms: 45000, expected: "45s" },
{ ms: 60000, expected: "1m" },
it("should format minutes", () => { { ms: 90000, expected: "1m 30s" }, // 90 seconds = 1m 30s
expect(formatAge(60000)).toBe("1m"); { ms: 300000, expected: "5m" },
expect(formatAge(90000)).toBe("1m 30s"); // 90 seconds = 1m 30s { ms: 3600000, expected: "1h" },
expect(formatAge(300000)).toBe("5m"); { ms: 3660000, expected: "1h 1m" },
}); { ms: 5400000, expected: "1h 30m" },
{ ms: 7200000, expected: "2h" },
it("should format hours and minutes", () => { { ms: 86400000, expected: "1d" },
expect(formatAge(3600000)).toBe("1h"); { ms: 90000000, expected: "1d 1h" },
expect(formatAge(3660000)).toBe("1h 1m"); { ms: 172800000, expected: "2d" },
expect(formatAge(7200000)).toBe("2h"); { ms: 183600000, expected: "2d 3h" },
expect(formatAge(5400000)).toBe("1h 30m"); { ms: 59999, expected: "1m" }, // Rounds to 1 minute exactly
}); { ms: 3599999, expected: "1h" }, // Rounds to 1 hour exactly
{ ms: 86399999, expected: "1d" }, // Rounds to 1 day exactly
it("should format days and hours", () => { ])("formats $ms ms", ({ ms, expected }) => {
expect(formatAge(86400000)).toBe("1d"); expect(formatAge(ms)).toBe(expected);
expect(formatAge(90000000)).toBe("1d 1h");
expect(formatAge(172800000)).toBe("2d");
expect(formatAge(183600000)).toBe("2d 3h");
});
it("should handle zero", () => {
expect(formatAge(0)).toBe("0s");
});
it("should handle edge cases", () => {
expect(formatAge(59999)).toBe("1m"); // Rounds to 1 minute exactly
expect(formatAge(3599999)).toBe("1h"); // Rounds to 1 hour exactly
expect(formatAge(86399999)).toBe("1d"); // Rounds to 1 day exactly
}); });
}); });
describe("countRunning", () => { describe("countRunning", () => {
it("should count running items", () => { it.each([
const items = [ {
{ running: true, name: "a" }, items: [
{ running: false, name: "b" }, { running: true, name: "a" },
{ running: true, name: "c" }, { running: false, name: "b" },
{ running: false, name: "d" }, { running: true, name: "c" },
]; { running: false, name: "d" },
],
expect(countRunning(items)).toBe(2); expected: 2,
}); },
{
it("should return 0 when no items running", () => { items: [
const items = [ { running: false, name: "a" },
{ running: false, name: "a" }, { running: false, name: "b" },
{ running: false, name: "b" }, ],
]; expected: 0,
},
expect(countRunning(items)).toBe(0); {
}); items: [
{ running: true, name: "a" },
it("should count all when all running", () => { { running: true, name: "b" },
const items = [ { running: true, name: "c" },
{ running: true, name: "a" }, ],
{ running: true, name: "b" }, expected: 3,
{ running: true, name: "c" }, },
]; ])("counts running items", ({ items, expected }) => {
expect(countRunning(items)).toBe(expected);
expect(countRunning(items)).toBe(3);
}); });
}); });
describe("countMismatches", () => { describe("countMismatches", () => {
it("should count image mismatches", () => { it.each([
const items = [ {
{ imageMatch: true, name: "a" }, items: [
{ imageMatch: false, name: "b" }, { imageMatch: true, name: "a" },
{ imageMatch: true, name: "c" }, { imageMatch: false, name: "b" },
{ imageMatch: false, name: "d" }, { imageMatch: true, name: "c" },
{ imageMatch: false, name: "e" }, { imageMatch: false, name: "d" },
]; { imageMatch: false, name: "e" },
],
expect(countMismatches(items)).toBe(3); expected: 3,
}); },
{
it("should return 0 when all match", () => { items: [
const items = [ { imageMatch: true, name: "a" },
{ imageMatch: true, name: "a" }, { imageMatch: true, name: "b" },
{ imageMatch: true, name: "b" }, ],
]; expected: 0,
},
expect(countMismatches(items)).toBe(0); {
}); items: [
{ imageMatch: false, name: "a" },
it("should count all when none match", () => { { imageMatch: false, name: "b" },
const items = [ { imageMatch: false, name: "c" },
{ imageMatch: false, name: "a" }, ],
{ imageMatch: false, name: "b" }, expected: 3,
{ imageMatch: false, name: "c" }, },
]; ])("counts image mismatches", ({ items, expected }) => {
expect(countMismatches(items)).toBe(expected);
expect(countMismatches(items)).toBe(3);
}); });
}); });