From 48b26d7f6030c638ee71530e94a2873aea9e4974 Mon Sep 17 00:00:00 2001 From: Jan Loewe <jan.loewe@ptb.de> Date: Thu, 22 Feb 2024 08:37:03 +0100 Subject: [PATCH] fix(mathml): fix mathml not being stored in XmlType --- src/DCC.ts | 6 +- .../Regression.MathML.IsEmpty.test.ts | 43 ++++++ tests/resources/Regression_MathML_IsEmpty.xml | 144 ++++++++++++++++++ 3 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 tests/DCC/regressions/Regression.MathML.IsEmpty.test.ts create mode 100644 tests/resources/Regression_MathML_IsEmpty.xml diff --git a/src/DCC.ts b/src/DCC.ts index 66912d4..f5b1c46 100644 --- a/src/DCC.ts +++ b/src/DCC.ts @@ -75,7 +75,7 @@ export class DigitalCalibrationCertificateType extends DCCXMLElement { measurementResults: MeasurementResultListType; comment?: Comment; document?: ByteDataType; - "ds:Signature"?: any; + "ds:Signature"?: never; constructor(el: Partial<DigitalCalibrationCertificateType> = {}) { super(el); @@ -1026,10 +1026,12 @@ export class FormulaType extends DCCXMLElement { /** This data block is used to add user or application specific XML content. */ export class XmlType extends DCCXMLElement { + [key: string]: unknown; _attr: IIdAndRefIdAndRefTypeAttributes; constructor(el: Partial<XmlType> = {}) { super(el); + Object.assign(this, el); } } @@ -1355,7 +1357,7 @@ export class PositionCoordinatesType extends DCCXMLElement { } export class Comment extends DCCXMLElement { - constructor(el: Partial<Comment | any>) { + constructor(el: Partial<Comment | never>) { super(el); Object.assign(this, el); } diff --git a/tests/DCC/regressions/Regression.MathML.IsEmpty.test.ts b/tests/DCC/regressions/Regression.MathML.IsEmpty.test.ts new file mode 100644 index 0000000..c9cb7ed --- /dev/null +++ b/tests/DCC/regressions/Regression.MathML.IsEmpty.test.ts @@ -0,0 +1,43 @@ +/** + * @vitest-environment-options { "xmlPath": "./tests/resources/Regression_MathML_IsEmpty.xml" } + */ + +import { select } from "../../util"; +import { DCCDocument, FormulaType } from "../../../src"; + +const base = "//*[@refType=\"formula_01|m|x|b\"]/dcc:mathml/ml:math"; +const xpath = { + y: `string(${base}/ml:apply/ml:ci)`, + m: `string(${base}/ml:apply/ml:apply/ml:apply/ml:ci[1])`, + x: `string(${base}/ml:apply/ml:apply/ml:apply/ml:ci[2])`, + b: `string(${base}/ml:apply/ml:apply/ml:ci)`, +}; + +describe("Regression.MathML.IsEmpty", () => { + let dcc: DCCDocument, dom, formula: FormulaType; + + beforeEach(() => { + ({ dcc, dom } = recreateEnv()); + formula = dcc.digitalCalibrationCertificate.measurementResults.measurementResult[0].results.result[0].data.formula[0]; + }); + + test("mathml should be defined", () => { + expect(formula.mathml).toBeDefined(); + }); + + test("should get correct y value from XML", () => { + expect(formula.mathml["ml:math"]["ml:apply"]["ml:ci"]._text).toBe(select(xpath.y, dom)); + }); + + test("should get correct m value from XML", () => { + expect(formula.mathml["ml:math"]["ml:apply"]["ml:apply"]["ml:apply"]["ml:ci"][0]._text).toBe(select(xpath.m, dom)); + }); + + test("should get correct x value from XML", () => { + expect(formula.mathml["ml:math"]["ml:apply"]["ml:apply"]["ml:apply"]["ml:ci"][1]._text).toBe(select(xpath.x, dom)); + }); + + test("should get correct b value from XML", () => { + expect(formula.mathml["ml:math"]["ml:apply"]["ml:apply"]["ml:ci"]._text).toBe(select(xpath.b, dom)); + }); +}); diff --git a/tests/resources/Regression_MathML_IsEmpty.xml b/tests/resources/Regression_MathML_IsEmpty.xml new file mode 100644 index 0000000..27d1c1f --- /dev/null +++ b/tests/resources/Regression_MathML_IsEmpty.xml @@ -0,0 +1,144 @@ +<?xml version="1.0" encoding="utf-8"?> +<dcc:digitalCalibrationCertificate + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ml="http://www.w3.org/1998/Math/MathML" + xmlns:dcc="https://ptb.de/dcc" + xmlns:si="https://ptb.de/si" + xsi:schemaLocation="http://www.w3.org/1998/Math/MathML https://www.w3.org/Math/XMLSchema/mathml3/mathml3.xsd https://ptb.de/dcc https://ptb.de/dcc/v3.2.1/dcc.xsd" + schemaVersion="3.2.1"> + <dcc:administrativeData> + <dcc:dccSoftware> + <dcc:software> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + <dcc:release>!</dcc:release> + </dcc:software> + </dcc:dccSoftware> + <dcc:coreData> + <dcc:countryCodeISO3166_1>MX</dcc:countryCodeISO3166_1> + <dcc:usedLangCodeISO639_1>en</dcc:usedLangCodeISO639_1> + <dcc:usedLangCodeISO639_1>es</dcc:usedLangCodeISO639_1> + <dcc:mandatoryLangCodeISO639_1>en</dcc:mandatoryLangCodeISO639_1> + <dcc:uniqueIdentifier>!</dcc:uniqueIdentifier> + <dcc:beginPerformanceDate>1957-08-13</dcc:beginPerformanceDate> + <dcc:endPerformanceDate>1957-08-13</dcc:endPerformanceDate> + <dcc:performanceLocation>laboratory</dcc:performanceLocation> + </dcc:coreData> + <dcc:items> + <dcc:item> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + <dcc:identifications> + <dcc:identification> + <dcc:issuer>manufacturer</dcc:issuer> + <dcc:value>!</dcc:value> + </dcc:identification> + </dcc:identifications> + </dcc:item> + </dcc:items> + <dcc:calibrationLaboratory> + <dcc:contact> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + <dcc:location> + <dcc:city>!</dcc:city> + </dcc:location> + </dcc:contact> + </dcc:calibrationLaboratory> + <dcc:respPersons> + <dcc:respPerson> + <dcc:person> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + </dcc:person> + </dcc:respPerson> + </dcc:respPersons> + <dcc:customer> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + <dcc:location> + <dcc:city>!</dcc:city> + </dcc:location> + </dcc:customer> + </dcc:administrativeData> + <dcc:measurementResults> + <dcc:measurementResult> + <dcc:name> + <dcc:content>String</dcc:content> + </dcc:name> + <dcc:results> + <dcc:result> + <dcc:name> + <dcc:content lang="es">Polinomio de aproximación</dcc:content> + <dcc:content lang="en">Approximation polynom</dcc:content> + </dcc:name> + <dcc:data> + <dcc:formula refType="formula_01|m|x|b"> + <dcc:mathml> + <ml:math> + <ml:apply> <ml:eq/> + <ml:apply> <ml:plus/> + <ml:apply> <ml:times/> + <ml:ci xref="m">m</ml:ci> + <ml:ci id="x">x</ml:ci> + </ml:apply> + <ml:ci xref="b">b</ml:ci> + </ml:apply> + <ml:ci id="y">y</ml:ci> + </ml:apply> + </ml:math> + </dcc:mathml> + </dcc:formula> + <dcc:quantity id="m" refType="basic_formulaParameter"> + <dcc:name> + <dcc:content lang="es">Coeficiente polinómico m</dcc:content> + <dcc:content lang="en">Polynom coefficient m</dcc:content> + </dcc:name> + <si:real> + <si:value>0.3522</si:value> + <si:unit>\metre\per\second\tothe{2}\kilogram</si:unit> + <si:expandedUnc> + <si:uncertainty>0.05</si:uncertainty> + <si:coverageFactor>2</si:coverageFactor> + <si:coverageProbability>0.95</si:coverageProbability> + <si:distribution>normal</si:distribution> + </si:expandedUnc> + </si:real> + </dcc:quantity> + <dcc:quantity id="b" refType="basic_formulaParameter"> + <dcc:name> + <dcc:content lang="es">Coeficiente polinómico b</dcc:content> + <dcc:content lang="en">Polynom coefficient b</dcc:content> + </dcc:name> + <si:real> + <si:value>10.139</si:value> + <si:unit>\metre\per\second\tothe{2}</si:unit> + <si:expandedUnc> + <si:uncertainty>0.25</si:uncertainty> + <si:coverageFactor>2</si:coverageFactor> + <si:coverageProbability>0.95</si:coverageProbability> + <si:distribution>normal</si:distribution> + </si:expandedUnc> + </si:real> + </dcc:quantity> + <dcc:quantity refId="x" refType="basic_formulaInputQuantity"> + <dcc:name> + <dcc:content lang="es">Masa agregada</dcc:content> + <dcc:content lang="en">Aggregate mass</dcc:content> + </dcc:name> + <si:realListXMLList> + <si:valueXMLList>0.01205 0.02324 0.05542 0.06661</si:valueXMLList> + <si:unitXMLList>\kilogram</si:unitXMLList> + </si:realListXMLList> + </dcc:quantity> + </dcc:data> + </dcc:result> + </dcc:results> + </dcc:measurementResult> + </dcc:measurementResults> +</dcc:digitalCalibrationCertificate> -- GitLab