23 lines
1.7 KiB
JavaScript
23 lines
1.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { selectTasks } from '../src/query.ts';
|
|
import { summarizeTasks } from '../src/summary.ts';
|
|
import { toggleTask } from '../src/transition.ts';
|
|
const tasks = [
|
|
{ id: 'api', title: '编写接口', done: false, hours: 3 },
|
|
{ id: 'review', title: '验证交互', done: true, hours: 2 },
|
|
{ id: 'tests', title: '完成测试', done: false, hours: 5 },
|
|
];
|
|
test('the all filter preserves all tasks', () => assert.deepEqual(selectTasks(tasks, 'all', ''), tasks));
|
|
test('pending shows only pending tasks', () => assert.deepEqual(selectTasks(tasks, 'pending', '').map(task => task.id), ['api','tests']));
|
|
test('done shows only completed tasks', () => assert.deepEqual(selectTasks(tasks, 'done', '').map(task => task.id), ['review']));
|
|
test('search combines the selected state with trimmed text', () => assert.deepEqual(selectTasks(tasks, 'done', ' 验证 ').map(task => task.id), ['review']));
|
|
test('unmatched search returns an empty list', () => assert.equal(selectTasks(tasks, 'all', '不存在').length, 0));
|
|
test('actual totals use completion states and pending hours', () => assert.deepEqual(summarizeTasks(tasks), { total: 3, completed: 1, pendingHours: 8 }));
|
|
test('toggle changes only the selected task and keeps the input intact', () => {
|
|
const original = structuredClone(tasks), changed = toggleTask(tasks, 'api');
|
|
assert.deepEqual(changed.map(task => task.done), [true,true,false]); assert.deepEqual(tasks, original);
|
|
});
|
|
test('two toggles restore the selected task', () => assert.deepEqual(toggleTask(toggleTask(tasks, 'review'), 'review'), tasks));
|
|
test('an unknown identity preserves the tasks', () => assert.deepEqual(toggleTask(tasks, 'unknown'), tasks));
|