Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
2 files
+ 81
1
Compare changes
  • Side-by-side
  • Inline
Files
2
/**
* @jest-environment ./tests/XMLEnvironment.ts
* @xml ./tests/resources/example.xml
*/
import { select, toTextArr, toTextContentArr } from "../util";
import { CalibrationLaboratoryType, DCCDocument } from "../../src";
const base = "/dcc:digitalCalibrationCertificate/dcc:administrativeData/dcc:calibrationLaboratory/dcc:contact";
const xpath = {
name: `string(${base}/dcc:name/dcc:content)`,
eMail: `string(${base}/dcc:eMail)`,
phone: `string(${base}/dcc:phone)`,
fax: `string(${base}/dcc:fax)`,
location: {
city: `${base}/dcc:location/dcc:city`,
countryCode: `${base}/dcc:location/dcc:countryCode`,
postCode: `${base}/dcc:location/dcc:postCode`,
street: `${base}/dcc:location/dcc:street`,
streetNo: `${base}/dcc:location/dcc:streetNo`,
further: `${base}/dcc:location/dcc:further/dcc:content`,
},
};
describe("CalibrationLaboratoryType", () => {
let dcc: DCCDocument, calibrationLaboratory: CalibrationLaboratoryType, dom;
beforeEach(async () => {
({ dcc, dom } = await xmlEnv.recreateEnv());
calibrationLaboratory = dcc.digitalCalibrationCertificate.administrativeData.calibrationLaboratory;
});
test("should get correct name from XML", () => {
expect(calibrationLaboratory.contact.name.content[0]._text).toBe(select(xpath.name, dom));
});
test("should get correct eMail from XML", () => {
expect(calibrationLaboratory.contact.eMail._text).toBe(select(xpath.eMail, dom));
});
test("should get correct phone from XML", () => {
expect(calibrationLaboratory.contact.phone._text).toBe(select(xpath.phone, dom));
});
test("should get correct city from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.city, dom);
expect(toTextArr(calibrationLaboratory.contact.location.city)).toEqual(toTextContentArr(expected));
});
test("should get correct countryCode from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.countryCode, dom);
expect(toTextArr(calibrationLaboratory.contact.location.countryCode)).toEqual(toTextContentArr(expected));
});
test("should get correct postCode from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.postCode, dom);
expect(toTextArr(calibrationLaboratory.contact.location.postCode)).toEqual(toTextContentArr(expected));
});
test("should get correct street from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.street, dom);
expect(toTextArr(calibrationLaboratory.contact.location.street)).toEqual(toTextContentArr(expected));
});
test("should get correct streetNo from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.streetNo, dom);
expect(toTextArr(calibrationLaboratory.contact.location.streetNo)).toEqual(toTextContentArr(expected));
});
test("should get correct further element from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.location.further, dom);
expect(toTextArr(calibrationLaboratory.contact.location.further[0].content)).toEqual(toTextContentArr(expected));
});
});
Loading