Files
docx-js/src/file/file.spec.ts

82 lines
2.9 KiB
TypeScript
Raw Normal View History

2018-11-02 00:42:49 +00:00
import { expect } from "chai";
2018-12-16 01:56:42 +00:00
import * as sinon from "sinon";
2018-11-02 00:42:49 +00:00
import { Formatter } from "export/formatter";
import { File } from "./file";
2018-12-16 01:56:42 +00:00
import { Paragraph } from "./paragraph";
import { Table } from "./table";
2018-11-02 00:42:49 +00:00
describe("File", () => {
describe("#constructor", () => {
it("should create with correct headers", () => {
const doc = new File();
const header = doc.createHeader();
const footer = doc.createFooter();
doc.addSection({
headers: {
default: header,
},
footers: {
default: 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("default");
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"][0]._attr["w:type"]).to.equal("default");
});
it("should create with correct headers", () => {
const doc = new File();
const header = doc.createHeader();
const footer = doc.createFooter();
doc.addSection({
headers: {
default: header,
first: header,
even: header,
},
footers: {
default: footer,
first: footer,
even: 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("default");
expect(tree["w:body"][1]["w:sectPr"][5]["w:headerReference"][0]._attr["w:type"]).to.equal("first");
expect(tree["w:body"][1]["w:sectPr"][6]["w:headerReference"][0]._attr["w:type"]).to.equal("even");
expect(tree["w:body"][1]["w:sectPr"][7]["w:footerReference"][0]._attr["w:type"]).to.equal("default");
expect(tree["w:body"][1]["w:sectPr"][8]["w:footerReference"][0]._attr["w:type"]).to.equal("first");
expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"][0]._attr["w:type"]).to.equal("even");
});
});
2018-12-16 01:56:42 +00:00
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);
});
});
2018-11-02 00:42:49 +00:00
});