| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { collectKatexEquationLines } from './katex-lines' |
| 3 | |
| 4 | function fakeElement(options: { |
| 5 | parent?: Element | null |
| 6 | closest?: Element | null |
| 7 | children?: Element[] |
| 8 | } = {}) { |
| 9 | const el = { |
| 10 | parentElement: options.parent ?? null, |
| 11 | closest: () => options.closest ?? null, |
| 12 | querySelectorAll: () => options.children ?? [], |
| 13 | } |
| 14 | return el as unknown as Element |
| 15 | } |
| 16 | |
| 17 | describe('collectKatexEquationLines', () => { |
| 18 | it('ignores nested KaTeX tables when mapping equation lines', () => { |
| 19 | const rowA1 = fakeElement() |
| 20 | const rowA2 = fakeElement() |
| 21 | const rowB1 = fakeElement() |
| 22 | const rowB2 = fakeElement() |
| 23 | const nestedRow = fakeElement() |
| 24 | |
| 25 | const outerLeftParent = fakeElement({ children: [rowA1, rowA2] }) |
| 26 | const outerRightParent = fakeElement({ children: [rowB1, rowB2] }) |
| 27 | const nestedParent = fakeElement({ |
| 28 | parent: fakeElement({ closest: outerLeftParent }), |
| 29 | children: [nestedRow], |
| 30 | }) |
| 31 | |
| 32 | const root = fakeElement({ |
| 33 | children: [outerLeftParent, nestedParent, outerRightParent], |
| 34 | }) |
| 35 | |
| 36 | expect(collectKatexEquationLines(root)).toEqual([ |
| 37 | [rowA1, rowB1], |
| 38 | [rowA2, rowB2], |
| 39 | ]) |
| 40 | }) |
| 41 | }) |
| 42 |