This commit is contained in:
@@ -1,16 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { dateKey, isTaskView, moveDueDate } from './mvp-utils'
|
||||
import { dateKey, habitWeek, isHabitComplete, isTaskView, numericHabitInputValue } from './mvp-utils'
|
||||
|
||||
describe('MVP view utilities', () => {
|
||||
it('normalizes to UTC so stored due_at stays stable in every local timezone', () => {
|
||||
const moved = moveDueDate('2026-09-05T14:30:00+08:00', '2026-09-09')
|
||||
expect(moved).toBe('2026-09-09T14:30:00.000Z')
|
||||
const newly = moveDueDate(null, '2026-09-09')
|
||||
expect(newly).toBe('2026-09-09T09:00:00.000Z')
|
||||
it('formats a local date as YYYY-MM-DD', () => {
|
||||
expect(dateKey(new Date(2026, 8, 5))).toBe('2026-09-05')
|
||||
})
|
||||
|
||||
it('returns the monday-to-sunday week containing the requested day', () => {
|
||||
expect(habitWeek(new Date(2026, 8, 5)).map(dateKey)).toEqual([
|
||||
'2026-08-31', '2026-09-01', '2026-09-02', '2026-09-03', '2026-09-04', '2026-09-05', '2026-09-06',
|
||||
])
|
||||
})
|
||||
|
||||
it('identifies only task-backed views as task data loaders', () => {
|
||||
expect(['tasks', 'today', 'upcoming'].filter(isTaskView)).toEqual(['tasks', 'today', 'upcoming'])
|
||||
expect(['calendar', 'habits', 'settings', 'trash'].filter(isTaskView)).toEqual([])
|
||||
expect(['habits', 'settings', 'trash'].filter(isTaskView)).toEqual([])
|
||||
})
|
||||
|
||||
it('only completes numeric habits when progress reaches the target', () => {
|
||||
expect(isHabitComplete('numeric', 3, 5)).toBe(false)
|
||||
expect(isHabitComplete('numeric', 5, 5)).toBe(true)
|
||||
expect(isHabitComplete('boolean', 1, 5)).toBe(true)
|
||||
})
|
||||
|
||||
it('does not invent a numeric value when the input is empty', () => {
|
||||
expect(numericHabitInputValue(undefined)).toBeNull()
|
||||
expect(numericHabitInputValue('')).toBeNull()
|
||||
expect(numericHabitInputValue(4)).toBe(4)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user