Add more tests
This commit is contained in:
@ -9,7 +9,7 @@ import { Table } from "./table";
|
||||
|
||||
describe("File", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create with correct headers", () => {
|
||||
it("should create with correct headers and footers", () => {
|
||||
const doc = new File();
|
||||
const header = doc.createHeader();
|
||||
const footer = doc.createFooter();
|
||||
@ -29,6 +29,26 @@ describe("File", () => {
|
||||
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"][0]._attr["w:type"]).to.equal("default");
|
||||
});
|
||||
|
||||
it("should create with first headers and footers", () => {
|
||||
const doc = new File();
|
||||
const header = doc.createHeader();
|
||||
const footer = doc.createFooter();
|
||||
|
||||
doc.addSection({
|
||||
headers: {
|
||||
first: header,
|
||||
},
|
||||
footers: {
|
||||
first: footer,
|
||||
},
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(doc.Document.Body);
|
||||
|
||||
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"][0]._attr["w:type"]).to.equal("first");
|
||||
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"][0]._attr["w:type"]).to.equal("first");
|
||||
});
|
||||
|
||||
it("should create with correct headers", () => {
|
||||
const doc = new File();
|
||||
const header = doc.createHeader();
|
||||
@ -60,7 +80,7 @@ describe("File", () => {
|
||||
});
|
||||
|
||||
describe("#addParagraph", () => {
|
||||
it("should call the underlying header's addParagraph", () => {
|
||||
it("should call the underlying document's addParagraph", () => {
|
||||
const file = new File();
|
||||
const spy = sinon.spy(file.Document, "addParagraph");
|
||||
file.addParagraph(new Paragraph());
|
||||
@ -70,7 +90,7 @@ describe("File", () => {
|
||||
});
|
||||
|
||||
describe("#addTable", () => {
|
||||
it("should call the underlying header's addParagraph", () => {
|
||||
it("should call the underlying document's addTable", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Document, "addTable");
|
||||
wrapper.addTable(new Table(1, 1));
|
||||
@ -78,4 +98,68 @@ describe("File", () => {
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createTable", () => {
|
||||
it("should call the underlying document's createTable", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Document, "createTable");
|
||||
wrapper.createTable(1, 1);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addTableOfContents", () => {
|
||||
it("should call the underlying document's addTableOfContents", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Document, "addTableOfContents");
|
||||
// tslint:disable-next-line:no-any
|
||||
wrapper.addTableOfContents({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createParagraph", () => {
|
||||
it("should call the underlying document's createParagraph", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Document, "createParagraph");
|
||||
wrapper.createParagraph("test");
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addImage", () => {
|
||||
it("should call the underlying document's addImage", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Document, "addParagraph");
|
||||
// tslint:disable-next-line:no-any
|
||||
wrapper.addImage({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createImage", () => {
|
||||
it("should call the underlying document's createImage", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.Media, "addMedia");
|
||||
const wrapperSpy = sinon.spy(wrapper.Document, "addParagraph");
|
||||
wrapper.createImage("");
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
expect(wrapperSpy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createFootnote", () => {
|
||||
it("should call the underlying document's createFootnote", () => {
|
||||
const wrapper = new File();
|
||||
const spy = sinon.spy(wrapper.FootNotes, "createFootNote");
|
||||
wrapper.createFootnote(new Paragraph(""));
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -281,12 +281,6 @@ export class File {
|
||||
|
||||
for (const header of headers) {
|
||||
switch (header.type) {
|
||||
case HeaderReferenceType.DEFAULT:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
default: header.header,
|
||||
};
|
||||
break;
|
||||
case HeaderReferenceType.FIRST:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
@ -299,6 +293,7 @@ export class File {
|
||||
even: header.header,
|
||||
};
|
||||
break;
|
||||
case HeaderReferenceType.DEFAULT:
|
||||
default:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
@ -316,12 +311,6 @@ export class File {
|
||||
|
||||
for (const footer of footers) {
|
||||
switch (footer.type) {
|
||||
case FooterReferenceType.DEFAULT:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
default: footer.footer,
|
||||
};
|
||||
break;
|
||||
case FooterReferenceType.FIRST:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
@ -334,6 +323,7 @@ export class File {
|
||||
even: footer.footer,
|
||||
};
|
||||
break;
|
||||
case FooterReferenceType.DEFAULT:
|
||||
default:
|
||||
newGroup = {
|
||||
...newGroup,
|
||||
|
@ -26,4 +26,58 @@ describe("FooterWrapper", () => {
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createTable", () => {
|
||||
it("should call the underlying footer's createTable", () => {
|
||||
const wrapper = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(wrapper.Footer, "createTable");
|
||||
wrapper.createTable(1, 1);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createParagraph", () => {
|
||||
it("should call the underlying footer's createParagraph", () => {
|
||||
const file = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Footer, "addParagraph");
|
||||
file.createParagraph();
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addImage", () => {
|
||||
it("should call the underlying footer's addImage", () => {
|
||||
const file = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Footer, "addParagraph");
|
||||
// tslint:disable-next-line:no-any
|
||||
file.addImage({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createImage", () => {
|
||||
it("should call the underlying footer's createImage", () => {
|
||||
const file = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Media, "addMedia");
|
||||
const fileSpy = sinon.spy(file, "addImage");
|
||||
file.createImage("");
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
expect(fileSpy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addChildElement", () => {
|
||||
it("should call the underlying footer's addChildElement", () => {
|
||||
const file = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Footer, "addChildElement");
|
||||
// tslint:disable-next-line:no-any
|
||||
file.addChildElement({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe("HeaderWrapper", () => {
|
||||
});
|
||||
|
||||
describe("#addTable", () => {
|
||||
it("should call the underlying header's addParagraph", () => {
|
||||
it("should call the underlying header's addTable", () => {
|
||||
const wrapper = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(wrapper.Header, "addTable");
|
||||
wrapper.addTable(new Table(1, 1));
|
||||
@ -26,4 +26,58 @@ describe("HeaderWrapper", () => {
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createTable", () => {
|
||||
it("should call the underlying header's createTable", () => {
|
||||
const wrapper = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(wrapper.Header, "createTable");
|
||||
wrapper.createTable(1, 1);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createParagraph", () => {
|
||||
it("should call the underlying header's createParagraph", () => {
|
||||
const file = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Header, "addParagraph");
|
||||
file.createParagraph();
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addImage", () => {
|
||||
it("should call the underlying header's addImage", () => {
|
||||
const file = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Header, "addParagraph");
|
||||
// tslint:disable-next-line:no-any
|
||||
file.addImage({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createImage", () => {
|
||||
it("should call the underlying header's createImage", () => {
|
||||
const file = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Media, "addMedia");
|
||||
const fileSpy = sinon.spy(file, "addImage");
|
||||
file.createImage("");
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
expect(fileSpy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addChildElement", () => {
|
||||
it("should call the underlying header's addChildElement", () => {
|
||||
const file = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.Header, "addChildElement");
|
||||
// tslint:disable-next-line:no-any
|
||||
file.addChildElement({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user