This commit is contained in:
Dolan
2017-03-09 22:56:08 +00:00
parent 5fac776dca
commit 7022b39d2e
21 changed files with 138 additions and 181 deletions

View File

@ -1,5 +1,5 @@
import { Attributes, XmlComponent } from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
export { Underline } from './underline'; export { Underline } from "./underline";
export class Bold extends XmlComponent { export class Bold extends XmlComponent {

View File

@ -18,9 +18,9 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
public toXml(): object { public toXml(): object {
const attrs = {}; const attrs = {};
if (this.root != undefined) { if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => { _.forOwn(this.root, (value, key) => {
if (value != undefined) { if (value !== undefined) {
const newKey = this.xmlKeys[key]; const newKey = this.xmlKeys[key];
attrs[newKey] = value; attrs[newKey] = value;
} }

View File

@ -1,2 +1,2 @@
export { LocalPacker } from "./packer/local"; export { LocalPacker } from "./packer/local";
export { ExpressPacker } from "./packer/express"; export { ExpressPacker } from "./packer/express";

View File

@ -5,7 +5,6 @@ import { Numbering } from "../../numbering";
import { Properties } from "../../properties"; import { Properties } from "../../properties";
import { Packer } from "./packer"; import { Packer } from "./packer";
export class ExpressPacker extends Packer { export class ExpressPacker extends Packer {
private res: express.Response; private res: express.Response;

View File

@ -15,7 +15,9 @@ export interface IStyleAttributes {
} }
class StyleAttributes extends XmlAttributeComponent { class StyleAttributes extends XmlAttributeComponent {
/* tslint:disable */
private _attr: IStyleAttributes; private _attr: IStyleAttributes;
/* tslint:enable */
constructor(properties: IStyleAttributes) { constructor(properties: IStyleAttributes) {
super({ super({

View File

@ -1,19 +1,15 @@
import { assert } from "chai"; import { assert } from "chai";
import { Utility } from "./utility";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("", () => { describe("", () => {
beforeEach(() => { beforeEach(() => {
// TODO
}); });
describe("#methodName()", () => { describe("#methodName()", () => {
it("should ", () => { it("should ", () => {
// TODO
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { LeftTabStop, MaxRightTabStop } from "../../../docx/paragraph/tab-stop";
import { assert } from "chai"; import { assert } from "chai";
import { LeftTabStop, MaxRightTabStop } from "../../../docx/paragraph/tab-stop";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("LeftTabStop", () => { describe("LeftTabStop", () => {
let tabStop: LeftTabStop; let tabStop: LeftTabStop;
@ -15,23 +11,23 @@ describe("LeftTabStop", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Tab Stop with correct attributes", () => { it("should create a Tab Stop with correct attributes", () => {
let newJson = jsonify(tabStop); const newJson = Utility.jsonify(tabStop);
let attributes = { const attributes = {
val: "left", val: "left",
pos: 100 pos: 100,
}; };
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
}); });
it("should create a Tab Stop with w:tab", () => { it("should create a Tab Stop with w:tab", () => {
let newJson = jsonify(tabStop); const newJson = Utility.jsonify(tabStop);
assert.equal(newJson.root[0].rootKey, "w:tab"); assert.equal(newJson.root[0].rootKey, "w:tab");
}); });
}); });
}); });
describe("RightTabStop", () => { describe("RightTabStop", () => {
// TODO
}); });
describe("MaxRightTabStop", () => { describe("MaxRightTabStop", () => {
@ -43,18 +39,18 @@ describe("MaxRightTabStop", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Tab Stop with correct attributes", () => { it("should create a Tab Stop with correct attributes", () => {
let newJson = jsonify(tabStop); const newJson = Utility.jsonify(tabStop);
let attributes = { const attributes = {
val: "right", val: "right",
pos: 9026 pos: 9026,
}; };
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
}); });
it("should create a Tab Stop with w:tab", () => { it("should create a Tab Stop with w:tab", () => {
let newJson = jsonify(tabStop); const newJson = Utility.jsonify(tabStop);
assert.equal(newJson.root[0].rootKey, "w:tab"); assert.equal(newJson.root[0].rootKey, "w:tab");
}); });
}); });
}); });

View File

@ -27,4 +27,4 @@ describe("NumberProperties", () => {
assert.equal(newJson.root[1].root[0].root.val, 5); assert.equal(newJson.root[1].root[0].root.val, 5);
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { Break } from "../../../docx/run/break";
import { assert } from "chai"; import { assert } from "chai";
import { Break } from "../../../docx/run/break";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Break", () => { describe("Break", () => {
let currentBreak: Break; let currentBreak: Break;
@ -15,8 +11,8 @@ describe("Break", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Break with correct root key", () => { it("should create a Break with correct root key", () => {
let newJson = jsonify(currentBreak); const newJson = Utility.jsonify(currentBreak);
assert.equal(newJson.rootKey, "w:br"); assert.equal(newJson.rootKey, "w:br");
}); });
}); });
}); });

View File

@ -2,10 +2,7 @@ import { assert, expect } from "chai";
import { Run } from "../../../docx/run"; import { Run } from "../../../docx/run";
import { TextRun } from "../../../docx/run/text-run"; import { TextRun } from "../../../docx/run/text-run";
import { Formatter } from "../../../export/formatter"; import { Formatter } from "../../../export/formatter";
import { Utility } from "../../utility";
function jsonify(obj: object) {
return JSON.parse(JSON.stringify(obj));
}
describe("Run", () => { describe("Run", () => {
let run: Run; let run: Run;
@ -17,7 +14,7 @@ describe("Run", () => {
describe("#bold()", () => { describe("#bold()", () => {
it("it should add bold to the properties", () => { it("it should add bold to the properties", () => {
run.bold(); run.bold();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b"); assert.equal(newJson.root[0].root[0].rootKey, "w:b");
}); });
}); });
@ -25,7 +22,7 @@ describe("Run", () => {
describe("#italic()", () => { describe("#italic()", () => {
it("it should add italics to the properties", () => { it("it should add italics to the properties", () => {
run.italic(); run.italic();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i"); assert.equal(newJson.root[0].root[0].rootKey, "w:i");
}); });
}); });
@ -33,7 +30,7 @@ describe("Run", () => {
describe("#underline()", () => { describe("#underline()", () => {
it("it should add underline to the properties", () => { it("it should add underline to the properties", () => {
run.underline(); run.underline();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:u"); assert.equal(newJson.root[0].root[0].rootKey, "w:u");
}); });
}); });
@ -41,7 +38,7 @@ describe("Run", () => {
describe("#smallCaps()", () => { describe("#smallCaps()", () => {
it("it should add smallCaps to the properties", () => { it("it should add smallCaps to the properties", () => {
run.smallCaps(); run.smallCaps();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps"); assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
}); });
}); });
@ -49,7 +46,7 @@ describe("Run", () => {
describe("#caps()", () => { describe("#caps()", () => {
it("it should add caps to the properties", () => { it("it should add caps to the properties", () => {
run.allCaps(); run.allCaps();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:caps"); assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
}); });
}); });
@ -57,7 +54,7 @@ describe("Run", () => {
describe("#strike()", () => { describe("#strike()", () => {
it("it should add strike to the properties", () => { it("it should add strike to the properties", () => {
run.strike(); run.strike();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:strike"); assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
}); });
}); });
@ -65,7 +62,7 @@ describe("Run", () => {
describe("#doubleStrike()", () => { describe("#doubleStrike()", () => {
it("it should add caps to the properties", () => { it("it should add caps to the properties", () => {
run.doubleStrike(); run.doubleStrike();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike"); assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
}); });
}); });
@ -73,7 +70,7 @@ describe("Run", () => {
describe("#break()", () => { describe("#break()", () => {
it("it should add break to the run", () => { it("it should add break to the run", () => {
run.break(); run.break();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[1].rootKey, "w:br"); assert.equal(newJson.root[1].rootKey, "w:br");
}); });
}); });
@ -81,7 +78,7 @@ describe("Run", () => {
describe("#tab()", () => { describe("#tab()", () => {
it("it should add break to the run", () => { it("it should add break to the run", () => {
run.tab(); run.tab();
const newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[1].rootKey, "w:tab"); assert.equal(newJson.root[1].rootKey, "w:tab");
}); });
}); });

View File

@ -1,10 +1,6 @@
import { SubScript, SuperScript } from "../../../docx/run/script";
import { assert } from "chai"; import { assert } from "chai";
import { SubScript, SuperScript } from "../../../docx/run/script";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("SubScript", () => { describe("SubScript", () => {
let subScript: SubScript; let subScript: SubScript;
@ -15,15 +11,15 @@ describe("SubScript", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Sub Script with correct attributes", () => { it("should create a Sub Script with correct attributes", () => {
let newJson = jsonify(subScript); const newJson = Utility.jsonify(subScript);
let attributes = { const attributes = {
val: "subscript" val: "subscript",
}; };
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes)); assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
}); });
it("should create a Sub Script with correct root key", () => { it("should create a Sub Script with correct root key", () => {
let newJson = jsonify(subScript); const newJson = Utility.jsonify(subScript);
assert.equal(newJson.rootKey, "w:vertAlign"); assert.equal(newJson.rootKey, "w:vertAlign");
}); });
}); });
@ -38,16 +34,16 @@ describe("SuperScript", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Super Script with correct attributes", () => { it("should create a Super Script with correct attributes", () => {
let newJson = jsonify(superScript); const newJson = Utility.jsonify(superScript);
let attributes = { const attributes = {
val: "superscript" val: "superscript",
}; };
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes)); assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
}); });
it("should create a Super Script with correct root key", () => { it("should create a Super Script with correct root key", () => {
let newJson = jsonify(superScript); const newJson = Utility.jsonify(superScript);
assert.equal(newJson.rootKey, "w:vertAlign"); assert.equal(newJson.rootKey, "w:vertAlign");
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { Strike, DoubleStrike } from "../../../docx/run/strike";
import { assert } from "chai"; import { assert } from "chai";
import { DoubleStrike, Strike } from "../../../docx/run/strike";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Strike", () => { describe("Strike", () => {
let strike: Strike; let strike: Strike;
@ -15,7 +11,7 @@ describe("Strike", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Strike with correct root key", () => { it("should create a Strike with correct root key", () => {
let newJson = jsonify(strike); const newJson = Utility.jsonify(strike);
assert.equal(newJson.rootKey, "w:strike"); assert.equal(newJson.rootKey, "w:strike");
}); });
}); });
@ -30,8 +26,8 @@ describe("DoubleStrike", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Double Strike with correct root key", () => { it("should create a Double Strike with correct root key", () => {
let newJson = jsonify(strike); const newJson = Utility.jsonify(strike);
assert.equal(newJson.rootKey, "w:dstrike"); assert.equal(newJson.rootKey, "w:dstrike");
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { Tab } from "../../../docx/run/tab";
import { assert } from "chai"; import { assert } from "chai";
import { Tab } from "../../../docx/run/tab";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Tab", () => { describe("Tab", () => {
let tab: Tab; let tab: Tab;
@ -15,8 +11,8 @@ describe("Tab", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Tab with correct root key", () => { it("should create a Tab with correct root key", () => {
let newJson = jsonify(tab); const newJson = Utility.jsonify(tab);
assert.equal(newJson.rootKey, "w:tab"); assert.equal(newJson.rootKey, "w:tab");
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { TextRun } from "../../../docx/run/text-run";
import { assert } from "chai"; import { assert } from "chai";
import { TextRun } from "../../../docx/run/text-run";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("TextRun", () => { describe("TextRun", () => {
let run: TextRun; let run: TextRun;
@ -13,8 +9,8 @@ describe("TextRun", () => {
it("should add text into run", () => { it("should add text into run", () => {
run = new TextRun("test"); run = new TextRun("test");
let newJson = jsonify(run); const newJson = Utility.jsonify(run);
assert.equal(newJson.root[1].root, "test"); assert.equal(newJson.root[1].root, "test");
}); });
}); });
}); });

View File

@ -1,13 +1,8 @@
import { assert, expect } from "chai"; import { assert, expect } from "chai";
import { TextRun } from "../../../docx/run/text-run"; import { TextRun } from "../../../docx/run/text-run";
import * as u from "../../../docx/run/underline"; import * as u from "../../../docx/run/underline";
import { Formatter } from "../../../export/formatter"; import { Formatter } from "../../../export/formatter";
import { Utility } from "../../utility";
function jsonify(obj: object) {
const stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Underline", () => { describe("Underline", () => {
@ -15,7 +10,7 @@ describe("Underline", () => {
it("should create a new Underline object with u:u as the rootKey", () => { it("should create a new Underline object with u:u as the rootKey", () => {
const underline = new u.Underline(); const underline = new u.Underline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.rootKey, "w:u"); assert.equal(newJson.rootKey, "w:u");
}); });
@ -42,13 +37,13 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should have u:u as the rootKey", () => { it("should have u:u as the rootKey", () => {
const underline = new u.DashDotDotHeavyUnderline(); const underline = new u.DashDotDotHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.rootKey, "w:u"); assert.equal(newJson.rootKey, "w:u");
}); });
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashDotDotHeavyUnderline(); const underline = new u.DashDotDotHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dashDotDotHeavy"); assert.equal(newJson.root[0].root.val, "dashDotDotHeavy");
}); });
}); });
@ -59,7 +54,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashDotHeavyUnderline(); const underline = new u.DashDotHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dashDotHeavy"); assert.equal(newJson.root[0].root.val, "dashDotHeavy");
}); });
}); });
@ -70,7 +65,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashLongHeavyUnderline(); const underline = new u.DashLongHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dashLongHeavy"); assert.equal(newJson.root[0].root.val, "dashLongHeavy");
}); });
}); });
@ -81,7 +76,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashLongUnderline(); const underline = new u.DashLongUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dashLong"); assert.equal(newJson.root[0].root.val, "dashLong");
}); });
}); });
@ -92,7 +87,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashUnderline(); const underline = new u.DashUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dash"); assert.equal(newJson.root[0].root.val, "dash");
}); });
}); });
@ -103,7 +98,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DotDashUnderline(); const underline = new u.DotDashUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dotDash"); assert.equal(newJson.root[0].root.val, "dotDash");
}); });
}); });
@ -114,7 +109,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DotDotDashUnderline(); const underline = new u.DotDotDashUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dotDotDash"); assert.equal(newJson.root[0].root.val, "dotDotDash");
}); });
}); });
@ -125,7 +120,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DottedHeavyUnderline(); const underline = new u.DottedHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dottedHeavy"); assert.equal(newJson.root[0].root.val, "dottedHeavy");
}); });
}); });
@ -136,7 +131,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DottedUnderline(); const underline = new u.DottedUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "dotted"); assert.equal(newJson.root[0].root.val, "dotted");
}); });
}); });
@ -147,7 +142,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DoubleUnderline(); const underline = new u.DoubleUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "double"); assert.equal(newJson.root[0].root.val, "double");
}); });
}); });
@ -158,7 +153,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.SingleUnderline(); const underline = new u.SingleUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "single"); assert.equal(newJson.root[0].root.val, "single");
}); });
}); });
@ -169,7 +164,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.ThickUnderline(); const underline = new u.ThickUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "thick"); assert.equal(newJson.root[0].root.val, "thick");
}); });
}); });
@ -180,7 +175,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WaveUnderline(); const underline = new u.WaveUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "wave"); assert.equal(newJson.root[0].root.val, "wave");
}); });
}); });
@ -191,7 +186,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WavyDoubleUnderline(); const underline = new u.WavyDoubleUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "wavyDouble"); assert.equal(newJson.root[0].root.val, "wavyDouble");
}); });
}); });
@ -202,7 +197,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WavyHeavyUnderline(); const underline = new u.WavyHeavyUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "wavyHeavy"); assert.equal(newJson.root[0].root.val, "wavyHeavy");
}); });
}); });
@ -213,7 +208,7 @@ describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WordsUnderline(); const underline = new u.WordsUnderline();
const newJson = jsonify(underline); const newJson = Utility.jsonify(underline);
assert.equal(newJson.root[0].root.val, "words"); assert.equal(newJson.root[0].root.val, "words");
}); });
}); });

