Add tests

This commit is contained in:
Dolan
2018-12-16 01:56:42 +00:00
parent a1c21d2143
commit 0725e54271
4 changed files with 59 additions and 6 deletions

View File

@ -1,8 +1,11 @@
import { expect } from "chai"; import { expect } from "chai";
import * as sinon from "sinon";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { File } from "./file"; import { File } from "./file";
import { Paragraph } from "./paragraph";
import { Table } from "./table";
describe("File", () => { describe("File", () => {
describe("#constructor", () => { describe("#constructor", () => {
@ -55,4 +58,24 @@ describe("File", () => {
expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"][0]._attr["w:type"]).to.equal("even"); expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"][0]._attr["w:type"]).to.equal("even");
}); });
}); });
describe("#addParagraph", () => {
it("should call the underlying header's addParagraph", () => {
const file = new File();
const spy = sinon.spy(file.Document, "addParagraph");
file.addParagraph(new Paragraph());
expect(spy.called).to.equal(true);
});
});
describe("#addTable", () => {
it("should call the underlying header's addParagraph", () => {
const wrapper = new File();
const spy = sinon.spy(wrapper.Document, "addTable");
wrapper.addTable(new Table(1, 1));
expect(spy.called).to.equal(true);
});
});
}); });

View File

@ -0,0 +1,29 @@
import { expect } from "chai";
import * as sinon from "sinon";
import { FooterWrapper } from "./footer-wrapper";
import { Media } from "./media";
import { Paragraph } from "./paragraph";
import { Table } from "./table";
describe("FooterWrapper", () => {
describe("#addParagraph", () => {
it("should call the underlying header's addParagraph", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.Footer, "addParagraph");
file.addParagraph(new Paragraph());
expect(spy.called).to.equal(true);
});
});
describe("#addTable", () => {
it("should call the underlying header's addParagraph", () => {
const wrapper = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(wrapper.Footer, "addTable");
wrapper.addTable(new Table(1, 1));
expect(spy.called).to.equal(true);
});
});
});

View File

@ -9,9 +9,9 @@ import { Table } from "./table";
describe("HeaderWrapper", () => { describe("HeaderWrapper", () => {
describe("#addParagraph", () => { describe("#addParagraph", () => {
it("should call the underlying header's addParagraph", () => { it("should call the underlying header's addParagraph", () => {
const file = new HeaderWrapper(new Media(), 1); const wrapper = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(file.Header, "addParagraph"); const spy = sinon.spy(wrapper.Header, "addParagraph");
file.addParagraph(new Paragraph()); wrapper.addParagraph(new Paragraph());
expect(spy.called).to.equal(true); expect(spy.called).to.equal(true);
}); });
@ -19,9 +19,9 @@ describe("HeaderWrapper", () => {
describe("#addTable", () => { describe("#addTable", () => {
it("should call the underlying header's addParagraph", () => { it("should call the underlying header's addParagraph", () => {
const file = new HeaderWrapper(new Media(), 1); const wrapper = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(file.Header, "addTable"); const spy = sinon.spy(wrapper.Header, "addTable");
file.addTable(new Table(1, 1)); wrapper.addTable(new Table(1, 1));
expect(spy.called).to.equal(true); expect(spy.called).to.equal(true);
}); });

View File

@ -233,6 +233,7 @@ export class ImportDotx {
private titlePageIsDefined(xmlData: string): boolean { private titlePageIsDefined(xmlData: string): boolean {
const xmlObj = xml2js(xmlData, { compact: true }) as XMLElementCompact; const xmlObj = xml2js(xmlData, { compact: true }) as XMLElementCompact;
const sectionProp = xmlObj["w:document"]["w:body"]["w:sectPr"]; const sectionProp = xmlObj["w:document"]["w:body"]["w:sectPr"];
return sectionProp["w:titlePg"] !== undefined; return sectionProp["w:titlePg"] !== undefined;
} }