Skip to content

Build your personal knowledge base with Trilium Notes

test(ocr): extend real Office extraction coverage to PPTX and ODP

Elian Doranbde64a33feb9
diff --git a/apps/server/src/services/ocr/processors/office_processor.integration.spec.ts b/apps/server/src/services/ocr/processors/office_processor.integration.spec.ts
index 1c5e593ca5..a5815430f6 100644
--- a/apps/server/src/services/ocr/processors/office_processor.integration.spec.ts
+++ b/apps/server/src/services/ocr/processors/office_processor.integration.spec.ts
@@ -20,13 +20,25 @@ vi.mock('@triliumnext/core', async (importOriginal) => {
let OfficeProcessor: typeof import('./office_processor.js').OfficeProcessor;
const DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
+const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
const ODT = 'application/vnd.oasis.opendocument.text';
+const ODP = 'application/vnd.oasis.opendocument.presentation';
const SAMPLES_DIR = join(__dirname, 'samples');
-// Phrases that span the whole sample document (heading, body, URL, code block,
-// ordered/unordered lists, block quote). Asserting on these proves the parser
-// walked the entire structure, not just the first paragraph.
+// Each sample exercises a distinct officeparser code path: DOCX -> WordParser,
+// PPTX -> PowerPointParser, ODT/ODP -> OpenOfficeParser (text vs. presentation
+// element handling), with OOXML vs. ODF magic-byte detection on top.
+const SAMPLES = [
+ { label: 'DOCX', file: 'demo.docx', mimeType: DOCX },
+ { label: 'PPTX', file: 'demo.pptx', mimeType: PPTX },
+ { label: 'ODT', file: 'demo.odt', mimeType: ODT },
+ { label: 'ODP', file: 'demo.odp', mimeType: ODP }
+];
+
+// Phrases drawn from across the shared sample content (heading, body, URL, code
+// block, ordered/unordered lists, block quote, closing line). Asserting on all of
+// them proves the parser walked the whole document, not just the first paragraph.
const EXPECTED_PHRASES = [
'Welcome to Trilium Notes!',
'showcase some of its features',
@@ -44,7 +56,25 @@ beforeEach(async () => {
});
describe('OfficeProcessor (integration — real officeparser)', () => {
- it('extracts the full text of a DOCX document', async () => {
+ describe.each(SAMPLES)('$label', ({ file, mimeType }) => {
+ it('extracts the embedded text with high confidence', async () => {
+ const processor = new OfficeProcessor();
+
+ const result = await processor.extractText(readSample(file), { mimeType });
+
+ for (const phrase of EXPECTED_PHRASES) {
+ expect(result.text).toContain(phrase);
+ }
+ // Multi-paragraph output joined by the configured newline delimiter.
+ expect(result.text.split('\n').length).toBeGreaterThan(5);
+ expect(result.confidence).toBe(0.99);
+ expect(result.pageCount).toBe(1);
+ // Language defaults to English when the caller does not specify one.
+ expect(result.language).toBe('eng');
+ });
+ });
+
+ it('passes the caller-supplied language through to the result', async () => {
const processor = new OfficeProcessor();
const result = await processor.extractText(readSample('demo.docx'), {
@@ -52,30 +82,10 @@ describe('OfficeProcessor (integration — real officeparser)', () => {
language: 'deu'
});
- for (const phrase of EXPECTED_PHRASES) {
- expect(result.text).toContain(phrase);
- }
- // Multi-paragraph output joined by the configured newline delimiter.
- expect(result.text.split('\n').length).toBeGreaterThan(5);
- expect(result.confidence).toBe(0.99);
- expect(result.pageCount).toBe(1);
expect(result.language).toBe('deu');
});
- it('extracts the full text of an ODT document and defaults the language', async () => {
- const processor = new OfficeProcessor();
-
- const result = await processor.extractText(readSample('demo.odt'), { mimeType: ODT });
-
- for (const phrase of EXPECTED_PHRASES) {
- expect(result.text).toContain(phrase);
- }
- expect(result.confidence).toBe(0.99);
- expect(result.pageCount).toBe(1);
- expect(result.language).toBe('eng');
- });
-
- it('produces the same extracted text regardless of the source format', async () => {
+ it('extracts identical text from the DOCX and ODT renditions of the same document', async () => {
const processor = new OfficeProcessor();
const docx = await processor.extractText(readSample('demo.docx'), { mimeType: DOCX });
diff --git a/apps/server/src/services/ocr/processors/samples/demo.odp b/apps/server/src/services/ocr/processors/samples/demo.odp
new file mode 100644
index 0000000000..5dbfe29e8e
Binary files /dev/null and b/apps/server/src/services/ocr/processors/samples/demo.odp differ
diff --git a/apps/server/src/services/ocr/processors/samples/demo.pptx b/apps/server/src/services/ocr/processors/samples/demo.pptx
new file mode 100644
index 0000000000..a2d07b8ac0
Binary files /dev/null and b/apps/server/src/services/ocr/processors/samples/demo.pptx differ