Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
1 file
+ 0
66
Compare changes
  • Side-by-side
  • Inline
+ 0
66
/**
* @jest-environment ./tests/XMLEnvironment.ts
* @xml ./tests/resources/example.xml
*/
import * as fc from "fast-check";
import { indexOf, select, toTextArr, toTextContentArr } from "../util";
import { CoreDataType, DCCDocument, DCCXMLElement } from "../../src";
import { string_ISO639_1 } from "../Arbitraries";
const base = "/dcc:digitalCalibrationCertificate/dcc:administrativeData/dcc:coreData";
const xpath = {
countryCodeISO3166_1: `string(${base}/dcc:countryCodeISO3166_1)`,
usedLangCodeISO639_1: `${base}/dcc:usedLangCodeISO639_1`,
};
describe("CoreDataType", () => {
let dcc: DCCDocument, coreData: CoreDataType, dom;
beforeEach(async () => {
({ dcc, dom } = await xmlEnv.recreateEnv());
coreData = dcc.digitalCalibrationCertificate.administrativeData.coreData;
});
test("should get correct countryCodeISO3166_1 from XML", () => {
expect(coreData.countryCodeISO3166_1._text).toBe(select(xpath.countryCodeISO3166_1, dom));
});
test("should get correct usedLangCodeISO639_1 from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.usedLangCodeISO639_1, dom);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toEqual(toTextContentArr(expected));
});
test("should set usedLangCodeISO639_1 correctly", () => {
fc.assert(
fc.property(string_ISO639_1(), (str) => {
// add new element to array
coreData.usedLangCodeISO639_1.push(new DCCXMLElement({ _text: str }));
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toContain(str);
expect(toTextContentArr(actual)).toContain(str);
}),
);
});
test("should delete usedLangCodeISO639_1 correctly", () => {
const selection = toTextContentArr(<Element[]>select(xpath.usedLangCodeISO639_1, dom));
fc.assert(
fc.property(fc.constantFrom(...selection), (str) => {
// get index and remove element from array
const index = indexOf(coreData.usedLangCodeISO639_1, str);
coreData.usedLangCodeISO639_1.splice(index, 1);
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).not.toContain(str);
expect(toTextContentArr(actual)).not.toContain(str);
}),
);
});
});
Loading