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";
export { Underline } from './underline';
export { Underline } from "./underline";
export class Bold extends XmlComponent {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,10 +2,7 @@ import { assert, expect } from "chai";
import { Run } from "../../../docx/run";
import { TextRun } from "../../../docx/run/text-run";
import { Formatter } from "../../../export/formatter";
function jsonify(obj: object) {
return JSON.parse(JSON.stringify(obj));
}
import { Utility } from "../../utility";
describe("Run", () => {
let run: Run;
@ -17,7 +14,7 @@ describe("Run", () => {
describe("#bold()", () => {
it("it should add bold to the properties", () => {
run.bold();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
});
});
@ -25,7 +22,7 @@ describe("Run", () => {
describe("#italic()", () => {
it("it should add italics to the properties", () => {
run.italic();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
});
});
@ -33,7 +30,7 @@ describe("Run", () => {
describe("#underline()", () => {
it("it should add underline to the properties", () => {
run.underline();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
});
});
@ -41,7 +38,7 @@ describe("Run", () => {
describe("#smallCaps()", () => {
it("it should add smallCaps to the properties", () => {
run.smallCaps();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
});
});
@ -49,7 +46,7 @@ describe("Run", () => {
describe("#caps()", () => {
it("it should add caps to the properties", () => {
run.allCaps();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
});
});
@ -57,7 +54,7 @@ describe("Run", () => {
describe("#strike()", () => {
it("it should add strike to the properties", () => {
run.strike();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
});
});
@ -65,7 +62,7 @@ describe("Run", () => {
describe("#doubleStrike()", () => {
it("it should add caps to the properties", () => {
run.doubleStrike();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
});
});
@ -73,7 +70,7 @@ describe("Run", () => {
describe("#break()", () => {
it("it should add break to the run", () => {
run.break();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
assert.equal(newJson.root[1].rootKey, "w:br");
});
});
@ -81,7 +78,7 @@ describe("Run", () => {
describe("#tab()", () => {
it("it should add break to the run", () => {
run.tab();
const newJson = jsonify(run);
const newJson = Utility.jsonify(run);
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";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
import { SubScript, SuperScript } from "../../../docx/run/script";
import { Utility } from "../../utility";
describe("SubScript", () => {
let subScript: SubScript;
@ -15,15 +11,15 @@ describe("SubScript", () => {
describe("#constructor()", () => {
it("should create a Sub Script with correct attributes", () => {
let newJson = jsonify(subScript);
let attributes = {
val: "subscript"
const newJson = Utility.jsonify(subScript);
const attributes = {
val: "subscript",
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
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");
});
});
@ -38,15 +34,15 @@ describe("SuperScript", () => {
describe("#constructor()", () => {
it("should create a Super Script with correct attributes", () => {
let newJson = jsonify(superScript);
let attributes = {
val: "superscript"
const newJson = Utility.jsonify(superScript);
const attributes = {
val: "superscript",
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
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");
});
});

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,6 @@
import { XmlComponent } from "../../../docx/xml-components";
import { assert } from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
import { XmlComponent } from "../../../docx/xml-components";
import { Utility } from "../../utility";
class TestComponent extends XmlComponent {
@ -20,7 +16,7 @@ describe("XmlComponent", () => {
describe("#constructor()", () => {
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");
});
});

View File

@ -4,11 +4,7 @@ import * as docx from "../../docx";
import { Attributes } from "../../docx/xml-components";
import { Formatter } from "../../export/formatter";
import { Properties } from "../../properties";
function jsonify(obj: object): any {
const stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
import { Utility } from "../utility";
describe("Formatter", () => {
let formatter: Formatter;
@ -43,7 +39,7 @@ describe("Formatter", () => {
rsidSect: "test2",
});
let newJson = formatter.format(attributes);
newJson = jsonify(newJson);
newJson = Utility.jsonify(newJson);
assert.isDefined(newJson._attr["w:rsidSect"]);
});
@ -52,7 +48,7 @@ describe("Formatter", () => {
val: "test",
});
let newJson = formatter.format(attributes);
newJson = jsonify(newJson);
newJson = Utility.jsonify(newJson);
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 * 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", () => {
let packer: LocalPacker;
let stylesFactory: DefaultStylesFactory;
beforeEach(() => {
let document = new Document();
let paragraph = new Paragraph("test text");
let heading = new Paragraph("Hello world").heading1();
const document = new Document();
const paragraph = new Paragraph("test text");
const heading = new Paragraph("Hello world").heading1();
document.addParagraph(new Paragraph("title").title());
document.addParagraph(heading);
document.addParagraph(new Paragraph("heading 2").heading2());
document.addParagraph(paragraph);
let properties = new Properties({
const properties = new Properties({
creator: "Dolan Miu",
revision: "1",
lastModifiedBy: "Dolan Miu"
lastModifiedBy: "Dolan Miu",
});
stylesFactory = new DefaultStylesFactory();
packer = new LocalPacker(document, stylesFactory.newInstance(), properties);
});
describe("#pack()", () => {
/* tslint:disable */
it("should create a standard docx file", function (done) {
/* tslint:enable */
this.timeout(99999999);
packer.pack("build-tests/tests/test.docx");
let int = setInterval(() => {
const int = setInterval(() => {
const stats = fs.statSync("build-tests/tests/test.docx");
if (stats.size > 2000) {
clearInterval(int);
@ -40,10 +43,10 @@ describe("Packer", () => {
done();
}
}, 1000);
let out = setTimeout(() => {
const out = setTimeout(() => {
clearInterval(int);
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) {
done(e);
}

View File

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

View File

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