Files
edentext/tests/schema-validation.test.ts
Steffen Becker 0d5c17a704 test: the fuzz leg draws every export option and validates each export against the schemas
tests/fuzzOptions.ts generates styles, outline numbering, sections with
zones, margins, paper and page numbering, decor, line numbering, notes and
metadata; the round trip compares per-section effective values, and what a
format has no place for is listed as lossy. The xmllint part of
schema-validation.test.ts moves to tests/schemaValidate.ts (one call per
schema) and a third leg validates every seed as ODT and DOCX. FUZZ_SEEDS
and SCHEMA_SEEDS widen the sweep.
2026-09-06 19:07:14 +02:00

36 lines
1.7 KiB
TypeScript

// The kitchen-sink exports (every feature at once) against the format schemas —
// tests/schemaValidate.ts does the work; the fuzz leg runs the same check over seeds.
import { describe, it, expect, beforeAll } from 'vitest';
import { unzipSync } from 'fflate';
import { buildOdt } from '../src/lib/export/odt';
import { buildDocx } from '../src/lib/export/docx';
import { kitchenSinkDoc, kitchenSinkSheet, kitchenSinkOptions } from './kitchenSink';
import { hasXmllint, validateOdt, validateDocx } from './schemaValidate';
describe.skipIf(!hasXmllint)('exported XML validates against the format schemas', () => {
const opts = kitchenSinkOptions();
let odt: Record<string, Uint8Array>;
let docx: Record<string, Uint8Array>;
beforeAll(async () => {
const doc = kitchenSinkDoc();
const sheet = kitchenSinkSheet();
odt = unzipSync(await buildOdt(doc, undefined, 'portrait', opts.hf, opts.language, 'A4',
sheet, undefined, 'add', false, opts.notesSettings, opts.props, true,
opts.pageNumbering, opts.decor, opts.lineNumbering, true, true));
docx = unzipSync(await buildDocx(doc, undefined, 'portrait', opts.hf, opts.language, 'A4',
sheet, undefined, 'add', false, opts.notesSettings, opts.props, true,
opts.pageNumbering, opts.decor, opts.lineNumbering, true, true));
});
it('every ODF part is schema-valid (foreign namespaces stripped, as extended conformance allows)', () => {
expect(Object.keys(odt)).toContain('content.xml');
expect(validateOdt(odt).join('\n\n')).toBe('');
});
it('every DOCX part is schema-valid after MCE resolution, as Word reads it', () => {
expect(Object.keys(docx)).toContain('word/document.xml');
expect(validateDocx(docx).join('\n\n')).toBe('');
});
});