Make .addSection fully declarative
This commit is contained in:
@ -1,38 +1,10 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { File, HeadingLevel, Media, Paragraph } from "file";
|
||||
import { Media } from "file";
|
||||
|
||||
import { ImageReplacer } from "./image-replacer";
|
||||
|
||||
describe("ImageReplacer", () => {
|
||||
let file: File;
|
||||
|
||||
beforeEach(() => {
|
||||
file = new File({
|
||||
creator: "Dolan Miu",
|
||||
revision: "1",
|
||||
lastModifiedBy: "Dolan Miu",
|
||||
});
|
||||
|
||||
file.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "title",
|
||||
heading: HeadingLevel.TITLE,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Hello world",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "heading 2",
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
}),
|
||||
new Paragraph("test text"),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe("#replace()", () => {
|
||||
it("should replace properly", () => {
|
||||
const imageReplacer = new ImageReplacer();
|
||||
|
@ -8,16 +8,17 @@ import { Compiler } from "./next-compiler";
|
||||
|
||||
describe("Compiler", () => {
|
||||
let compiler: Compiler;
|
||||
let file: File;
|
||||
|
||||
beforeEach(() => {
|
||||
file = new File();
|
||||
compiler = new Compiler();
|
||||
});
|
||||
|
||||
describe("#compile()", () => {
|
||||
it("should pack all the content", async function () {
|
||||
this.timeout(99999999);
|
||||
const file = new File({
|
||||
sections: [],
|
||||
});
|
||||
const zipFile = compiler.compile(file);
|
||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
|
||||
@ -38,24 +39,27 @@ describe("Compiler", () => {
|
||||
});
|
||||
|
||||
it("should pack all additional headers and footers", async function () {
|
||||
file.addSection({
|
||||
headers: {
|
||||
default: new Header(),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer(),
|
||||
},
|
||||
children: [],
|
||||
});
|
||||
|
||||
file.addSection({
|
||||
headers: {
|
||||
default: new Header(),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer(),
|
||||
},
|
||||
children: [],
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
headers: {
|
||||
default: new Header(),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer(),
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
default: new Header(),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer(),
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
this.timeout(99999999);
|
||||
@ -80,12 +84,15 @@ describe("Compiler", () => {
|
||||
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
const paragraph = new Paragraph("");
|
||||
const doc = new File();
|
||||
|
||||
doc.addSection({
|
||||
properties: {},
|
||||
children: [paragraph],
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [paragraph],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: no-string-literal
|
||||
const spy = sinon.spy(compiler["formatter"], "format");
|
||||
|
||||
|
@ -14,23 +14,24 @@ describe("Packer", () => {
|
||||
creator: "Dolan Miu",
|
||||
revision: "1",
|
||||
lastModifiedBy: "Dolan Miu",
|
||||
});
|
||||
|
||||
file.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "title",
|
||||
heading: HeadingLevel.TITLE,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Hello world",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "heading 2",
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
}),
|
||||
new Paragraph("test text"),
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "title",
|
||||
heading: HeadingLevel.TITLE,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Hello world",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "heading 2",
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
}),
|
||||
new Paragraph("test text"),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user