View File

@ -1,5 +1,5 @@
import { Attributes } from "../../../docx/xml-components";
import { assert } from "chai"; import { assert } from "chai";
import { Attributes } from "../../../docx/xml-components";
describe("Attribute", () => { describe("Attribute", () => {
let attributes: Attributes; let attributes: Attributes;
@ -11,28 +11,28 @@ describe("Attribute", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should not add val with empty constructor", () => { it("should not add val with empty constructor", () => {
let newAttrs = new Attributes(); const newAttrs = new Attributes();
let stringifiedJson = JSON.stringify(newAttrs); const stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson); const newJson = JSON.parse(stringifiedJson);
assert.isUndefined(newJson.root.val); assert.isUndefined(newJson.root.val);
}); });
it("should have val as defined with populated constructor", () => { it("should have val as defined with populated constructor", () => {
let newAttrs = new Attributes({ const newAttrs = new Attributes({
val: "test" val: "test",
}); });
let stringifiedJson = JSON.stringify(newAttrs); const stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson); const newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.val, "test"); assert.equal(newJson.root.val, "test");
}); });
it("should have space value as defined with populated constructor", () => { it("should have space value as defined with populated constructor", () => {
let newAttrs = new Attributes({ const newAttrs = new Attributes({
space: "spaceTest" space: "spaceTest",
}); });
let stringifiedJson = JSON.stringify(newAttrs); const stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson); const newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.space, "spaceTest"); assert.equal(newJson.root.space, "spaceTest");
}); });
}); });
}); });

