perf: preload and cache countdowns
ci / docker (push) Successful in 3m49s

This commit is contained in:
2026-09-07 17:50:26 +08:00
parent 635930db50
commit a02b6f660c
6 changed files with 64 additions and 5 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { calendarModeLabel, clampFabPosition, countdownDayText, countdownKindLabel, dateKey, defaultView, habitButtonValue, habitWeek, isFabDrag, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, nextTotalAfterLocalTaskAdd, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, readHabitGridCache, shouldToggleRowSwipe, writeHabitGridCache } from './mvp-utils'
import { calendarModeLabel, clampFabPosition, countdownDayText, countdownKindLabel, dateKey, defaultView, habitButtonValue, habitWeek, isFabDrag, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, nextTotalAfterLocalTaskAdd, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, readCountdownCache, readHabitGridCache, shouldToggleRowSwipe, writeCountdownCache, writeHabitGridCache } from './mvp-utils'
describe('MVP view utilities', () => {
it('formats a local date as YYYY-MM-DD', () => {
@@ -77,6 +77,13 @@ describe('MVP view utilities', () => {
expect(readHabitGridCache('2026-09-14')).toBeNull()
})
it('reuses countdown data while the page refreshes in the background', () => {
const active = [{ id: 'countdown-1', title: '旅行' }]
const archived = [{ id: 'countdown-2', title: '旧日期' }]
writeCountdownCache(active, archived)
expect(readCountdownCache()).toEqual({ items: active, archived })
})
it('renders countdown labels from date-only day values', () => {
expect(countdownDayText(8)).toBe('还有 8 天')
expect(countdownDayText(0)).toBe('就是今天')