import test from "node:test"; import assert from "node:assert/strict"; import { settleDuration, swipeStep } from "../shared/navigation.js"; test("phone swipes accept deliberate travel and short fast flicks in both directions", () => { assert.equal(swipeStep(-100, 8, 500, 393), 1); assert.equal(swipeStep(100, -8, 500, 393), -1); assert.equal(swipeStep(-40, 2, 65, 393), 1); assert.equal(swipeStep(60, 0, 500, 320), -1); }); test("scrolling, diagonal travel, slow small movements and jitter never switch tabs", () => { assert.equal(swipeStep(12, 150, 250, 393), 0); assert.equal(swipeStep(100, 100, 150, 393), 0); assert.equal(swipeStep(40, 2, 500, 393), 0); assert.equal(swipeStep(8, 0, 5, 393), 0); }); test("a released swipe settles at the finger's speed, within natural bounds", () => { // Tab taps and slow releases use a distance-based duration. assert.equal(settleDuration(-393, 393), 340); assert.equal(settleDuration(-60, 393), 220); // A fast flick toward the destination shortens the settle so it starts at // the release velocity: 3.2 * 200px / 4px/ms = 160ms. assert.equal(settleDuration(-200, 393, -4), 160); // A gentle release never stretches the settle beyond the base duration. assert.equal(settleDuration(-250, 393, -2), 220); // Momentum away from the destination (a cancelled swipe) is ignored. assert.equal(settleDuration(150, 393, -3), Math.max(220, 340 * (150 / 393))); // Extremely fast flicks are clamped so the settle stays visible. assert.equal(settleDuration(-300, 393, -20), 160); });