This commit is contained in:
@@ -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('就是今天')
|
||||
|
||||
@@ -115,6 +115,7 @@ export function isFabDrag(deltaX: number, deltaY: number, threshold = 8) {
|
||||
}
|
||||
|
||||
let habitGridCache: { week: string; habits: unknown[] } | null = null
|
||||
let countdownCache: { items: unknown[]; archived: unknown[] } | null = null
|
||||
|
||||
export function readHabitGridCache<T>(week: string): T[] | null {
|
||||
return habitGridCache?.week === week ? habitGridCache.habits as T[] : null
|
||||
@@ -124,6 +125,14 @@ export function writeHabitGridCache<T>(week: string, habits: T[]) {
|
||||
habitGridCache = { week, habits }
|
||||
}
|
||||
|
||||
export function readCountdownCache<T>() {
|
||||
return countdownCache as { items: T[]; archived: T[] } | null
|
||||
}
|
||||
|
||||
export function writeCountdownCache<T>(items: T[], archived: T[]) {
|
||||
countdownCache = { items, archived }
|
||||
}
|
||||
|
||||
export function formatApiErrorDetail(detail: unknown): string {
|
||||
if (typeof detail === 'string') return detail
|
||||
if (Array.isArray(detail)) {
|
||||
|
||||
Reference in New Issue
Block a user