eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1// Collection-swipe decision logic for the lightbox (web/static/lightbox.js).
2import assert from "node:assert/strict";
3import { stepIndex, dragIntent } from "../web/static/lightbox.js";
4
5let failures = 0;
6function test(name, fn) {
7 try { fn(); console.log("PASS " + name); } catch (e) { console.log("FAIL " + name + " — " + e.message); failures++; }
8}
9
10test("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
16test("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
21test("a fast horizontal flick navigates even at small distance", () => {
22 assert.equal(dragIntent(-40, 5, -0.7, 0), "nav-next");
23});
24
25test("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
30process.exit(failures ? 1 : 0);
31