Files
docx-js/ts/tests/bodyTest.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-03-31 23:01:20 +01:00
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import {Body} from "../docx/document/body";
import {assert} from "chai";
2016-04-09 04:53:42 +01:00
import {SectionProperties} from "../docx/document/body/section-properties";
import {PageSize} from "../docx/document/body/page-size";
import {PageMargin} from "../docx/document/body/page-margin";
import {Columns} from "../docx/document/body/columns";
import {DocumentGrid} from "../docx/document/body/doc-grid";
2016-03-31 23:01:20 +01:00
function jsonify(obj: Object) {
2016-05-26 15:08:34 +01:00
let stringifiedJson = JSON.stringify(obj);
2016-03-31 23:01:20 +01:00
return JSON.parse(stringifiedJson);
}
2016-04-03 05:24:56 +01:00
describe("Body", () => {
2016-05-26 15:08:34 +01:00
let body: Body;
2016-03-31 23:01:20 +01:00
beforeEach(() => {
body = new Body();
2016-04-09 04:53:42 +01:00
body.push(new SectionProperties());
body.push(new PageSize());
body.push(new PageMargin());
body.push(new Columns());
body.push(new DocumentGrid());
2016-03-31 23:01:20 +01:00
});
2016-04-04 17:30:29 +01:00
describe("#constructor()", () => {
2016-04-01 00:22:44 +01:00
it("should create the Section Properties", () => {
2016-05-26 15:08:34 +01:00
let newJson = jsonify(body);
2016-05-02 22:39:03 +01:00
assert.equal(newJson.root[0].rootKey, "w:sectPr");
2016-04-01 00:22:44 +01:00
});
it("should create the Page Size", () => {
2016-05-26 15:08:34 +01:00
let newJson = jsonify(body);
2016-05-02 22:39:03 +01:00
assert.equal(newJson.root[1].rootKey, "w:pgSz");
2016-04-01 00:22:44 +01:00
});
it("should create the Page Margin", () => {
2016-05-26 15:08:34 +01:00
let newJson = jsonify(body);
2016-05-02 22:39:03 +01:00
assert.equal(newJson.root[2].rootKey, "w:pgMar");
2016-04-01 00:22:44 +01:00
});
it("should create the Columns", () => {
2016-05-26 15:08:34 +01:00
let newJson = jsonify(body);
2016-05-02 22:39:03 +01:00
assert.equal(newJson.root[3].rootKey, "w:cols");
2016-04-01 00:22:44 +01:00
});
it("should create the Document Grid", () => {
2016-05-26 15:08:34 +01:00
let newJson = jsonify(body);
2016-05-02 22:39:03 +01:00
assert.equal(newJson.root[4].rootKey, "w:docGrid");
});
2016-03-31 23:01:20 +01:00
});
});