Files
IPSExtractor/services/desktop_app/src/renderer/lib/schemaDisplay.test.ts
T

41 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildSchemaFieldNodes, getSampleValueAtPath, groupSchemaFields, splitFieldPath } from "./schemaDisplay";
const sample = {
"CLINICA MARYBAU LA LOMA LTDA.": {
"N.I.T.": "900.277.630-4",
"Ciudad": "El Paso, Cesar",
},
"Factura Electrónica de Venta No.": "C145288",
"Descripción de los Servicios Facturados": {
items: [{ Código: "890701", "Vr. Total": "145,000" }],
},
};
describe("schemaDisplay", () => {
it("reads nested sample values", () => {
expect(getSampleValueAtPath(sample, "CLINICA MARYBAU LA LOMA LTDA./N.I.T.")).toBe("900.277.630-4");
expect(getSampleValueAtPath(sample, "Factura Electrónica de Venta No.")).toBe("C145288");
expect(getSampleValueAtPath(sample, "Descripción de los Servicios Facturados/items/*/Código")).toBe("890701");
});
it("groups fields by parent path", () => {
const nodes = buildSchemaFieldNodes(
{
"CLINICA MARYBAU LA LOMA LTDA./N.I.T.": "str",
"CLINICA MARYBAU LA LOMA LTDA./Ciudad": "str",
"Factura Electrónica de Venta No.": "str",
},
sample,
);
const groups = groupSchemaFields(nodes);
expect(groups).toHaveLength(2);
expect(groups[0].fields).toHaveLength(2);
});
it("uses short labels for nested paths", () => {
expect(splitFieldPath("Datos del Paciente/Nombre:").label).toBe("Nombre:");
expect(splitFieldPath("Datos del Paciente/Nombre:").groupLabel).toBe("Datos del Paciente");
});
});