import { describe, expect, it } from 'vitest'
import { parseDocx } from '../src/index'
import { buildDocx } from './helpers/build-docx'
const XML_DECL = '\r\n'
const MULTILEVEL_NUMBERING =
XML_DECL +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'' +
''
describe('numbering definitions (word/numbering.xml)', () => {
it('parses per-level numFmt / lvlText / start and lvlOverrides', async () => {
const bytes = await buildDocx({
bodyXml: 'x',
numberingXml: MULTILEVEL_NUMBERING,
})
const doc = await parseDocx(bytes)
const num1 = doc.numbering.get('1')!
expect(num1.abstractNumId).toBe('0')
expect(num1.levels[0]).toEqual({ numFmt: 'decimal', lvlText: '%1.', start: 1 })
expect(num1.levels[1]).toEqual({ numFmt: 'decimal', lvlText: '%1.%2', start: 1 })
expect(num1.levels[2]).toEqual({ numFmt: 'lowerLetter', lvlText: '%3)', start: 3 })
expect(num1.startOverrides).toEqual({})
const num2 = doc.numbering.get('2')!
expect(num2.startOverrides).toEqual({ 0: 1 })
// A full w:lvl inside lvlOverride replaces that level's definition; other levels
// follow the abstractNum
expect(num2.levels[1]).toEqual({ numFmt: 'upperRoman', lvlText: '%2:', start: 5 })
expect(num2.levels[0]).toEqual({ numFmt: 'decimal', lvlText: '%1.', start: 1 })
})
it('keeps the bullet/ordered classification for list blocks', async () => {
const bytes = await buildDocx({
bodyXml:
'a' +
'b',
withNumbering: true,
})
const doc = await parseDocx(bytes)
expect(doc.blocks[0].list?.kind).toBe('bullet')
expect(doc.blocks[1].list?.kind).toBe('ordered')
expect(doc.numbering.get('2')?.levels[0]?.lvlText).toBe('%1.')
})
})