Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
2 files
+ 139
8
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 117
0
/**
* @jest-environment ./tests/XMLEnvironment.ts
* @xml ./tests/resources/example.xml
*/
import { select, toTextArr, toTextContentArr } from "../util";
import { ItemType, DCCDocument, DCCXMLElement, IdentificationType } from "../../src";
const base = "//dcc:administrativeData/dcc:items";
const xpath = {
items: {
item: {
name: {
content: `${base}/dcc:item[1]/dcc:name/dcc:content`,
},
manufacturer: {
name: {
content: `${base}/dcc:item[1]/dcc:manufacturer/dcc:name/dcc:content`,
},
},
model: `string(${base}/dcc:item[1]/dcc:model)`,
identifications: {
identification1: {
issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:issuer)`,
value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:value)`,
name: {
content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:name/dcc:content`,
},
},
identification2: {
issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:issuer)`,
value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:value)`,
name: {
content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:name/dcc:content`,
},
},
identification3: {
issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:issuer)`,
value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:value)`,
name: {
content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:name/dcc:content`,
},
},
},
},
},
};
describe("ItemType", () => {
let dcc: DCCDocument, item: ItemType, identification1, identification2, identification3: IdentificationType, dom;
beforeEach(async () => {
({ dcc, dom } = await xmlEnv.recreateEnv());
item = dcc.digitalCalibrationCertificate.administrativeData.items.item[0];
identification1 = item.identifications.identification[0];
identification2 = item.identifications.identification[1];
identification3 = item.identifications.identification[2];
});
test("should get correct item name content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.items.item.name.content, dom);
expect(toTextArr(item.name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct item manufacturer name content from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.items.item.manufacturer.name.content, dom);
expect(toTextArr(item.manufacturer.name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct item model from XML", () => {
expect(item.model._text).toBe(select(xpath.items.item.model, dom));
});
test("should get correct identification 1 issuer from XML", () => {
expect(identification1.issuer._text).toBe(select(xpath.items.item.identifications.identification1.issuer, dom));
});
test("should get correct identification 1 value from XML", () => {
expect(identification1.value._text).toBe(select(xpath.items.item.identifications.identification1.value, dom));
});
test("should get correct identification 1 name content from XML", () => {
const expected = <Element[]>select(xpath.items.item.identifications.identification1.name.content, dom);
expect(toTextArr(identification1.name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct identification 2 issuer from XML", () => {
expect(identification2.issuer._text).toBe(select(xpath.items.item.identifications.identification2.issuer, dom));
});
test("should get correct identification 2 value from XML", () => {
expect(identification2.value._text).toBe(select(xpath.items.item.identifications.identification2.value, dom));
});
test("should get correct identification 2 name content from XML", () => {
const expected = <Element[]>select(xpath.items.item.identifications.identification2.name.content, dom);
expect(toTextArr(identification2.name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct identification 3 issuer from XML", () => {
expect(identification3.issuer._text).toBe(select(xpath.items.item.identifications.identification3.issuer, dom));
});
test("should get correct identification 3 value from XML", () => {
expect(identification3.value._text).toBe(select(xpath.items.item.identifications.identification3.value, dom));
});
test("should get correct identification 3 name content from XML", () => {
const expected = <Element[]>select(xpath.items.item.identifications.identification3.name.content, dom);
expect(toTextArr(identification3.name.content)).toEqual(toTextContentArr(expected));
});
/* TODO: setters */
});
Loading