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 { 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"],
});
});
});
});

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";
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"],
});
});
});
});

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";
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, {
const tree = new Formatter().format(new SimplePos());
expect(tree).to.deep.equal({
"wp:simplePos": {
_attr: {
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 { 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, {
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, {
expect(tree).to.deep.equal({
"wp:positionV": [
{
_attr: {
relativeFrom: "margin",
});
assert.equal(newJson.root[1].rootKey, "wp:posOffset");
assert.include(newJson.root[1].root[0], 40);
},
},
{
"wp:posOffset": ["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";
@ -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",
},
},
},
],
});
});
});
});

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";
@ -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": "",
},
},
});
});
});
});

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";
@ -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",
},
},
});
});
});
});

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";
@ -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": {},
});
});
});
});

View File

@ -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": {} }],
});
});
});

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";
@ -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,
},
},
});
});
});
});

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";
@ -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": {},
});
});
});
});