Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
1 file
+ 211
0
Compare changes
  • Side-by-side
  • Inline
+ 211
0
/**
* @jest-environment ./tests/XMLEnvironment.ts
* @xml ./tests/resources/example.xml
*/
import { select, toTextArr, toTextContentArr } from "../util";
import { StatementMetaDataType, DCCDocument } from "../../src";
const base = "//dcc:administrativeData/dcc:statements";
const xpath = {
statements: {
statement1: {
norm: `string(${base}/dcc:statement[1]/dcc:norm)`,
reference: `string(${base}/dcc:statement[1]/dcc:reference)`,
declaration: {
content: `${base}/dcc:statement[1]/dcc:declaration/dcc:content`,
},
refType: `string(${base}/dcc:statement[1]/@refType)`,
},
statement2: {
declaration: {
content: `${base}/dcc:statement[2]/dcc:declaration/dcc:content`,
},
data: {
quantity1: {
name: {
content: `${base}/dcc:statement[2]/dcc:data/dcc:quantity[1]/dcc:name/dcc:content`,
},
si_real: {
si_value: `string(${base}/dcc:statement[2]/dcc:data/dcc:quantity[1]/si:real/si:value)`,
si_unit: `string(${base}/dcc:statement[2]/dcc:data/dcc:quantity[1]/si:real/si:unit)`,
},
},
quantity2: {
name: {
content: `${base}/dcc:statement[2]/dcc:data/dcc:quantity[2]/dcc:name/dcc:content`,
},
si_real: {
si_value: `string(${base}/dcc:statement[2]/dcc:data/dcc:quantity[2]/si:real/si:value)`,
si_unit: `string(${base}/dcc:statement[2]/dcc:data/dcc:quantity[2]/si:real/si:unit)`,
},
},
},
refType: `string(${base}/dcc:statement[2]/@refType)`,
},
statement3: {
declaration: {
content: `${base}/dcc:statement[3]/dcc:declaration/dcc:content`,
},
respAuthority: {
name: {
content: `${base}/dcc:statement[3]/dcc:respAuthority/dcc:name/dcc:content`,
},
email: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:email)`,
location: {
city: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:city)`,
countryCode: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:countryCode)`,
postCode: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:postCode)`,
},
},
conformity: `string(${base}/dcc:statement[3]/dcc:conformity)`,
refType: `string(${base}/dcc:statement[3]/@refType)`,
},
statement4: {
declaration: {
content: `${base}/dcc:statement[4]/dcc:declaration/dcc:content`,
},
date: `string(${base}/dcc:statement[4]/dcc:date)`,
respAuthority: {
name: {
content: `${base}/dcc:statement[3]/dcc:respAuthority/dcc:name/dcc:content`,
},
email: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:email)`,
location: {
city: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:city)`,
countryCode: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:countryCode)`,
postCode: `string(${base}/dcc:statement[3]/dcc:respAuthority/dcc:location/dcc:postCode)`,
},
},
refType: `string(${base}/dcc:statement[4]/@refType)`,
},
},
};
describe("ItemType", () => {
let dcc: DCCDocument, statement1, statement2, statement3, statement4: StatementMetaDataType, dom;
beforeEach(async () => {
({ dcc, dom } = await xmlEnv.recreateEnv());
statement1 = dcc.digitalCalibrationCertificate.administrativeData.statements.statement[0];
statement2 = dcc.digitalCalibrationCertificate.administrativeData.statements.statement[1];
statement3 = dcc.digitalCalibrationCertificate.administrativeData.statements.statement[2];
statement4 = dcc.digitalCalibrationCertificate.administrativeData.statements.statement[3];
});
test("should get correct statement 1 declaration content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement1.declaration.content, dom);
expect(toTextArr(statement1.declaration.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 1 norm model from XML", () => {
expect(statement1.norm[0]._text).toBe(select(xpath.statements.statement1.norm, dom));
});
test("should get correct statement 1 reference from XML", () => {
expect(statement1.reference[0]._text).toBe(select(xpath.statements.statement1.reference, dom));
});
/* TODO: get refType from jest */
/*
test("should get correct statement 1 refType from XML", () => {
console.log(statement1);
expect(statement1.refType._text).toBe(select(xpath.statements.statement1.refType, dom));
});
*/
test("should get correct statement 2 declaration content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement2.declaration.content, dom);
expect(toTextArr(statement2.declaration.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 2 data quantity 1 name content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement2.data.quantity1.name.content, dom);
expect(toTextArr(statement2.data.quantity[0].name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 2 data quantity 1 si:value from XML", () => {
expect(statement2.data.quantity[0].real.value._text).toBe(select(xpath.statements.statement2.data.quantity1.si_real.si_value, dom));
});
test("should get correct statement 2 data quantity 2 si:unit from XML", () => {
expect(statement2.data.quantity[0].real.unit._text).toBe(select(xpath.statements.statement2.data.quantity1.si_real.si_unit, dom));
});
test("should get correct statement 2 data quantity 2 name content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement2.data.quantity2.name.content, dom);
expect(toTextArr(statement2.data.quantity[1].name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 2 data quantity 2 si:value from XML", () => {
expect(statement2.data.quantity[1].real.value._text).toBe(select(xpath.statements.statement2.data.quantity2.si_real.si_value, dom));
});
test("should get correct statement 2 data quantity 2 si:unit from XML", () => {
expect(statement2.data.quantity[1].real.unit._text).toBe(select(xpath.statements.statement2.data.quantity2.si_real.si_unit, dom));
});
test("should get correct statement 3 declaration content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement3.declaration.content, dom);
expect(toTextArr(statement3.declaration.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 3 responsible authority name content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement3.respAuthority.name.content, dom);
expect(toTextArr(statement3.respAuthority.name.content)).toEqual(toTextContentArr(expected));
});
/* responsible authority 3 */
test("should get correct statement 3 responsible authority email from XML", () => {
expect(statement3.respAuthority.eMail._text).toBe(select(xpath.statements.statement3.respAuthority.email, dom));
});
test("should get correct statement 3 responsible authority location city from XML", () => {
expect(statement3.respAuthority.location.city[0]._text).toBe(select(xpath.statements.statement3.respAuthority.location.city, dom));
});
test("should get correct statement 3 responsible authority location country code from XML", () => {
expect(statement3.respAuthority.location.countryCode[0]._text).toBe(select(xpath.statements.statement3.respAuthority.location.countryCode, dom));
});
test("should get correct statement 3 responsible authority location post code from XML", () => {
expect(statement3.respAuthority.location.postCode[0]._text).toBe(select(xpath.statements.statement3.respAuthority.location.postCode, dom));
});
test("should get correct statement 3 conformity from XML", () => {
expect(statement3.conformity._text).toBe(select(xpath.statements.statement3.conformity, dom));
});
test("should get correct statement 4 declaration content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.statements.statement4.declaration.content, dom);
expect(toTextArr(statement4.declaration.content)).toEqual(toTextContentArr(expected));
});
test("should get correct statement 4 date from XML", () => {
expect(statement4.date._text).toBe(select(xpath.statements.statement4.date, dom));
});
/* responsible authority 4 */
test("should get correct statement 4 responsible authority email from XML", () => {
expect(statement4.respAuthority.eMail._text).toBe(select(xpath.statements.statement4.respAuthority.email, dom));
});
test("should get correct statement 4 responsible authority location city from XML", () => {
expect(statement4.respAuthority.location.city[0]._text).toBe(select(xpath.statements.statement4.respAuthority.location.city, dom));
});
test("should get correct statement 4 responsible authority location country code from XML", () => {
expect(statement4.respAuthority.location.countryCode[0]._text).toBe(select(xpath.statements.statement4.respAuthority.location.countryCode, dom));
});
test("should get correct statement 4 responsible authority location post code from XML", () => {
expect(statement4.respAuthority.location.postCode[0]._text).toBe(select(xpath.statements.statement4.respAuthority.location.postCode, dom));
});
/* TODO: refTypes */
/* TODO: setters */
});
Loading