test(replay-ui): pin clampIndex step boundaries

This commit is contained in:
pj committed 2026-06-06 13:07:43 +05:30
1 parent 2702b158d8
commit f934581b58
1 file changed
+24
+24
View File
@@ -0,0 +1,24 @@
import { describe, it, expect } from "bun:test";
import { clampIndex } from "../hooks/useStep";
// Bug class: a wrong boundary lets the URL address step 0 or a step past the
// end, so the viewer requests a non-existent step and renders nothing. Steps
// are 1-based and capped at maxIndex.
describe("clampIndex", () => {
const cases: [number, number | undefined, number][] = [
[0, 5, 1],
[-3, 5, 1],
[1, 5, 1],
[3, 5, 3],
[5, 5, 5],
[6, 5, 5],
[100, 5, 5],
[3, undefined, 3],
[0, undefined, 1],
];
for (const [index, max, expected] of cases) {
it(`clamps (${index}, ${max}) -> ${expected}`, () => {
expect(clampIndex(index, max)).toBe(expected);
});
}
});