Merge pull request #189 from dolanmiu/feat/more-tests

More tests
This commit is contained in:
Dolan
2018-11-02 00:53:54 +00:00
committed by GitHub
3 changed files with 92 additions and 6 deletions

8
.nycrc
View File

@ -1,9 +1,9 @@
{ {
"check-coverage": true, "check-coverage": true,
"lines": 87.17, "lines": 87.39,
"functions": 83.12, "functions": 83.54,
"branches": 71.22, "branches": 71.95,
"statements": 86.95, "statements": 87.17,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],

58
src/file/file.spec.ts Normal file
View File

@ -0,0 +1,58 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { File } from "./file";
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");
});
});
});

View File

@ -1,3 +1,4 @@
// tslint:disable:object-literal-key-quotes
import { expect } from "chai"; import { expect } from "chai";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
@ -7,8 +8,7 @@ import { Media } from "./media";
describe("Media", () => { describe("Media", () => {
describe("#addImage", () => { describe("#addImage", () => {
it("Add image", () => { it("should add image", () => {
// tslint:disable-next-line:no-any
const file = new File(); const file = new File();
const image = Media.addImage(file, ""); const image = Media.addImage(file, "");
@ -18,6 +18,34 @@ describe("Media", () => {
tree = new Formatter().format(image.Run); tree = new Formatter().format(image.Run);
expect(tree["w:r"]).to.be.an.instanceof(Array); expect(tree["w:r"]).to.be.an.instanceof(Array);
}); });
it("should ensure the correct relationship id is used when adding image", () => {
const file = new File();
const image1 = Media.addImage(file, "test");
const tree = new Formatter().format(image1.Paragraph);
const inlineElements = tree["w:p"][1]["w:r"][1]["w:drawing"][0]["wp:inline"];
const graphicData = inlineElements.find((x) => x["a:graphic"]);
expect(graphicData["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"][0]).to.deep.equal({
_attr: {
"r:embed": `rId${file.DocumentRelationships.RelationshipCount}`,
cstate: "none",
},
});
const image2 = Media.addImage(file, "test");
const tree2 = new Formatter().format(image2.Paragraph);
const inlineElements2 = tree2["w:p"][1]["w:r"][1]["w:drawing"][0]["wp:inline"];
const graphicData2 = inlineElements2.find((x) => x["a:graphic"]);
expect(graphicData2["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"][0]).to.deep.equal({
_attr: {
"r:embed": `rId${file.DocumentRelationships.RelationshipCount}`,
cstate: "none",
},
});
});
}); });
describe("#addMedia", () => { describe("#addMedia", () => {