Files
cinny/src/app/hooks/useSwipeNav.test.ts
T
jaredandClaude Opus 5 cf80729a5c
CI / Build & Quality Checks (push) Successful in 1m29s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 6s
CI / Trigger Desktop Build (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s
feat(media): swipe between items in the full-screen viewer (#164)
Touch had no way to move between images except the small arrow buttons.
A one-finger horizontal swipe now goes next/previous, and is inert while
the image is zoomed in (where the same gesture pans). The classifier is
pure and unit-tested: ≥ 60 px horizontal, not mostly vertical, under
800 ms, single finger.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
2026-09-23 15:20:22 -04:00

24 lines
904 B
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { classifySwipe } from './useSwipeNav';
const start = { x: 300, y: 200, t: 1_000 };
const at = (x: number, y: number) => ({ x, y });
describe('classifySwipe', () => {
it('left is next, right is prev', () => {
assert.equal(classifySwipe(start, at(100, 210), 1_200), 'next');
assert.equal(classifySwipe({ ...start, x: 100 }, at(300, 190), 1_200), 'prev');
});
it('ignores short, too-vertical and too-slow gestures', () => {
assert.equal(classifySwipe(start, at(260, 200), 1_200), undefined);
assert.equal(classifySwipe(start, at(100, 400), 1_200), undefined);
assert.equal(classifySwipe(start, at(100, 200), 2_500), undefined);
});
it('allows a little vertical drift on a long horizontal swipe', () => {
assert.equal(classifySwipe(start, at(60, 340), 1_300), 'next');
});
});