2016-07-01 22:09:55 +01:00
|
|
|
/// <reference path="../../typings/mocha/mocha.d.ts" />
|
|
|
|
/// <reference path="../../typings/lodash/lodash.d.ts" />
|
|
|
|
/// <reference path="../../typings/chai/chai.d.ts" />
|
2016-04-03 05:23:13 +01:00
|
|
|
|
2017-03-07 12:46:42 +01:00
|
|
|
import {Formatter} from "../../export/formatter";
|
2016-07-01 22:09:55 +01:00
|
|
|
import * as docx from "../../docx";
|
|
|
|
import {Attributes} from "../../docx/xml-components";
|
|
|
|
import {Properties} from "../../properties";
|
2016-03-31 05:30:37 +01:00
|
|
|
import {assert} from "chai";
|
2016-03-31 05:28:19 +01:00
|
|
|
|
|
|
|
function jsonify(obj: Object) {
|
2016-05-26 15:08:34 +01:00
|
|
|
let stringifiedJson = JSON.stringify(obj);
|
2016-03-31 05:28:19 +01:00
|
|
|
return JSON.parse(stringifiedJson);
|
|
|
|
}
|
2016-03-28 00:53:24 +01:00
|
|
|
|
2016-04-03 20:00:30 +01:00
|
|
|
describe("Formatter", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let formatter: Formatter;
|
2016-03-28 00:53:24 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
formatter = new Formatter();
|
|
|
|
});
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
describe("#format()", () => {
|
2016-04-03 05:23:13 +01:00
|
|
|
it("should format simple paragraph", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let paragraph = new docx.Paragraph();
|
|
|
|
let newJson = formatter.format(paragraph);
|
2016-04-03 05:23:13 +01:00
|
|
|
newJson = jsonify(newJson);
|
|
|
|
assert.isDefined(newJson["w:p"]);
|
|
|
|
});
|
|
|
|
|
2016-04-05 01:49:12 +01:00
|
|
|
it("should remove xmlKeys", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let paragraph = new docx.Paragraph();
|
|
|
|
let newJson = formatter.format(paragraph);
|
|
|
|
let stringifiedJson = JSON.stringify(newJson);
|
2016-04-05 01:49:12 +01:00
|
|
|
assert(stringifiedJson.indexOf("xmlKeys") < 0);
|
|
|
|
});
|
|
|
|
|
2016-05-01 22:24:20 +01:00
|
|
|
it("should format simple paragraph with bold text", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let paragraph = new docx.Paragraph();
|
2016-04-03 05:23:13 +01:00
|
|
|
paragraph.addText(new docx.TextRun("test").bold());
|
2016-05-26 15:08:34 +01:00
|
|
|
let newJson = formatter.format(paragraph);
|
2016-03-31 05:28:19 +01:00
|
|
|
newJson = jsonify(newJson);
|
2016-04-25 01:11:06 +01:00
|
|
|
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
|
2016-04-03 05:23:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should format attributes (rsidSect)", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let attributes = new Attributes({
|
2016-04-03 05:23:13 +01:00
|
|
|
rsidSect: "test2"
|
|
|
|
});
|
2016-05-26 15:08:34 +01:00
|
|
|
let newJson = formatter.format(attributes);
|
2016-04-03 05:23:13 +01:00
|
|
|
newJson = jsonify(newJson);
|
2016-04-09 04:53:42 +01:00
|
|
|
assert.isDefined(newJson["_attr"]["w:rsidSect"]);
|
2016-04-03 05:23:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should format attributes (val)", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let attributes = new Attributes({
|
2016-04-03 05:23:13 +01:00
|
|
|
val: "test"
|
|
|
|
});
|
2016-05-26 15:08:34 +01:00
|
|
|
let newJson = formatter.format(attributes);
|
2016-04-03 05:23:13 +01:00
|
|
|
newJson = jsonify(newJson);
|
2016-04-09 04:53:42 +01:00
|
|
|
assert.isDefined(newJson["_attr"]["w:val"]);
|
2016-03-31 04:33:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should should change 'p' tag into 'w:p' tag", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let paragraph = new docx.Paragraph();
|
|
|
|
let newJson = formatter.format(paragraph);
|
2016-03-31 05:30:37 +01:00
|
|
|
assert.isDefined(newJson["w:p"]);
|
2016-03-28 00:53:24 +01:00
|
|
|
});
|
2016-04-04 17:30:29 +01:00
|
|
|
|
2016-04-05 01:49:12 +01:00
|
|
|
it("should format Properties object correctly", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let properties = new Properties({
|
2016-04-04 17:30:29 +01:00
|
|
|
title: "test document",
|
|
|
|
creator: "Dolan"
|
|
|
|
});
|
2016-05-26 15:08:34 +01:00
|
|
|
let newJson = formatter.format(properties);
|
2016-04-04 17:30:29 +01:00
|
|
|
newJson = jsonify(newJson);
|
2016-04-05 01:49:12 +01:00
|
|
|
assert.isDefined(newJson["cp:coreProperties"]);
|
2016-04-04 17:30:29 +01:00
|
|
|
});
|
2016-03-28 00:53:24 +01:00
|
|
|
});
|
|
|
|
});
|