fix: persist completed item visibility
ci / gitleaks (push) Successful in 18s
ci / docker (push) Successful in 3m49s

This commit is contained in:
2026-09-08 11:24:39 +08:00
parent 356fbfa942
commit 798725ad29
5 changed files with 47 additions and 8 deletions
+14 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { calendarModeLabel, clampFabPosition, countdownDayText, countdownKindLabel, dateKey, defaultView, habitButtonNotice, habitButtonValue, habitWeek, isFabDrag, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, nextTotalAfterLocalTaskAdd, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, readCountdownCache, readHabitGridCache, shouldToggleRowSwipe, writeCountdownCache, writeHabitGridCache } from './mvp-utils'
import { calendarModeLabel, clampFabPosition, countdownDayText, countdownKindLabel, dateKey, defaultView, habitButtonNotice, habitButtonValue, habitWeek, isFabDrag, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, nextTotalAfterLocalTaskAdd, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, readCountdownCache, readHabitGridCache, readStoredBoolean, shouldToggleRowSwipe, writeCountdownCache, writeHabitGridCache, writeStoredBoolean } from './mvp-utils'
describe('MVP view utilities', () => {
it('formats a local date as YYYY-MM-DD', () => {
@@ -77,6 +77,19 @@ describe('MVP view utilities', () => {
expect(habitButtonNotice('boolean', 1, 0)).toBe('已取消完成')
})
it('persists boolean display preferences across page refreshes', () => {
const storage = new Map<string, string>()
const fakeStorage = {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
}
expect(readStoredBoolean(fakeStorage, 'dodo.show-completed', true)).toBe(true)
writeStoredBoolean(fakeStorage, 'dodo.show-completed', false)
expect(readStoredBoolean(fakeStorage, 'dodo.show-completed', true)).toBe(false)
storage.set('dodo.show-completed', 'invalid')
expect(readStoredBoolean(fakeStorage, 'dodo.show-completed', true)).toBe(true)
})
it('reuses the current week habit grid while refreshing in the background', () => {
const habits = [{ id: 'habit-1', name: '喝水' }]
writeHabitGridCache('2026-09-07', habits)