3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-12 19:58:28 +01:00
Files
adf-codec/src/markdown/portable/task-list.test.ts
T

24 lines
1.2 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import type { AdfNode } from '../../adf/document.ts'
import { pathTo, splitTaskList } from './task-list.ts'
test('names the steps from a block to a node deep in it', () => {
const target: AdfNode = { text: 'x', type: 'text' }
const blocks: AdfNode[] = [{ type: 'rule' }, { content: [{ content: [{ type: 'paragraph' }, { content: [target], type: 'paragraph' }], type: 'blockquote' }], type: 'panel' }]
assert.deepEqual(pathTo(blocks, target), [1, 'content', 0, 'content', 1, 'content', 0])
assert.deepEqual(pathTo(blocks, blocks[0] ?? target), [0])
})
test('names no steps to a node the blocks do not hold', () => {
assert.equal(pathTo([{ content: [{ text: 'x', type: 'text' }], type: 'paragraph' }], { text: 'x', type: 'text' }), undefined)
})
test('keeps the inline nodes of a lone paragraph in the taskItem it becomes, so pathTo still finds them', () => {
const inline: AdfNode = { text: 'x', type: 'text' }
const item: AdfNode = { attrs: { state: 'TODO' }, content: [{ content: [inline], type: 'paragraph' }], type: 'blockTaskItem' }
const blocks = splitTaskList({ content: [item], type: 'taskList' })
assert.deepEqual(pathTo(blocks, inline), [0, 'content', 0, 'content', 0])
})