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

118 lines
3.6 KiB
TypeScript
Raw Normal View History

2016-03-29 04:10:33 +01:00
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import * as docx from "../docx";
import {assert} from "chai";
2016-03-30 03:58:53 +01:00
function jsonify(obj: Object) {
2016-05-26 15:08:34 +01:00
let stringifiedJson = JSON.stringify(obj);
2016-03-30 03:58:53 +01:00
return JSON.parse(stringifiedJson);
}
2016-04-03 05:24:56 +01:00
describe("Paragraph", () => {
2016-05-26 15:08:34 +01:00
let paragraph: docx.Paragraph;
2016-03-29 04:10:33 +01:00
beforeEach(() => {
paragraph = new docx.Paragraph();
});
2016-05-26 15:08:34 +01:00
describe("#constructor()", () => {
2016-03-29 04:10:33 +01:00
it("should create valid JSON", () => {
2016-05-26 15:08:34 +01:00
let stringifiedJson = JSON.stringify(paragraph);
let newJson;
2016-03-29 04:10:33 +01:00
try {
newJson = JSON.parse(stringifiedJson);
} catch (e) {
assert.isTrue(false);
}
assert.isTrue(true);
});
it("should create have valid properties", () => {
2016-05-26 15:08:34 +01:00
let stringifiedJson = JSON.stringify(paragraph);
let newJson = JSON.parse(stringifiedJson);
2016-05-09 21:50:46 +01:00
assert.equal(newJson.root[0].rootKey, "w:pPr");
});
2016-03-29 04:10:33 +01:00
});
describe("#heading1()", () => {
it("should add heading style to JSON", () => {
paragraph.heading1();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
2016-03-29 04:10:33 +01:00
});
});
describe("#heading2()", () => {
it("should add heading style to JSON", () => {
paragraph.heading2();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-03-29 04:10:33 +01:00
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
2016-03-29 04:10:33 +01:00
});
});
describe("#heading3()", () => {
it("should add heading style to JSON", () => {
paragraph.heading3();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-03-29 04:10:33 +01:00
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
2016-03-29 04:10:33 +01:00
});
});
describe("#title()", () => {
it("should add title style to JSON", () => {
paragraph.title();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-03-29 04:10:33 +01:00
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
2016-03-29 04:10:33 +01:00
});
});
2016-03-29 04:50:23 +01:00
describe("#center()", () => {
it("should add center alignment to JSON", () => {
paragraph.center();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-03-29 04:50:23 +01:00
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
2016-03-29 04:50:23 +01:00
});
});
2016-03-29 05:01:33 +01:00
2016-03-29 23:36:57 +01:00
describe("#thematicBreak()", () => {
2016-03-29 05:01:33 +01:00
it("should add thematic break to JSON", () => {
2016-03-29 23:36:57 +01:00
paragraph.thematicBreak();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
2016-03-29 05:01:33 +01:00
});
});
2016-03-30 00:28:05 +01:00
describe("#pageBreak()", () => {
it("should add page break to JSON", () => {
paragraph.pageBreak();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
2016-03-30 00:28:05 +01:00
});
it("should add page break with 'page' type", () => {
paragraph.pageBreak();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
2016-03-30 00:28:05 +01:00
});
});
2016-03-30 02:55:11 +01:00
describe("#bullet()", () => {
it("should add list paragraph style to JSON", () => {
paragraph.bullet();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
2016-03-30 02:55:11 +01:00
});
it("it should add numbered properties", () => {
paragraph.bullet();
2016-05-26 15:08:34 +01:00
let newJson = jsonify(paragraph);
2016-05-01 22:24:20 +01:00
assert.isDefined(newJson.root[0].root[2]);
2016-03-30 02:55:11 +01:00
});
});
2016-03-29 04:10:33 +01:00
});