More tests
This commit is contained in:
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
||||
{
|
||||
"check-coverage": true,
|
||||
"lines": 87.17,
|
||||
"functions": 83.12,
|
||||
"branches": 71.22,
|
||||
"statements": 86.95,
|
||||
"lines": 87.39,
|
||||
"functions": 83.54,
|
||||
"branches": 71.95,
|
||||
"statements": 87.17,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
|
58
src/file/file.spec.ts
Normal file
58
src/file/file.spec.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
});
|
@ -1,3 +1,4 @@
|
||||
// tslint:disable:object-literal-key-quotes
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
@ -7,8 +8,7 @@ import { Media } from "./media";
|
||||
|
||||
describe("Media", () => {
|
||||
describe("#addImage", () => {
|
||||
it("Add image", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
it("should add image", () => {
|
||||
const file = new File();
|
||||
const image = Media.addImage(file, "");
|
||||
|
||||
@ -18,6 +18,34 @@ describe("Media", () => {
|
||||
tree = new Formatter().format(image.Run);
|
||||
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", () => {
|
||||
|
Reference in New Issue
Block a user