This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue } from './mvp-utils'
|
||||
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue, shouldToggleHabitSwipe } from './mvp-utils'
|
||||
|
||||
describe('MVP view utilities', () => {
|
||||
it('formats a local date as YYYY-MM-DD', () => {
|
||||
@@ -28,4 +28,11 @@ describe('MVP view utilities', () => {
|
||||
expect(numericHabitInputValue('')).toBeNull()
|
||||
expect(numericHabitInputValue(4)).toBe(4)
|
||||
})
|
||||
|
||||
it('toggles a habit only for a deliberate horizontal swipe', () => {
|
||||
expect(shouldToggleHabitSwipe(78, 8)).toBe(true)
|
||||
expect(shouldToggleHabitSwipe(-78, 8)).toBe(false)
|
||||
expect(shouldToggleHabitSwipe(30, 2)).toBe(false)
|
||||
expect(shouldToggleHabitSwipe(80, 35)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,3 +34,7 @@ export function numericHabitInputValue(input: number | string | undefined) {
|
||||
const value = Number(input)
|
||||
return Number.isFinite(value) && value >= 0 ? value : null
|
||||
}
|
||||
|
||||
export function shouldToggleHabitSwipe(deltaX: number, deltaY: number) {
|
||||
return deltaX >= 64 && Math.abs(deltaY) <= 24 && deltaX > Math.abs(deltaY) * 1.5
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user