View File

@ -1,10 +1,6 @@
import { XmlComponent } from "../../../docx/xml-components";
import { assert } from "chai"; import { assert } from "chai";
import { XmlComponent } from "../../../docx/xml-components";
function jsonify(obj: Object) { import { Utility } from "../../utility";
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
class TestComponent extends XmlComponent { class TestComponent extends XmlComponent {
@ -20,7 +16,7 @@ describe("XmlComponent", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create an Xml Component which has the correct rootKey", () => { it("should create an Xml Component which has the correct rootKey", () => {
let newJson = jsonify(xmlComponent); const newJson = Utility.jsonify(xmlComponent);
assert.equal(newJson.rootKey, "w:test"); assert.equal(newJson.rootKey, "w:test");
}); });
}); });

View File

@ -4,11 +4,7 @@ import * as docx from "../../docx";
import { Attributes } from "../../docx/xml-components"; import { Attributes } from "../../docx/xml-components";
import { Formatter } from "../../export/formatter"; import { Formatter } from "../../export/formatter";
import { Properties } from "../../properties"; import { Properties } from "../../properties";
import { Utility } from "../utility";
function jsonify(obj: object): any {
const stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Formatter", () => { describe("Formatter", () => {
let formatter: Formatter; let formatter: Formatter;
@ -43,7 +39,7 @@ describe("Formatter", () => {
rsidSect: "test2", rsidSect: "test2",
}); });
let newJson = formatter.format(attributes); let newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = Utility.jsonify(newJson);
assert.isDefined(newJson._attr["w:rsidSect"]); assert.isDefined(newJson._attr["w:rsidSect"]);
}); });
@ -52,7 +48,7 @@ describe("Formatter", () => {
val: "test", val: "test",
}); });
let newJson = formatter.format(attributes); let newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = Utility.jsonify(newJson);
assert.isDefined(newJson._attr["w:val"]); assert.isDefined(newJson._attr["w:val"]);
}); });

