diff --git a/src/file/drawing/floating/align.spec.ts b/src/file/drawing/floating/align.spec.ts index a44ab7039b..906aa8732f 100644 --- a/src/file/drawing/floating/align.spec.ts +++ b/src/file/drawing/floating/align.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { Align } from "./align"; import { VerticalPositionAlign } from "./floating-position"; @@ -8,9 +8,10 @@ import { VerticalPositionAlign } from "./floating-position"; describe("Align", () => { describe("#constructor()", () => { it("should create a element with correct root key", () => { - const newJson = Utility.jsonify(new Align(VerticalPositionAlign.CENTER)); - assert.equal(newJson.rootKey, "wp:align"); - assert.include(newJson.root[0], VerticalPositionAlign.CENTER); + const tree = new Formatter().format(new Align(VerticalPositionAlign.CENTER)); + expect(tree).to.deep.equal({ + "wp:align": ["center"], + }); }); }); }); diff --git a/src/file/drawing/floating/position-offset.spec.ts b/src/file/drawing/floating/position-offset.spec.ts index 237490f9f2..f3fb6c35af 100644 --- a/src/file/drawing/floating/position-offset.spec.ts +++ b/src/file/drawing/floating/position-offset.spec.ts @@ -1,15 +1,16 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { PositionOffset } from "./position-offset"; describe("PositionOffset", () => { describe("#constructor()", () => { it("should create a element with correct root key", () => { - const newJson = Utility.jsonify(new PositionOffset(50)); - assert.equal(newJson.rootKey, "wp:posOffset"); - assert.equal(newJson.root[0], 50); + const tree = new Formatter().format(new PositionOffset(50)); + expect(tree).to.deep.equal({ + "wp:posOffset": ["50"], + }); }); }); }); diff --git a/src/file/drawing/floating/simple-pos.spec.ts b/src/file/drawing/floating/simple-pos.spec.ts index 32218b7a33..395781a358 100644 --- a/src/file/drawing/floating/simple-pos.spec.ts +++ b/src/file/drawing/floating/simple-pos.spec.ts @@ -1,17 +1,20 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { SimplePos } from "./simple-pos"; describe("SimplePos", () => { describe("#constructor()", () => { it("should create a element with correct root key", () => { - const newJson = Utility.jsonify(new SimplePos()); - assert.equal(newJson.rootKey, "wp:simplePos"); - assert.include(newJson.root[0].root, { - x: 0, - y: 0, + const tree = new Formatter().format(new SimplePos()); + expect(tree).to.deep.equal({ + "wp:simplePos": { + _attr: { + x: 0, + y: 0, + }, + }, }); }); }); diff --git a/src/file/drawing/floating/vertical-position.spec.ts b/src/file/drawing/floating/vertical-position.spec.ts index 42d70d7112..ff34f762ef 100644 --- a/src/file/drawing/floating/vertical-position.spec.ts +++ b/src/file/drawing/floating/vertical-position.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { VerticalPositionAlign, VerticalPositionRelativeFrom } from "./floating-position"; import { VerticalPosition } from "./vertical-position"; @@ -8,35 +8,45 @@ import { VerticalPosition } from "./vertical-position"; describe("VerticalPosition", () => { describe("#constructor()", () => { it("should create a element with position align", () => { - const newJson = Utility.jsonify( + const tree = new Formatter().format( new VerticalPosition({ relative: VerticalPositionRelativeFrom.MARGIN, align: VerticalPositionAlign.INSIDE, }), ); - assert.equal(newJson.rootKey, "wp:positionV"); - assert.include(newJson.root[0].root, { - relativeFrom: "margin", + expect(tree).to.deep.equal({ + "wp:positionV": [ + { + _attr: { + relativeFrom: "margin", + }, + }, + { + "wp:align": ["inside"], + }, + ], }); - - assert.equal(newJson.root[1].rootKey, "wp:align"); - assert.include(newJson.root[1].root, "inside"); }); it("should create a element with offset", () => { - const newJson = Utility.jsonify( + const tree = new Formatter().format( new VerticalPosition({ relative: VerticalPositionRelativeFrom.MARGIN, offset: 40, }), ); - assert.equal(newJson.rootKey, "wp:positionV"); - assert.include(newJson.root[0].root, { - relativeFrom: "margin", + expect(tree).to.deep.equal({ + "wp:positionV": [ + { + _attr: { + relativeFrom: "margin", + }, + }, + { + "wp:posOffset": ["40"], + }, + ], }); - - assert.equal(newJson.root[1].rootKey, "wp:posOffset"); - assert.include(newJson.root[1].root[0], 40); }); }); }); diff --git a/src/file/paragraph/formatting/border.spec.ts b/src/file/paragraph/formatting/border.spec.ts index d0fda56359..20b8e4309e 100644 --- a/src/file/paragraph/formatting/border.spec.ts +++ b/src/file/paragraph/formatting/border.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { assert, expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { ThematicBreak } from "./border"; @@ -28,14 +28,21 @@ describe("ThematicBreak", () => { }); it("should create a Thematic Break with correct border properties", () => { - const newJson = Utility.jsonify(thematicBreak); - const attributes = { - color: "auto", - space: "1", - val: "single", - sz: "6", - }; - assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); + const tree = new Formatter().format(thematicBreak); + expect(tree).to.deep.equal({ + "w:pBdr": [ + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": "1", + "w:sz": "6", + "w:val": "single", + }, + }, + }, + ], + }); }); }); }); diff --git a/src/file/paragraph/formatting/style.spec.ts b/src/file/paragraph/formatting/style.spec.ts index bf70dc35a4..af3fd9e3a7 100644 --- a/src/file/paragraph/formatting/style.spec.ts +++ b/src/file/paragraph/formatting/style.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { Style } from "./style"; @@ -10,14 +10,26 @@ describe("ParagraphStyle", () => { describe("#constructor()", () => { it("should create a style with given value", () => { style = new Style("test"); - const newJson = Utility.jsonify(style); - assert.equal(newJson.root[0].root.val, "test"); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:pStyle": { + _attr: { + "w:val": "test", + }, + }, + }); }); it("should create a style with blank val", () => { style = new Style(""); - const newJson = Utility.jsonify(style); - assert.equal(newJson.root[0].root.val, ""); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:pStyle": { + _attr: { + "w:val": "", + }, + }, + }); }); }); }); diff --git a/src/file/paragraph/links/outline-level.spec.ts b/src/file/paragraph/links/outline-level.spec.ts index 6ba188fd9d..4b13ef03e2 100644 --- a/src/file/paragraph/links/outline-level.spec.ts +++ b/src/file/paragraph/links/outline-level.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { OutlineLevel } from "./outline-level"; @@ -10,14 +10,14 @@ describe("ParagraphOutlineLevel", () => { describe("#constructor()", () => { it("should create an outlineLevel with given value", () => { outlineLevel = new OutlineLevel("0"); - const newJson = Utility.jsonify(outlineLevel); - assert.equal(newJson.root[0].root.val, "0"); - }); - - it("should create an outlineLevel with blank val", () => { - outlineLevel = new OutlineLevel(""); - const newJson = Utility.jsonify(outlineLevel); - assert.equal(newJson.root[0].root.val, ""); + const tree = new Formatter().format(outlineLevel); + expect(tree).to.deep.equal({ + "w:outlineLvl": { + _attr: { + "w:val": "0", + }, + }, + }); }); }); }); diff --git a/src/file/paragraph/run/break.spec.ts b/src/file/paragraph/run/break.spec.ts index a07e1426bd..98e058937d 100644 --- a/src/file/paragraph/run/break.spec.ts +++ b/src/file/paragraph/run/break.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { Break } from "./break"; @@ -13,8 +13,10 @@ describe("Break", () => { describe("#constructor()", () => { it("should create a Break with correct root key", () => { - const newJson = Utility.jsonify(currentBreak); - assert.equal(newJson.rootKey, "w:br"); + const tree = new Formatter().format(currentBreak); + expect(tree).to.deep.equal({ + "w:br": {}, + }); }); }); }); diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index c30147d22f..ae6526a229 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -1,7 +1,6 @@ -import { assert, expect } from "chai"; +import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { Utility } from "tests/utility"; import { Run } from "./"; @@ -15,28 +14,50 @@ describe("Run", () => { describe("#bold()", () => { it("it should add bold to the properties", () => { run.bold(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:b"); - assert.equal(newJson.root[0].root[1].rootKey, "w:bCs"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + { + "w:rPr": [ + { "w:b": { _attr: { "w:val": true } } }, + { + "w:bCs": { + _attr: { + "w:val": true, + }, + }, + }, + ], + }, + ], + }); }); }); describe("#italics()", () => { it("it should add italics to the properties", () => { run.italics(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:i"); - assert.equal(newJson.root[0].root[1].rootKey, "w:iCs"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + { + "w:rPr": [ + { "w:i": { _attr: { "w:val": true } } }, + { + "w:iCs": { + _attr: { + "w:val": true, + }, + }, + }, + ], + }, + ], + }); }); }); describe("#underline()", () => { - it("it should add underline to the properties", () => { - run.underline(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:u"); - }); - it("should default to 'single' and no color", () => { run.underline(); const tree = new Formatter().format(run); @@ -57,48 +78,60 @@ describe("Run", () => { describe("#smallCaps()", () => { it("it should add smallCaps to the properties", () => { run.smallCaps(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }], + }); }); }); describe("#caps()", () => { it("it should add caps to the properties", () => { run.allCaps(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:caps"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:caps": {} }] }], + }); }); }); describe("#strike()", () => { it("it should add strike to the properties", () => { run.strike(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:strike"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }], + }); }); }); describe("#doubleStrike()", () => { it("it should add caps to the properties", () => { run.doubleStrike(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }], + }); }); }); describe("#break()", () => { it("it should add break to the run", () => { run.break(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[1].rootKey, "w:br"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:br": {} }], + }); }); }); describe("#tab()", () => { it("it should add break to the run", () => { run.tab(); - const newJson = Utility.jsonify(run); - assert.equal(newJson.root[1].rootKey, "w:tab"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:tab": {} }], + }); }); }); diff --git a/src/file/paragraph/run/strike.spec.ts b/src/file/paragraph/run/strike.spec.ts index 3d4f83db43..73c7e853c8 100644 --- a/src/file/paragraph/run/strike.spec.ts +++ b/src/file/paragraph/run/strike.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { DoubleStrike, Strike } from "./formatting"; @@ -13,8 +13,14 @@ describe("Strike", () => { describe("#constructor()", () => { it("should create a Strike with correct root key", () => { - const newJson = Utility.jsonify(strike); - assert.equal(newJson.rootKey, "w:strike"); + const tree = new Formatter().format(strike); + expect(tree).to.deep.equal({ + "w:strike": { + _attr: { + "w:val": true, + }, + }, + }); }); }); }); @@ -28,8 +34,14 @@ describe("DoubleStrike", () => { describe("#constructor()", () => { it("should create a Double Strike with correct root key", () => { - const newJson = Utility.jsonify(strike); - assert.equal(newJson.rootKey, "w:dstrike"); + const tree = new Formatter().format(strike); + expect(tree).to.deep.equal({ + "w:dstrike": { + _attr: { + "w:val": true, + }, + }, + }); }); }); }); diff --git a/src/file/paragraph/run/tab.spec.ts b/src/file/paragraph/run/tab.spec.ts index 600b4778ac..04d3503521 100644 --- a/src/file/paragraph/run/tab.spec.ts +++ b/src/file/paragraph/run/tab.spec.ts @@ -1,6 +1,6 @@ -import { assert } from "chai"; +import { expect } from "chai"; -import { Utility } from "tests/utility"; +import { Formatter } from "export/formatter"; import { Tab } from "./tab"; @@ -13,8 +13,10 @@ describe("Tab", () => { describe("#constructor()", () => { it("should create a Tab with correct root key", () => { - const newJson = Utility.jsonify(tab); - assert.equal(newJson.rootKey, "w:tab"); + const tree = new Formatter().format(tab); + expect(tree).to.deep.equal({ + "w:tab": {}, + }); }); }); });