This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { dateKey, defaultView, habitWeek, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, numericHabitInputValue, previousHabitSwipeValue, shouldToggleRowSwipe } from './mvp-utils'
|
||||
import { dateKey, defaultView, habitWeek, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, shouldToggleRowSwipe } from './mvp-utils'
|
||||
|
||||
describe('MVP view utilities', () => {
|
||||
it('formats a local date as YYYY-MM-DD', () => {
|
||||
@@ -33,6 +33,20 @@ describe('MVP view utilities', () => {
|
||||
expect(defaultView()).toBe('today')
|
||||
})
|
||||
|
||||
it('quick-adds Today tasks to Inbox at noon in Asia/Shanghai', () => {
|
||||
const now = new Date('2026-09-05T16:30:00.000Z')
|
||||
expect(quickTaskFields('today', 'selected-list', 'inbox-list', now)).toEqual({
|
||||
list_id: 'inbox-list',
|
||||
due_at: '2026-09-06T12:00:00+08:00',
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps quick-add tasks in the selected list outside Today', () => {
|
||||
expect(quickTaskFields('tasks', 'selected-list', 'inbox-list', new Date('2026-09-05T16:30:00.000Z'))).toEqual({
|
||||
list_id: 'selected-list',
|
||||
})
|
||||
})
|
||||
|
||||
it('only includes scheduled, unpaused habits today regardless of kind or completion', () => {
|
||||
const day = '2026-09-06'
|
||||
expect(isHabitScheduledToday({ kind: 'boolean', cells: [{ day, scheduled: true, paused: false, value: true }] }, day)).toBe(true)
|
||||
|
||||
@@ -28,6 +28,21 @@ export function defaultView() {
|
||||
return 'today' as const
|
||||
}
|
||||
|
||||
export function quickTaskFields(view: string, activeList: string, inboxList: string, now = new Date()) {
|
||||
if (view !== 'today') return { list_id: activeList }
|
||||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}).formatToParts(now)
|
||||
const value = (type: Intl.DateTimeFormatPartTypes) => parts.find((part) => part.type === type)?.value
|
||||
return {
|
||||
list_id: inboxList,
|
||||
due_at: `${value('year')}-${value('month')}-${value('day')}T12:00:00+08:00`,
|
||||
}
|
||||
}
|
||||
|
||||
export function isHabitComplete(kind: string | undefined, value: number | boolean | undefined, target = 1) {
|
||||
if (kind === 'numeric') return Number(value ?? 0) >= target
|
||||
return Boolean(value)
|
||||
|
||||
@@ -7,7 +7,6 @@ type SearchTask = {
|
||||
description?: string
|
||||
parent_id?: string | null
|
||||
completed?: boolean
|
||||
tags?: { name: string }[]
|
||||
list_name?: string
|
||||
}
|
||||
|
||||
@@ -35,12 +34,11 @@ describe('task utilities', () => {
|
||||
expect(html).not.toContain('<script>')
|
||||
})
|
||||
|
||||
it('filters titles, descriptions, tags, and list names', () => {
|
||||
it('filters titles, descriptions, and list names', () => {
|
||||
const searchable: SearchTask[] = [
|
||||
...tasks,
|
||||
{ id: '4', title: 'Plan', tags: [{ name: '重要' }], list_name: '工作清单' },
|
||||
{ id: '4', title: 'Plan', list_name: '工作清单' },
|
||||
]
|
||||
expect(filterTasks(searchable, '重要').map((task) => task.id)).toEqual(['4'])
|
||||
expect(filterTasks(searchable, '工作').map((task) => task.id)).toEqual(['4'])
|
||||
})
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ export type MinimalTask = {
|
||||
description?: string
|
||||
parent_id?: string | null
|
||||
completed?: boolean
|
||||
tags?: { name: string }[]
|
||||
list_name?: string
|
||||
}
|
||||
|
||||
@@ -75,7 +74,6 @@ export function filterTasks<T extends MinimalTask>(tasks: T[], query: string) {
|
||||
task.title,
|
||||
task.description ?? '',
|
||||
task.list_name ?? '',
|
||||
...(task.tags ?? []).map((tag) => tag.name),
|
||||
].join(' ')
|
||||
return haystack.toLowerCase().includes(q)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user