Add more tests
This commit is contained in:
@ -9,7 +9,7 @@ import { Table } from "./table";
|
|||||||
|
|
||||||
describe("File", () => {
|
describe("File", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create with correct headers", () => {
|
it("should create with correct headers and footers", () => {
|
||||||
const doc = new File();
|
const doc = new File();
|
||||||
const header = doc.createHeader();
|
const header = doc.createHeader();
|
||||||
const footer = doc.createFooter();
|
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");
|
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", () => {
|
it("should create with correct headers", () => {
|
||||||
const doc = new File();
|
const doc = new File();
|
||||||
const header = doc.createHeader();
|
const header = doc.createHeader();
|
||||||
@ -60,7 +80,7 @@ describe("File", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#addParagraph", () => {
|
describe("#addParagraph", () => {
|
||||||
it("should call the underlying header's addParagraph", () => {
|
it("should call the underlying document's addParagraph", () => {
|
||||||
const file = new File();
|
const file = new File();
|
||||||
const spy = sinon.spy(file.Document, "addParagraph");
|
const spy = sinon.spy(file.Document, "addParagraph");
|
||||||
file.addParagraph(new Paragraph());
|
file.addParagraph(new Paragraph());
|
||||||
@ -70,7 +90,7 @@ describe("File", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#addTable", () => {
|
describe("#addTable", () => {
|
||||||
it("should call the underlying header's addParagraph", () => {
|
it("should call the underlying document's addTable", () => {
|
||||||
const wrapper = new File();
|
const wrapper = new File();
|
||||||
const spy = sinon.spy(wrapper.Document, "addTable");
|
const spy = sinon.spy(wrapper.Document, "addTable");
|
||||||
wrapper.addTable(new Table(1, 1));
|
wrapper.addTable(new Table(1, 1));
|
||||||
@ -78,4 +98,68 @@ describe("File", () => {
|
|||||||
expect(spy.called).to.equal(true);
|
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) {
|
for (const header of headers) {
|
||||||
switch (header.type) {
|
switch (header.type) {
|
||||||
case HeaderReferenceType.DEFAULT:
|
|
||||||
newGroup = {
|
|
||||||
...newGroup,
|
|
||||||
default: header.header,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case HeaderReferenceType.FIRST:
|
case HeaderReferenceType.FIRST:
|
||||||
newGroup = {
|
newGroup = {
|
||||||
...newGroup,
|
...newGroup,
|
||||||
@ -299,6 +293,7 @@ export class File {
|
|||||||
even: header.header,
|
even: header.header,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case HeaderReferenceType.DEFAULT:
|
||||||
default:
|
default:
|
||||||
newGroup = {
|
newGroup = {
|
||||||
...newGroup,
|
...newGroup,
|
||||||
@ -316,12 +311,6 @@ export class File {
|
|||||||
|
|
||||||
for (const footer of footers) {
|
for (const footer of footers) {
|
||||||
switch (footer.type) {
|
switch (footer.type) {
|
||||||
case FooterReferenceType.DEFAULT:
|
|
||||||
newGroup = {
|
|
||||||
...newGroup,
|
|
||||||
default: footer.footer,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case FooterReferenceType.FIRST:
|
case FooterReferenceType.FIRST:
|
||||||
newGroup = {
|
newGroup = {
|
||||||
...newGroup,
|
...newGroup,
|
||||||
@ -334,6 +323,7 @@ export class File {
|
|||||||
even: footer.footer,
|
even: footer.footer,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case FooterReferenceType.DEFAULT:
|
||||||
default:
|
default:
|
||||||
newGroup = {
|
newGroup = {
|
||||||
...newGroup,
|
...newGroup,
|
||||||
|
@ -26,4 +26,58 @@ describe("FooterWrapper", () => {
|
|||||||
expect(spy.called).to.equal(true);
|
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", () => {
|
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 wrapper = new HeaderWrapper(new Media(), 1);
|
||||||
const spy = sinon.spy(wrapper.Header, "addTable");
|
const spy = sinon.spy(wrapper.Header, "addTable");
|
||||||
wrapper.addTable(new Table(1, 1));
|
wrapper.addTable(new Table(1, 1));
|
||||||
@ -26,4 +26,58 @@ describe("HeaderWrapper", () => {
|
|||||||
expect(spy.called).to.equal(true);
|
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