feat: complete task management workflow

This commit is contained in:
2026-09-05 11:18:52 +08:00
parent f182c704a4
commit 57145c198b
17 changed files with 1514 additions and 115 deletions
+54
View File
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest'
import { filterTasks, groupTaskTree, renderMarkdown, toDateTimeLocal } from './task-utils'
type SearchTask = {
id: string
title: string
description?: string
parent_id?: string | null
completed?: boolean
tags?: { name: string }[]
list_name?: string
}
const tasks: SearchTask[] = [
{ id: '1', title: 'Write release notes', description: 'mention **API**', parent_id: null, completed: false },
{ id: '2', title: 'Check links', description: '', parent_id: '1', completed: false },
{ id: '3', title: 'Buy milk', description: '', parent_id: null, completed: true },
]
describe('task utilities', () => {
it('filters task titles and markdown descriptions case-insensitively', () => {
expect(filterTasks(tasks, 'api').map((task) => task.id)).toEqual(['1'])
expect(filterTasks(tasks, 'WRITE').map((task) => task.id)).toEqual(['1'])
})
it('keeps a one-level subtask tree without duplicating children', () => {
expect(groupTaskTree(tasks)).toEqual([{ task: tasks[0], subtasks: [tasks[1]] }, { task: tasks[2], subtasks: [] }])
})
it('renders safe basic markdown and strips unsafe html', () => {
const html = renderMarkdown('# Plan\n**bold** [link](https://example.com)\n<script>alert(1)</script>')
expect(html).toContain('<h1>Plan</h1>')
expect(html).toContain('<strong>bold</strong>')
expect(html).toContain('rel="noopener noreferrer"')
expect(html).not.toContain('<script>')
})
it('filters titles, descriptions, tags, and list names', () => {
const searchable: SearchTask[] = [
...tasks,
{ id: '4', title: 'Plan', tags: [{ name: '重要' }], list_name: '工作清单' },
]
expect(filterTasks(searchable, '重要').map((task) => task.id)).toEqual(['4'])
expect(filterTasks(searchable, '工作').map((task) => task.id)).toEqual(['4'])
})
it('formats API dates in local wall-clock time', () => {
const original = process.env.TZ
process.env.TZ = 'Asia/Shanghai'
expect(toDateTimeLocal('2026-09-05T12:30:00Z')).toBe('2026-09-05T20:30')
process.env.TZ = original
expect(toDateTimeLocal(null)).toBe('')
})
})