2016-03-28 00:53:24 +01:00
|
|
|
/// <reference path="../typings/mocha/mocha.d.ts" />
|
|
|
|
/// <reference path="../typings/lodash/lodash.d.ts" />
|
2016-03-31 05:30:37 +01:00
|
|
|
/// <reference path="../typings/chai/chai.d.ts" />
|
2016-03-28 00:53:24 +01:00
|
|
|
|
|
|
|
import {Formatter} from "../export/Formatter";
|
2016-03-31 05:28:19 +01:00
|
|
|
import * as docx from "../docx";
|
2016-04-03 05:23:13 +01:00
|
|
|
import {Attributes} from "../docx/xml-components";
|
|
|
|
|
2016-03-31 05:30:37 +01:00
|
|
|
import {assert} from "chai";
|
2016-03-31 05:28:19 +01:00
|
|
|
|
|
|
|
function jsonify(obj: Object) {
|
|
|
|
var stringifiedJson = JSON.stringify(obj);
|
|
|
|
return JSON.parse(stringifiedJson);
|
|
|
|
}
|
2016-03-28 00:53:24 +01:00
|
|
|
|
2016-04-03 05:24:56 +01:00
|
|
|
describe.only("Formatter", () => {
|
2016-03-28 00:53:24 +01:00
|
|
|
var formatter: Formatter;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
formatter = new Formatter();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#format()', () => {
|
2016-04-03 05:23:13 +01:00
|
|
|
it("should format simple paragraph", () => {
|
|
|
|
var paragraph = new docx.Paragraph();
|
|
|
|
var newJson = formatter.format(paragraph);
|
|
|
|
newJson = jsonify(newJson);
|
|
|
|
assert.isDefined(newJson["w:p"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should format simple paragraph with bold text", () => {
|
2016-03-31 05:28:19 +01:00
|
|
|
var paragraph = new docx.Paragraph();
|
2016-04-03 05:23:13 +01:00
|
|
|
paragraph.addText(new docx.TextRun("test").bold());
|
2016-03-31 05:28:19 +01:00
|
|
|
var newJson = formatter.format(paragraph);
|
|
|
|
newJson = jsonify(newJson);
|
2016-04-03 05:23:13 +01:00
|
|
|
assert.isDefined(newJson["w:p"][3]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attrs"]["w:val"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should format attributes (rsidSect)", () => {
|
|
|
|
var attributes = new Attributes({
|
|
|
|
rsidSect: "test2"
|
|
|
|
});
|
|
|
|
var newJson = formatter.format(attributes);
|
|
|
|
newJson = jsonify(newJson);
|
|
|
|
assert.isDefined(newJson["_attrs"]["w:rsidSect"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should format attributes (val)", () => {
|
|
|
|
var attributes = new Attributes({
|
|
|
|
val: "test"
|
|
|
|
});
|
|
|
|
var newJson = formatter.format(attributes);
|
|
|
|
newJson = jsonify(newJson);
|
|
|
|
assert.isDefined(newJson["_attrs"]["w:val"]);
|
2016-03-31 04:33:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should should change 'p' tag into 'w:p' tag", () => {
|
2016-04-03 05:23:13 +01:00
|
|
|
var newJson = formatter.format({ "p": "test", "xmlKeys": { "p": "w:p" } });
|
2016-03-31 05:30:37 +01:00
|
|
|
assert.isDefined(newJson["w:p"]);
|
2016-03-28 00:53:24 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|