Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
Compare and Show latest version
11 files
+ 189
35
Compare changes
  • Side-by-side
  • Inline
Files
11
+ 72
0
 
/**
 
* @jest-environment ./tests/XMLEnvironment.ts
 
* @xml ./tests/resources/example.xml
 
*/
 
 
import { select, toTextArr, toTextContentArr } from "../util";
 
import { ContactType, DCCDocument, LocationType } from "../../src";
 
 
const base = "//dcc:administrativeData/dcc:customer";
 
const xpath = {
 
customerNameContent: `${base}/dcc:name/dcc:content`,
 
customerEmail: `string(${base}/dcc:eMail)`,
 
customerPhone: `${base}/dcc:phone)`,
 
customerFax: `${base}/dcc:fax)`,
 
customerLocation: `${base}/dcc:location`,
 
customerLocationCity: `${base}/dcc:location/dcc:city[1]`,
 
customerLocationCountryCode: `${base}/dcc:location/dcc:countryCode[1]`,
 
customerLocationPostCode: `${base}/dcc:location/dcc:postCode[1]`,
 
customerLocationPostBoxOffice: `${base}/dcc:location/dcc:postBoxOffice[1]`,
 
customerLocationState: `${base}/dcc:location/dcc:state[1]`,
 
customerLocationStreet: `${base}/dcc:location/dcc:street[1]`,
 
customerLocationStreetNo: `${base}/dcc:location/dcc:streetNo[1]`,
 
customerLocationFurther: `${base}/dcc:location/dcc:further[1]/dcc:content`,
 
customerLocationPositionCoordinates: `${base}/dcc:location/dcc:positionCoordinates[1]`,
 
customerDescriptionData: `${base}/dcc:descriptionData`,
 
customerId: `${base}/@id`,
 
};
 
 
describe("ContactType", () => {
 
let dcc: DCCDocument, customer: ContactType, location: LocationType, dom;
 
 
beforeEach(async () => {
 
({ dcc, dom } = await xmlEnv.recreateEnv());
 
customer = dcc.digitalCalibrationCertificate.administrativeData.customer;
 
location = customer.location;
 
});
 
 
test("should get correct customer name content from XML", () => {
 
// get expected list from example xml
 
const expected = <Element[]>select(xpath.customerNameContent, dom);
 
expect(toTextArr(customer.name.content)).toEqual(toTextContentArr(expected));
 
});
 
 
test("should get correct customer email address from XML", () => {
 
expect(customer.eMail._text).toBe(select(xpath.customerEmail, dom));
 
});
 
 
test("should get correct customer location city from XML", () => {
 
const expected = <Element[]>select(xpath.customerLocationCity, dom);
 
expect(customer.location.city[0]._text).toEqual(toTextContentArr(expected).pop());
 
});
 
 
test("should get correct customer location county code from XML", () => {
 
const expected = <Element[]>select(xpath.customerLocationCountryCode, dom);
 
expect(customer.location.countryCode[0]._text).toEqual(toTextContentArr(expected).pop());
 
});
 
 
test("should get correct customer location post code from XML", () => {
 
const expected = <Element[]>select(xpath.customerLocationPostCode, dom);
 
expect(customer.location.postCode[0]._text).toEqual(toTextContentArr(expected).pop());
 
});
 
 
test("should get correct customer location further from XML", () => {
 
const expected = <Element[]>select(xpath.customerLocationFurther, dom);
 
 
for (var i = 0; i < expected.length; i++) {
 
expect(customer.location.further[0].content[i]._text).toBe(expected[i].textContent);
 
}
 
});
 
 
/* TODO: setters */
 
});
Loading