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

44 lines
1.5 KiB
TypeScript
Raw Normal View History

import { expect } from "chai";
2018-10-26 01:04:07 +01:00
import { Formatter } from "export/formatter";
import { Body } from "./body";
2016-03-31 23:01:20 +01:00
2016-04-03 05:24:56 +01:00
describe("Body", () => {
let body: Body;
2016-03-31 23:01:20 +01:00
beforeEach(() => {
body = new Body();
2016-03-31 23:01:20 +01:00
});
describe("#constructor()", () => {
it("should create default section", () => {
const formatted = new Formatter().format(body)["w:body"][0];
expect(formatted)
.to.have.property("w:sectPr")
.and.to.be.an.instanceof(Array);
2018-09-17 21:44:12 +01:00
expect(formatted["w:sectPr"]).to.have.length(5);
});
});
describe("addSection", () => {
it("should add section with options", () => {
body.addSection({
width: 10000,
height: 10000,
});
const formatted = new Formatter().format(body)["w:body"];
expect(formatted).to.be.an.instanceof(Array);
const defaultSectionPr = formatted[0]["w:p"][1]["w:pPr"][0]["w:sectPr"];
// check that this is the default section and added first in paragraph
expect(defaultSectionPr[0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
// check for new section (since it's the last one, it's direct child of body)
const newSection = formatted[1]["w:sectPr"];
expect(newSection[0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 10000, "w:w": 10000, "w:orient": "portrait" } }] });
});
});
2017-03-09 22:31:55 +00:00
});