Add tests and bump coverage

This commit is contained in:
Dolan Miu
2022-09-22 07:19:14 +01:00
parent 5950055cca
commit 0ac23d0646
3 changed files with 65 additions and 3 deletions

6
.nycrc
View File

@ -1,9 +1,9 @@
{ {
"check-coverage": true, "check-coverage": true,
"statements": 99.62, "statements": 99.72,
"branches": 96.81, "branches": 97.95,
"functions": 99.82, "functions": 99.82,
"lines": 99.62, "lines": 99.71,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],

View File

@ -13,6 +13,13 @@ describe("Columns", () => {
expect(tree["w:cols"]).to.deep.equal({ _attr: { "w:num": 3, "w:space": 720 } }); expect(tree["w:cols"]).to.deep.equal({ _attr: { "w:num": 3, "w:space": 720 } });
}); });
it("should create set space and count to undefined if they are undefined", () => {
const columns = new Columns({});
const tree = new Formatter().format(columns);
expect(tree["w:cols"]).to.deep.equal({ _attr: {} });
});
it("should ignore individual column attributes if equalWidth is true", () => { it("should ignore individual column attributes if equalWidth is true", () => {
const unequalColumns = [new Column({ width: 1000, space: 400 }), new Column({ width: 2000 })]; const unequalColumns = [new Column({ width: 1000, space: 400 }), new Column({ width: 2000 })];
const columns = new Columns({ count: 3, space: 720, equalWidth: true, children: unequalColumns }); const columns = new Columns({ count: 3, space: 720, equalWidth: true, children: unequalColumns });

View File

@ -6,6 +6,7 @@ import { sectionMarginDefaults, sectionPageSizeDefaults } from "./document";
import { File } from "./file"; import { File } from "./file";
import { Footer, Header } from "./header"; import { Footer, Header } from "./header";
import { Paragraph } from "./paragraph"; import { Paragraph } from "./paragraph";
import { Media } from "./media";
const PAGE_SIZE_DEFAULTS = { const PAGE_SIZE_DEFAULTS = {
"w:h": sectionPageSizeDefaults.HEIGHT, "w:h": sectionPageSizeDefaults.HEIGHT,
@ -411,4 +412,58 @@ describe("File", () => {
expect(doc.Numbering).to.not.be.undefined; expect(doc.Numbering).to.not.be.undefined;
}); });
}); });
describe("#getters", () => {
it("should have defined getters", () => {
const doc = new File({
sections: [],
});
expect(doc.CoreProperties).to.not.be.undefined;
expect(doc.Media).to.not.be.undefined;
expect(doc.FileRelationships).to.not.be.undefined;
expect(doc.Headers).to.not.be.undefined;
expect(doc.Footers).to.not.be.undefined;
expect(doc.ContentTypes).to.not.be.undefined;
expect(doc.CustomProperties).to.not.be.undefined;
expect(doc.AppProperties).to.not.be.undefined;
expect(doc.FootNotes).to.not.be.undefined;
expect(doc.Settings).to.not.be.undefined;
expect(doc.Comments).to.not.be.undefined;
});
});
describe("#templates", () => {
// Test will be deprecated when import-dotx and templates are deprecated
it("should work with template", () => {
const doc = new File(
{
sections: [],
},
{
template: {
currentRelationshipId: 1,
headers: [],
footers: [],
styles: "",
titlePageIsDefined: true,
media: new Media(),
},
},
);
expect(doc).to.not.be.undefined;
});
});
describe("#externalStyles", () => {
it("should work with external styles", () => {
const doc = new File({
sections: [],
externalStyles: "",
});
expect(doc.Styles).to.not.be.undefined;
});
});
}); });