| 1 | // Collection-swipe decision logic for the lightbox (web/static/lightbox.js). |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { stepIndex, dragIntent } from "../web/static/lightbox.js"; |
| 4 | |
| 5 | let failures = 0; |
| 6 | function test(name, fn) { |
| 7 | try { fn(); console.log("PASS " + name); } catch (e) { console.log("FAIL " + name + " — " + e.message); failures++; } |
| 8 | } |
| 9 | |
| 10 | test("stepIndex clamps at both ends, no wrap", () => { |
| 11 | assert.equal(stepIndex(0, -1, 5), 0); |
| 12 | assert.equal(stepIndex(4, 1, 5), 4); |
| 13 | assert.equal(stepIndex(2, 1, 5), 3); |
| 14 | }); |
| 15 | |
| 16 | test("a mostly-horizontal committed drag navigates against the drag direction", () => { |
| 17 | assert.equal(dragIntent(-120, 10, -0.8, 0), "nav-next"); // dragged left → next |
| 18 | assert.equal(dragIntent(120, -10, 0.8, 0), "nav-prev"); |
| 19 | }); |
| 20 | |
| 21 | test("a fast horizontal flick navigates even at small distance", () => { |
| 22 | assert.equal(dragIntent(-40, 5, -0.7, 0), "nav-next"); |
| 23 | }); |
| 24 | |
| 25 | test("a mostly-vertical drag still dismisses; a small slow drag settles", () => { |
| 26 | assert.equal(dragIntent(20, 200, 0, 0.9), "dismiss"); |
| 27 | assert.equal(dragIntent(10, 8, 0.01, 0.01), "settle"); |
| 28 | }); |
| 29 | |
| 30 | process.exit(failures ? 1 : 0); |
| 31 | |