import { describe, it, expect } from 'vitest'; import { zipSync, strToU8 } from 'fflate'; import { importOdt } from '../../src/lib/import/odt'; // text:display="none" — on a style it hides the paragraph, on a field it hides the // stored value. A hidden heading is the exception: it carries the outline the running // head reads, and the editor can hold it only by rendering it. const NS = 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ' + 'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ' + 'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ' + 'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"'; const styles = ` `; function odt(body: string): Uint8Array { const content = ` ${body}`; return zipSync({ 'content.xml': strToU8(content), 'styles.xml': strToU8(styles) }); } const blocks = (body: string) => importOdt(odt(body)).content.content ?? []; const textOf = (n: { content?: { text?: string }[] }) => (n.content ?? []).map((c) => c.text ?? '').join(''); describe('hidden text on ODF import', () => { it('drops the whole paragraph a style hides, not just its text', () => { const out = blocks('HiddenVisible'); expect(out.map(textOf)).toEqual(['Visible']); }); it('keeps a hidden heading, which the running head reads as the chapter', () => { const out = blocks('Chapter 1' + 'Visible'); expect(out.map(textOf)).toEqual(['Chapter 1', 'Visible']); }); it('renders nothing for a field the file marks as not displayed', () => { const out = blocks('a42b'); expect(out.map(textOf)).toEqual(['ab']); }); it('says so, rather than dropping content silently', () => { expect(importOdt(odt('x')).warnings) .toContain('Hidden text was removed'); }); });