Remove usage of Utility class

This commit is contained in:
Dolan
2019-06-26 22:12:18 +01:00
parent 564a055316
commit a531713214
11 changed files with 182 additions and 99 deletions

View File

@ -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 { Align } from "./align";
import { VerticalPositionAlign } from "./floating-position"; import { VerticalPositionAlign } from "./floating-position";
@ -8,9 +8,10 @@ import { VerticalPositionAlign } from "./floating-position";
describe("Align", () => { describe("Align", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a element with correct root key", () => { it("should create a element with correct root key", () => {
const newJson = Utility.jsonify(new Align(VerticalPositionAlign.CENTER)); const tree = new Formatter().format(new Align(VerticalPositionAlign.CENTER));
assert.equal(newJson.rootKey, "wp:align"); expect(tree).to.deep.equal({
assert.include(newJson.root[0], VerticalPositionAlign.CENTER); "wp:align": ["center"],
});
}); });
}); });
}); });

View File

@ -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"; import { PositionOffset } from "./position-offset";
describe("PositionOffset", () => { describe("PositionOffset", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a element with correct root key", () => { it("should create a element with correct root key", () => {
const newJson = Utility.jsonify(new PositionOffset(50)); const tree = new Formatter().format(new PositionOffset(50));
assert.equal(newJson.rootKey, "wp:posOffset"); expect(tree).to.deep.equal({
assert.equal(newJson.root[0], 50); "wp:posOffset": ["50"],
});
}); });
}); });
}); });

View File

@ -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"; import { SimplePos } from "./simple-pos";
describe("SimplePos", () => { describe("SimplePos", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a element with correct root key", () => { it("should create a element with correct root key", () => {
const newJson = Utility.jsonify(new SimplePos()); const tree = new Formatter().format(new SimplePos());
assert.equal(newJson.rootKey, "wp:simplePos"); expect(tree).to.deep.equal({
assert.include(newJson.root[0].root, { "wp:simplePos": {
x: 0, _attr: {
y: 0, x: 0,
y: 0,
},
},
}); });
}); });
}); });

View File

@ -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 { VerticalPositionAlign, VerticalPositionRelativeFrom } from "./floating-position";
import { VerticalPosition } from "./vertical-position"; import { VerticalPosition } from "./vertical-position";
@ -8,35 +8,45 @@ import { VerticalPosition } from "./vertical-position";
describe("VerticalPosition", () => { describe("VerticalPosition", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a element with position align", () => { it("should create a element with position align", () => {
const newJson = Utility.jsonify( const tree = new Formatter().format(
new VerticalPosition({ new VerticalPosition({
relative: VerticalPositionRelativeFrom.MARGIN, relative: VerticalPositionRelativeFrom.MARGIN,
align: VerticalPositionAlign.INSIDE, align: VerticalPositionAlign.INSIDE,
}), }),
); );
assert.equal(newJson.rootKey, "wp:positionV"); expect(tree).to.deep.equal({
assert.include(newJson.root[0].root, { "wp:positionV": [
relativeFrom: "margin", {
_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", () => { it("should create a element with offset", () => {
const newJson = Utility.jsonify( const tree = new Formatter().format(
new VerticalPosition({ new VerticalPosition({
relative: VerticalPositionRelativeFrom.MARGIN, relative: VerticalPositionRelativeFrom.MARGIN,
offset: 40, offset: 40,
}), }),
); );
assert.equal(newJson.rootKey, "wp:positionV"); expect(tree).to.deep.equal({
assert.include(newJson.root[0].root, { "wp:positionV": [
relativeFrom: "margin", {
_attr: {
relativeFrom: "margin",
},
},
{
"wp:posOffset": ["40"],
},
],
}); });
assert.equal(newJson.root[1].rootKey, "wp:posOffset");
assert.include(newJson.root[1].root[0], 40);
}); });
}); });
}); });

View File

@ -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"; import { ThematicBreak } from "./border";
@ -28,14 +28,21 @@ describe("ThematicBreak", () => {
}); });
it("should create a Thematic Break with correct border properties", () => { it("should create a Thematic Break with correct border properties", () => {
const newJson = Utility.jsonify(thematicBreak); const tree = new Formatter().format(thematicBreak);
const attributes = { expect(tree).to.deep.equal({
color: "auto", "w:pBdr": [
space: "1", {
val: "single", "w:bottom": {
sz: "6", _attr: {
}; "w:color": "auto",
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); "w:space": "1",
"w:sz": "6",
"w:val": "single",
},
},
},
],
});
}); });
}); });
}); });

View File

