improve test coverage

This commit is contained in:
Tom Hunkapiller
2021-05-26 10:14:19 +03:00
parent 5a52541136
commit 05a6ab77cc
7 changed files with 182 additions and 20 deletions

View File

@ -1,8 +1,14 @@
import { expect } from "chai";
import {
dateTimeValue,
hexColorValue,
hpsMeasureValue,
longHexNumber,
measurementOrPercentValue,
percentageValue,
positiveUniversalMeasureValue,
shortHexNumber,
signedHpsMeasureValue,
signedTwipsMeasureValue,
twipsMeasureValue,
universalMeasureValue,
@ -48,6 +54,29 @@ describe("values", () => {
});
});
describe("longHexNumber", () => {
it("should allow valid values", () => {
expect(longHexNumber("112233FF")).to.eq("112233FF");
});
it("should throw on invalid values", () => {
expect(() => longHexNumber("112233GG")).to.throw();
expect(() => longHexNumber("112233F")).to.throw();
expect(() => longHexNumber("112233FFF")).to.throw();
});
});
describe("shortHexNumber", () => {
it("should allow valid values", () => {
expect(shortHexNumber("1122")).to.eq("1122");
expect(shortHexNumber("FFFF")).to.eq("FFFF");
});
it("should throw on invalid values", () => {
expect(() => shortHexNumber("11")).to.throw();
expect(() => shortHexNumber("112233")).to.throw();
expect(() => shortHexNumber("FFFG")).to.throw();
});
});
describe("hexColorValue", () => {
it("should allow valid values", () => {
expect(hexColorValue("auto")).to.eq("auto");
@ -114,4 +143,51 @@ describe("values", () => {
expect(() => hpsMeasureValue("-5mm")).to.throw();
});
});
describe("signedHpsMeasureValue", () => {
it("should allow valid values", () => {
expect(signedHpsMeasureValue(1243)).to.eq(1243);
expect(signedHpsMeasureValue(-1243)).to.eq(-1243);
expect(signedHpsMeasureValue("5mm")).to.eq("5mm");
expect(signedHpsMeasureValue("-5mm")).to.eq("-5mm");
});
it("should throw on invalid values", () => {
expect(() => hpsMeasureValue(NaN)).to.throw();
expect(() => hpsMeasureValue("5FF")).to.throw();
});
});
describe("percentageValue", () => {
it("should allow valid values", () => {
expect(percentageValue("0%")).to.eq("0%");
expect(percentageValue("-20%")).to.eq("-20%");
expect(percentageValue("100%")).to.eq("100%");
expect(percentageValue("1000%")).to.eq("1000%");
});
it("should throw on invalid values", () => {
expect(() => percentageValue("0%%")).to.throw();
expect(() => percentageValue("20")).to.throw();
expect(() => percentageValue("FF%")).to.throw();
});
});
describe("measurementOrPercentValue", () => {
it("should allow valid values", () => {
expect(measurementOrPercentValue(1243)).to.eq(1243);
expect(measurementOrPercentValue(-1243)).to.eq(-1243);
expect(measurementOrPercentValue("10%")).to.eq("10%");
expect(measurementOrPercentValue("5mm")).to.eq("5mm");
});
it("should throw on invalid values", () => {
expect(() => measurementOrPercentValue(NaN)).to.throw();
expect(() => measurementOrPercentValue("10%%")).to.throw();
expect(() => measurementOrPercentValue("10F")).to.throw();
});
});
describe("dateTimeValue", () => {
it("should allow valid values", () => {
expect(dateTimeValue(new Date())).to.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d+)?Z/);
});
});
});