Files
rk-frontend/src/lib/pdf-search.test.ts
T
2026-11-05 15:17:01 +01:00

28 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
// @ts-ignore Node führt diesen Test direkt mit Type-Stripping aus.
import { findPdfPages, findUnitPages } from './pdf-search.ts';
const pages = [
{ page: 2, text: 'Name =BAI-ET+29/50 Aktuelle Seite 102 Zufuhrband' },
{ page: 3, text: 'Name =BAI-ET+28/5 Aktuelle Seite 103' },
{ page: 7, text: 'Name = BAI-ET +29 /5 Aktuelle Seite 107 SC' },
{ page: 8, text: 'Name =BAI-ET+29/5.1 Aktuelle Seite 108' },
{ page: 9, text: '', label: '=BAI-ET+29/5' },
];
test('EPLAN references match structure and exact page, independently of PDF page number', () => {
assert.deepEqual(findPdfPages(pages, '=BAI-ET+29/5'), [7, 9]);
});
test('name search ignores case, whitespace and PDF dash variants', () => {
assert.deepEqual(findPdfPages(pages, 'zufuhr band'), [2]);
assert.deepEqual(findPdfPages(pages, '=BAI–ET+29/5'), [7, 9]);
assert.deepEqual(findPdfPages(pages, ''), []);
});
test('unit search uses all distinct E/A references before falling back to the name', () => {
assert.deepEqual(findUnitPages(pages, { name: 'Zufuhrband', label: 'BA1_Zufuhrband', references: ['=BAI-ET+29/5', '=BAI-ET+29/5'] }),
{ pages: [7, 9], source: 'EPLAN-Verweise' });
assert.deepEqual(findUnitPages(pages, { name: 'Zufuhrband', label: 'BA1_Zufuhrband', references: ['=MISSING/5'] }),
{ pages: [2], source: 'Unit-Name' });
});