import { test } from 'node:test'; import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const { findTasks, setTask } = require('../electron/tasks.cjs'); const links = require('../electron/links.cjs'); const page = (id, body, extra = {}) => ({ id, title: id.split('/').pop(), exists: true, parent: null, tags: [], props: {}, body, ...extra }); test('findTasks lists checklist items with due dates and tags, skipping code, boards and canvases', () => { const pages = [ page('Plan', '# Plan\n- [ ] Write spec #work 📅 2026-03-01\n - [x] Draft\n```\n- [ ] not a task\n```\n- plain\n', { tags: ['proj'] }), page('Board', '## Todo\n- [ ] card', { props: { 'kanban-plugin': 'basic' } }), page('Map.canvas', '- [ ] x', { kind: 'canvas' }) ]; const t = findTasks(pages); assert.equal(t.length, 2); assert.deepEqual({ ...t[0], tags: [...t[0].tags].sort() }, { id: 'Plan', title: 'Plan', icon: null, line: 1, done: false, text: 'Write spec #work 📅 2026-03-01', due: '2026-03-01', tags: ['proj', 'work'], depth: 0 }); assert.equal(t[1].done, true); assert.equal(t[1].depth, 1); }); test('setTask ticks the line, and refuses when the line changed', () => { const body = 'a\n- [ ] one\n- [x] two\n'; assert.equal(setTask(body, 1, 'one', true), 'a\n- [x] one\n- [x] two\n'); assert.equal(setTask(body, 2, 'two', false), 'a\n- [ ] one\n- [ ] two\n'); assert.equal(setTask(body, 1, 'other', true), null); assert.equal(setTask(body, 0, 'a', true), null); }); test('unlinked finds plain mentions and ignores links, code and URLs', () => { const pages = [ page('Roadmap', 'Plan the Roadmap'), page('A', 'We should read the roadmap soon.'), page('B', 'Already [[Roadmap]] linked, roadmap again.'), page('C', '`roadmap` and https://x.test/roadmap and [roadmap](y)'), page('D', 'roadmaps are not it') ]; assert.deepEqual(links.unlinked('Roadmap', pages).map((p) => p.id), ['A']); }); test('linkFirstMention links only the first mention and keeps what was written', () => { const pages = [page('Roadmap', ''), page('A', '')]; assert.equal(links.linkFirstMention('see the roadmap, the Roadmap', 'Roadmap', pages), 'see the [[Roadmap|roadmap]], the Roadmap'); assert.equal(links.linkFirstMention('Roadmap here', 'Roadmap', pages), '[[Roadmap]] here'); assert.equal(links.linkFirstMention('nothing', 'Roadmap', pages), null); });