|
1 | 1 | import { describe, expect, test } from 'vitest' |
| 2 | +import { isDoubleTap } from '../src/gestures/double-tap' |
2 | 3 | import { createGestureLock, resetLock, tryLock } from '../src/gestures/lock' |
3 | 4 | import { clampFontSize, touchDistance } from '../src/gestures/pinch' |
4 | 5 | import { |
@@ -291,6 +292,51 @@ describe('touchToCell', () => { |
291 | 292 | }) |
292 | 293 | }) |
293 | 294 |
|
| 295 | +describe('isDoubleTap', () => { |
| 296 | + const maxInterval = 300 |
| 297 | + const maxDistance = 50 |
| 298 | + |
| 299 | + test('within interval and distance returns true', () => { |
| 300 | + expect(isDoubleTap(200, 30, maxInterval, maxDistance)).toBe(true) |
| 301 | + }) |
| 302 | + |
| 303 | + test('exceeds interval returns false', () => { |
| 304 | + expect(isDoubleTap(400, 30, maxInterval, maxDistance)).toBe(false) |
| 305 | + }) |
| 306 | + |
| 307 | + test('zero dt (simultaneous) returns false', () => { |
| 308 | + expect(isDoubleTap(0, 10, maxInterval, maxDistance)).toBe(false) |
| 309 | + }) |
| 310 | + |
| 311 | + test('exact interval boundary returns true', () => { |
| 312 | + expect(isDoubleTap(300, 30, maxInterval, maxDistance)).toBe(true) |
| 313 | + }) |
| 314 | + |
| 315 | + test('negative dt returns false', () => { |
| 316 | + expect(isDoubleTap(-100, 10, maxInterval, maxDistance)).toBe(false) |
| 317 | + }) |
| 318 | + |
| 319 | + test('within distance returns true', () => { |
| 320 | + expect(isDoubleTap(200, 49, maxInterval, maxDistance)).toBe(true) |
| 321 | + }) |
| 322 | + |
| 323 | + test('exceeds distance returns false', () => { |
| 324 | + expect(isDoubleTap(200, 60, maxInterval, maxDistance)).toBe(false) |
| 325 | + }) |
| 326 | + |
| 327 | + test('exact distance boundary returns true', () => { |
| 328 | + expect(isDoubleTap(200, 50, maxInterval, maxDistance)).toBe(true) |
| 329 | + }) |
| 330 | + |
| 331 | + test('within time but too far apart returns false', () => { |
| 332 | + expect(isDoubleTap(100, 80, maxInterval, maxDistance)).toBe(false) |
| 333 | + }) |
| 334 | + |
| 335 | + test('close enough but too slow returns false', () => { |
| 336 | + expect(isDoubleTap(500, 10, maxInterval, maxDistance)).toBe(false) |
| 337 | + }) |
| 338 | +}) |
| 339 | + |
294 | 340 | describe('resolveScrollAction', () => { |
295 | 341 | test('keys strategy returns pageSeq for up', () => { |
296 | 342 | const action = resolveScrollAction('up', 'keys', { x: 1, y: 1 }, 0, 1000, 50) |
|
0 commit comments