import { describe, expect, it } from 'vitest' import { filterTasks, groupTaskTree, moveItemWithinScope, renderMarkdown, toDateTimeLocal } from './task-utils' type SearchTask = { id: string title: string description?: string parent_id?: string | null completed?: boolean 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('moves an item before or after another item without changing other scopes', () => { const rows = [ { id: 'a', parent_id: null }, { id: 'a1', parent_id: 'a' }, { id: 'b', parent_id: null }, { id: 'c', parent_id: null }, ] expect(moveItemWithinScope(rows, 'c', 'a', 'before').map((row) => row.id)).toEqual(['c', 'a1', 'a', 'b']) expect(moveItemWithinScope(rows, 'a', 'c', 'after').map((row) => row.id)).toEqual(['b', 'a1', 'c', 'a']) expect(moveItemWithinScope(rows, 'a1', 'b', 'before')).toEqual(rows) }) it('renders safe basic markdown and strips unsafe html', () => { const html = renderMarkdown('# Plan\n**bold** [link](https://example.com)\n') expect(html).toContain('

Plan

') expect(html).toContain('bold') expect(html).toContain('rel="noopener noreferrer"') expect(html).not.toContain('