|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { limitTodos, todoKey } from '../src/core/todoUtils'; |
| 3 | +import { TodoItem } from '../src/parser/types'; |
| 4 | + |
| 5 | + |
| 6 | +describe('limitTodos', () => { |
| 7 | + it('filters out invalid todos and limits the result', () => { |
| 8 | + const todos: TodoItem[] = [ |
| 9 | + { tag: 'TODO', text: 'short', file: 'a.ts', line: 1 }, |
| 10 | + { tag: 'FIXME', text: 'Fix the login', file: 'b.ts', line: 2 }, |
| 11 | + { tag: 'TODO', text: 'Refactor component', file: 'c.ts', line: 3 }, |
| 12 | + { tag: 'BUG', text: 'Another fix', file: 'd.ts', line: 4 }, |
| 13 | + ]; |
| 14 | + |
| 15 | + const limited = limitTodos(todos, 2); |
| 16 | + |
| 17 | + expect(limited.length).toBe(2); |
| 18 | + expect(limited[0].text).toBe('Fix the login'); |
| 19 | + expect(limited[1].text).toBe('Refactor component'); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('todoKey', () => { |
| 24 | + it('can be used to remove duplicate todos before limiting', () => { |
| 25 | + const todos: TodoItem[] = [ |
| 26 | + { tag: 'TODO', text: 'duplicate task', file: 'a.ts', line: 1 }, |
| 27 | + { tag: 'TODO', text: 'duplicate task', file: 'b.ts', line: 2 }, |
| 28 | + { tag: 'TODO', text: 'unique task', file: 'c.ts', line: 3 }, |
| 29 | + ]; |
| 30 | + |
| 31 | + const seen = new Set<string>(); |
| 32 | + const unique = todos.filter(t => { |
| 33 | + const key = todoKey(t); |
| 34 | + if (seen.has(key)) return false; |
| 35 | + seen.add(key); |
| 36 | + return true; |
| 37 | + }); |
| 38 | + |
| 39 | + const result = limitTodos(unique, 5); |
| 40 | + |
| 41 | + expect(result.length).toBe(2); |
| 42 | + expect(result.map(t => t.text)).toEqual(['duplicate task', 'unique task']); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
0 commit comments