@ -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"; import { Style } from "./style";
@ -10,14 +10,26 @@ describe("ParagraphStyle", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a style with given value", () => { it("should create a style with given value", () => {
style = new Style("test"); style = new Style("test");
const newJson = Utility.jsonify(style); const tree = new Formatter().format(style);
assert.equal(newJson.root[0].root.val, "test"); expect(tree).to.deep.equal({
"w:pStyle": {
_attr: {
"w:val": "test",
},
},
});
}); });
it("should create a style with blank val", () => { it("should create a style with blank val", () => {
style = new Style(""); style = new Style("");
const newJson = Utility.jsonify(style); const tree = new Formatter().format(style);
assert.equal(newJson.root[0].root.val, ""); expect(tree).to.deep.equal({
"w:pStyle": {
_attr: {
"w:val": "",
},
},
});
}); });
}); });
}); });

View File

@ -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"; import { OutlineLevel } from "./outline-level";
@ -10,14 +10,14 @@ describe("ParagraphOutlineLevel", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create an outlineLevel with given value", () => { it("should create an outlineLevel with given value", () => {
outlineLevel = new OutlineLevel("0"); outlineLevel = new OutlineLevel("0");
const newJson = Utility.jsonify(outlineLevel); const tree = new Formatter().format(outlineLevel);
assert.equal(newJson.root[0].root.val, "0"); expect(tree).to.deep.equal({
}); "w:outlineLvl": {
_attr: {
it("should create an outlineLevel with blank val", () => { "w:val": "0",
outlineLevel = new OutlineLevel(""); },
const newJson = Utility.jsonify(outlineLevel); },
assert.equal(newJson.root[0].root.val, ""); });
}); });
}); });
}); });

View File

@ -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"; import { Break } from "./break";
@ -13,8 +13,10 @@ describe("Break", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Break with correct root key", () => { it("should create a Break with correct root key", () => {
const newJson = Utility.jsonify(currentBreak); const tree = new Formatter().format(currentBreak);
assert.equal(newJson.rootKey, "w:br"); expect(tree).to.deep.equal({
"w:br": {},
});
}); });
}); });
}); });

View File

@ -1,7 +1,6 @@
import { assert, expect } from "chai"; import { expect } from "chai";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { Utility } from "tests/utility";
import { Run } from "./"; import { Run } from "./";
@ -15,28 +14,50 @@ 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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b"); expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].rootKey, "w:bCs"); "w:r": [
{
"w:rPr": [
{ "w:b": { _attr: { "w:val": true } } },
{
"w:bCs": {
_attr: {
"w:val": true,
},
},
},
],
},
],
});
}); });
}); });
describe("#italics()", () => { describe("#italics()", () => {
it("it should add italics to the properties", () => { it("it should add italics to the properties", () => {
run.italics(); run.italics();
const newJson = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i"); expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].rootKey, "w:iCs"); "w:r": [
{
"w:rPr": [
{ "w:i": { _attr: { "w:val": true } } },
{
"w:iCs": {
_attr: {
"w:val": true,
},
},
},
],
},
],
});
}); });
}); });
describe("#underline()", () => { 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", () => { it("should default to 'single' and no color", () => {
run.underline(); run.underline();
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
@ -57,48 +78,60 @@ 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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps"); expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
});
}); });
}); });
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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:caps"); expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
});
}); });
}); });
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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:strike"); expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
});
}); });
}); });
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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike"); expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
});
}); });
}); });
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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[1].rootKey, "w:br"); expect(tree).to.deep.equal({
"w:r": [{ "w:br": {} }],
});
}); });
}); });
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 = Utility.jsonify(run); const tree = new Formatter().format(run);
assert.equal(newJson.root[1].rootKey, "w:tab"); expect(tree).to.deep.equal({
"w:r": [{ "w:tab": {} }],
});
}); });
}); });

View File

@ -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"; import { DoubleStrike, Strike } from "./formatting";
@ -13,8 +13,14 @@ describe("Strike", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Strike with correct root key", () => { it("should create a Strike with correct root key", () => {
const newJson = Utility.jsonify(strike); const tree = new Formatter().format(strike);
assert.equal(newJson.rootKey, "w:strike"); expect(tree).to.deep.equal({
"w:strike": {
_attr: {
"w:val": true,
},
},
});
}); });
}); });
}); });
@ -28,8 +34,14 @@ 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", () => {
const newJson = Utility.jsonify(strike); const tree = new Formatter().format(strike);
assert.equal(newJson.rootKey, "w:dstrike"); expect(tree).to.deep.equal({
"w:dstrike": {
_attr: {
"w:val": true,
},
},
});
}); });
}); });
}); });

View File

@ -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"; import { Tab } from "./tab";
@ -13,8 +13,10 @@ describe("Tab", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Tab with correct root key", () => { it("should create a Tab with correct root key", () => {
const newJson = Utility.jsonify(tab); const tree = new Formatter().format(tab);
assert.equal(newJson.rootKey, "w:tab"); expect(tree).to.deep.equal({
"w:tab": {},
});
}); });
}); });
}); });