fix: land on today and swipe count habits incrementally
ci / docker (push) Successful in 3m16s

This commit is contained in:
2026-09-06 10:44:06 +08:00
parent cc98bc53e9
commit 4c93d0e1f8
7 changed files with 90 additions and 51 deletions
+15 -3
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue, shouldToggleRowSwipe } from './mvp-utils'
import { dateKey, defaultView, habitWeek, isHabitComplete, isTaskView, nextHabitSwipeValue, numericHabitInputValue, previousHabitSwipeValue, shouldToggleRowSwipe } from './mvp-utils'
describe('MVP view utilities', () => {
it('formats a local date as YYYY-MM-DD', () => {
@@ -29,10 +29,22 @@ describe('MVP view utilities', () => {
expect(numericHabitInputValue(4)).toBe(4)
})
it('toggles a row only for a deliberate right swipe', () => {
it('uses today as the default landing view', () => {
expect(defaultView()).toBe('today')
})
it('increments count habits one swipe at a time and caps at target', () => {
expect(nextHabitSwipeValue('numeric', 2, 5)).toBe(3)
expect(nextHabitSwipeValue('numeric', 5, 5)).toBe(5)
expect(previousHabitSwipeValue('numeric', 3)).toBe(2)
expect(previousHabitSwipeValue('numeric', 0)).toBe(0)
})
it('toggles a row for a deliberate mostly-horizontal swipe', () => {
expect(shouldToggleRowSwipe(78, 8)).toBe(true)
expect(shouldToggleRowSwipe(88, 28)).toBe(true)
expect(shouldToggleRowSwipe(-78, 8)).toBe(false)
expect(shouldToggleRowSwipe(30, 2)).toBe(false)
expect(shouldToggleRowSwipe(80, 35)).toBe(false)
expect(shouldToggleRowSwipe(80, 60)).toBe(false)
})
})