import { describe, it, expect } from 'vitest'; import { DocxStyles } from '../../src/lib/import/docxStyles'; const W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'; // Word's "Normal" (here LibreOffice's German "Standard"): the w:default="1" paragraph // style carries the real body font, while docDefaults still says Times New Roman. const STYLES = ` `; const styles = () => new DocxStyles(new DOMParser().parseFromString(STYLES, 'application/xml'), null); describe('DocxStyles.paragraphRun', () => { it('applies the default paragraph style to a paragraph with no w:pStyle', () => { expect(styles().paragraphRun(null)).toMatchObject({ font: 'Arial', sizeHalfPt: 22 }); }); it('resolves a pStyle through its basedOn chain to the default style', () => { expect(styles().paragraphRun('Listenabsatz')).toMatchObject({ font: 'Arial', sizeHalfPt: 22 }); }); it("lets a pStyle's own font win over the default style", () => { expect(styles().paragraphRun('Quote').font).toBe('Georgia'); }); it('falls back to docDefaults when there is no default paragraph style', () => { const bare = ` `; const s = new DocxStyles(new DOMParser().parseFromString(bare, 'application/xml'), null); expect(s.paragraphRun(null).font).toBe('Times New Roman'); }); }); describe('DocxStyles.paragraphSpacing', () => { it('is empty when no layer sets spacing (Word implies 0)', () => { expect(styles().paragraphSpacing(null)).toEqual({}); }); it("reads modern Word's docDefaults spacing", () => { const modern = ` `; const s = new DocxStyles(new DOMParser().parseFromString(modern, 'application/xml'), null); expect(s.paragraphSpacing(null)).toMatchObject({ after: 160, line: 259 }); expect(s.paragraphSpacing('NoSpacing')).toMatchObject({ after: 0, line: 240 }); }); });