61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
import { firstValueFrom, of } from 'rxjs';
|
|
import { SourceGateway } from '../api/source-gateway';
|
|
import { DocumentConnection, DocumentTable } from './document-source';
|
|
import { PdfConnection } from './pdf-source';
|
|
|
|
describe('DocumentTable', () => {
|
|
const extraction = { columns: [], sample_rows: [], total_rows: 1, suggested_mapping: [], key_field: 'pac_id_hospital', fields: [], records: [] };
|
|
|
|
function table(): DocumentTable {
|
|
const connection = new DocumentConnection([new File(['a'], 'a.pdf'), new File(['b'], 'b.png')]);
|
|
return new DocumentTable(connection, 'Registros');
|
|
}
|
|
|
|
it('sends every file, the settings and the corrections for the flow target only', async () => {
|
|
const t = table();
|
|
t.configure({ segmentation: 'pages', pages_per_record: 2, ocr_mode: 'always', key_pattern: ' EXP-\\d+ ' }, {
|
|
'cacu.Paciente': { '0': { pac_sexo: 'F' } },
|
|
'cacu.CitologiaCervical': { '1': { cit_vph_resultado: 'NEGATIVO' } },
|
|
});
|
|
const locator = await t.locator('cacu.Paciente');
|
|
expect(locator).toEqual({
|
|
source_type: 'document',
|
|
payload: {
|
|
files: [
|
|
{ name: 'a.pdf', file_base64: btoa('a') },
|
|
{ name: 'b.png', file_base64: btoa('b') },
|
|
],
|
|
segmentation: 'pages',
|
|
pages_per_record: 2,
|
|
ocr_mode: 'always',
|
|
key_pattern: 'EXP-\\d+',
|
|
overrides: { '0': { pac_sexo: 'F' } },
|
|
},
|
|
});
|
|
});
|
|
|
|
it('changing how pages are split drops corrections, which point at record numbers', () => {
|
|
const t = table();
|
|
t.configure(t.settings(), { 'cacu.Paciente': { '0': { pac_sexo: 'F' } } });
|
|
t.configure({ ...t.settings(), segmentation: 'document' });
|
|
expect(t.overrides('cacu.Paciente')).toEqual({});
|
|
});
|
|
|
|
it('keeps the last extraction per target', async () => {
|
|
const t = table();
|
|
const calls: unknown[][] = [];
|
|
const gateway = { document: { extract: (...args: unknown[]) => (calls.push(args), of(extraction)) } } as unknown as SourceGateway;
|
|
await firstValueFrom(t.preview(gateway, 'cacu.Paciente'));
|
|
expect(t.extractions()['cacu.Paciente']).toBe(extraction);
|
|
expect(calls[0][1]).toBe('cacu.Paciente');
|
|
});
|
|
|
|
it('a PDF offers its whole text as a document table next to its detected tables', () => {
|
|
const gateway = { pdf: { detect: () => of({ page_count: 1, has_text_layer: false, table_candidates: [] }) } } as unknown as SourceGateway;
|
|
const pdf = new PdfConnection(new File(['%PDF'], 'informe.pdf'));
|
|
pdf.load(gateway).subscribe();
|
|
expect(pdf.tables()).toEqual([pdf.documentTable]);
|
|
expect(pdf.documentTable.files.map((f) => f.name)).toEqual(['informe.pdf']);
|
|
});
|
|
});
|