View File

@ -1,38 +1,41 @@
import * as fs from "fs";
import { LocalPacker } from "../../export/packer/local";
import { Document } from "../../docx/document";
import { Properties } from "../../properties";
import { DefaultStyle } from "../../styles/sample";
import { Paragraph } from "../../docx/paragraph";
import { DefaultStylesFactory } from "../../styles/factory";
import { assert } from "chai"; import { assert } from "chai";
import * as fs from "fs";
import { Document } from "../../docx/document";
import { Paragraph } from "../../docx/paragraph";
import { LocalPacker } from "../../export/packer/local";
import { Properties } from "../../properties";
import { DefaultStylesFactory } from "../../styles/factory";
import { DefaultStyle } from "../../styles/sample";
describe("Packer", () => { describe("Packer", () => {
let packer: LocalPacker; let packer: LocalPacker;
let stylesFactory: DefaultStylesFactory; let stylesFactory: DefaultStylesFactory;
beforeEach(() => { beforeEach(() => {
let document = new Document(); const document = new Document();
let paragraph = new Paragraph("test text"); const paragraph = new Paragraph("test text");
let heading = new Paragraph("Hello world").heading1(); const heading = new Paragraph("Hello world").heading1();
document.addParagraph(new Paragraph("title").title()); document.addParagraph(new Paragraph("title").title());
document.addParagraph(heading); document.addParagraph(heading);
document.addParagraph(new Paragraph("heading 2").heading2()); document.addParagraph(new Paragraph("heading 2").heading2());
document.addParagraph(paragraph); document.addParagraph(paragraph);
let properties = new Properties({ const properties = new Properties({
creator: "Dolan Miu", creator: "Dolan Miu",
revision: "1", revision: "1",
lastModifiedBy: "Dolan Miu" lastModifiedBy: "Dolan Miu",
}); });
stylesFactory = new DefaultStylesFactory(); stylesFactory = new DefaultStylesFactory();
packer = new LocalPacker(document, stylesFactory.newInstance(), properties); packer = new LocalPacker(document, stylesFactory.newInstance(), properties);
}); });
describe("#pack()", () => { describe("#pack()", () => {
/* tslint:disable */
it("should create a standard docx file", function (done) { it("should create a standard docx file", function (done) {
/* tslint:enable */
this.timeout(99999999); this.timeout(99999999);
packer.pack("build-tests/tests/test.docx"); packer.pack("build-tests/tests/test.docx");
let int = setInterval(() => { const int = setInterval(() => {
const stats = fs.statSync("build-tests/tests/test.docx"); const stats = fs.statSync("build-tests/tests/test.docx");
if (stats.size > 2000) { if (stats.size > 2000) {
clearInterval(int); clearInterval(int);
@ -40,14 +43,14 @@ describe("Packer", () => {
done(); done();
} }
}, 1000); }, 1000);
let out = setTimeout(() => { const out = setTimeout(() => {
clearInterval(int); clearInterval(int);
try { try {
assert(false, 'did not create a file within the alloted time'); assert(false, "did not create a file within the alloted time");
} catch (e) { } catch (e) {
done(e); done(e);
} }
}, 2000); }, 2000);
}); });
}); });
}); });

View File

@ -4,13 +4,10 @@ import { Numbering } from "../numbering";
import { AbstractNumbering } from "../numbering/abstract-numbering"; import { AbstractNumbering } from "../numbering/abstract-numbering";
import { Num } from "../numbering/num"; import { Num } from "../numbering/num";
function jsonify(obj: object) {
return JSON.parse(JSON.stringify(obj));
}
describe("Numbering", () => { describe("Numbering", () => {
let numbering: Numbering; let numbering: Numbering;
beforeEach(() => { beforeEach(() => {
numbering = new Numbering(); numbering = new Numbering();
}); });
@ -22,8 +19,8 @@ describe("Numbering", () => {
const abstractNums = tree["w:numbering"].filter((el) => el["w:abstractNum"]); const abstractNums = tree["w:numbering"].filter((el) => el["w:abstractNum"]);
expect(abstractNums).to.have.lengthOf(1); expect(abstractNums).to.have.lengthOf(1);
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([ expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
{_attr: {"w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0}}, { _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } },
{"w:multiLevelType": [{_attr: {"w:val": "hybridMultilevel"}}]}, { "w:multiLevelType": [{ _attr: { "w:val": "hybridMultilevel" } }] },
]); ]);
abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => { abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => {
@ -32,10 +29,10 @@ describe("Numbering", () => {
"_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr", "_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr",
]); ]);
expect(el["w:lvl"]).to.have.deep.members([ expect(el["w:lvl"]).to.have.deep.members([
{_attr: {"w:ilvl": ix, "w15:tentative": 1}}, { _attr: { "w:ilvl": ix, "w15:tentative": 1 } },
{"w:start": [{_attr: {"w:val": 1}}]}, { "w:start": [{ _attr: { "w:val": 1 } }] },
{"w:lvlJc": [{_attr: {"w:val": "left"}}]}, { "w:lvlJc": [{ _attr: { "w:val": "left" } }] },
{"w:numFmt": [{_attr: {"w:val": "bullet"}}]}, { "w:numFmt": [{ _attr: { "w:val": "bullet" } }] },
]); ]);
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test: // Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
// {"w:lvlText": [{"_attr": {"w:val": "•"}}]}, // {"w:lvlText": [{"_attr": {"w:val": "•"}}]},
@ -65,8 +62,8 @@ describe("Numbering", () => {
const n = numbering.createConcreteNumbering(a2); const n = numbering.createConcreteNumbering(a2);
expect(n).to.be.instanceof(Num); expect(n).to.be.instanceof(Num);
const tree = new Formatter().format(numbering); const tree = new Formatter().format(numbering);
const serializedN = tree["w:numbering"].find( const serializedN = tree["w:numbering"].find((obj) =>
(obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id,
); );
expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id); expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id);
}); });
@ -91,22 +88,22 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end"); const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end");
const tree = new Formatter().format(level); const tree = new Formatter().format(level);
expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}}) expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]}) expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] });
expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "end"}}]}) expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "end" } }] });
expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]}) expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] });
expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]}) expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] });
}); });
it("uses 'start' as the default alignment", () => { it("uses 'start' as the default alignment", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)"); const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)");
const tree = new Formatter().format(level); const tree = new Formatter().format(level);
expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}}) expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]}) expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] });
expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "start"}}]}) expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "start" } }] });
expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]}) expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] });
expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]}) expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] });
}); });
}); });
}); });

View File

@ -1,5 +1,5 @@
export class Utility { export class Utility {
public static jsonify(obj: Object) { public static jsonify(obj: object): any {
const stringifiedJson = JSON.stringify(obj); const stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }