Remove usage of Utility
This commit is contained in:
@ -1,10 +1,9 @@
|
|||||||
import { assert } from "chai";
|
import { assert, expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import * as file from "../file";
|
import * as file from "file";
|
||||||
import { CoreProperties } from "../file/core-properties";
|
import { CoreProperties } from "file/core-properties";
|
||||||
import { Attributes } from "../file/xml-components";
|
import { Attributes } from "file/xml-components";
|
||||||
import { Utility } from "../tests/utility";
|
|
||||||
|
|
||||||
describe("Formatter", () => {
|
describe("Formatter", () => {
|
||||||
let formatter: Formatter;
|
let formatter: Formatter;
|
||||||
@ -38,26 +37,24 @@ describe("Formatter", () => {
|
|||||||
const attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
rsidSect: "test2",
|
rsidSect: "test2",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
const tree = formatter.format(attributes);
|
||||||
newJson = Utility.jsonify(newJson);
|
expect(tree).to.deep.equal({
|
||||||
if (newJson._attr === undefined) {
|
_attr: {
|
||||||
assert.fail();
|
"w:rsidSect": "test2",
|
||||||
return;
|
},
|
||||||
}
|
});
|
||||||
assert.isDefined(newJson._attr["w:rsidSect"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format attributes (val)", () => {
|
it("should format attributes (val)", () => {
|
||||||
const attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
val: "test",
|
val: "test",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
const tree = formatter.format(attributes);
|
||||||
newJson = Utility.jsonify(newJson);
|
expect(tree).to.deep.equal({
|
||||||
if (newJson._attr === undefined) {
|
_attr: {
|
||||||
assert.fail();
|
"w:val": "test",
|
||||||
return;
|
},
|
||||||
}
|
});
|
||||||
assert.isDefined(newJson._attr["w:val"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should should change 'p' tag into 'w:p' tag", () => {
|
it("should should change 'p' tag into 'w:p' tag", () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { HorizontalPositionAlign, HorizontalPositionRelativeFrom } from "./floating-position";
|
import { HorizontalPositionAlign, HorizontalPositionRelativeFrom } from "./floating-position";
|
||||||
import { HorizontalPosition } from "./horizontal-position";
|
import { HorizontalPosition } from "./horizontal-position";
|
||||||
@ -8,35 +8,45 @@ import { HorizontalPosition } from "./horizontal-position";
|
|||||||
describe("HorizontalPosition", () => {
|
describe("HorizontalPosition", () => {
|
||||||
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 HorizontalPosition({
|
new HorizontalPosition({
|
||||||
relative: HorizontalPositionRelativeFrom.MARGIN,
|
relative: HorizontalPositionRelativeFrom.MARGIN,
|
||||||
align: HorizontalPositionAlign.CENTER,
|
align: HorizontalPositionAlign.CENTER,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionH");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionH": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
relativeFrom: "margin",
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:align": ["center"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:align");
|
|
||||||
assert.include(newJson.root[1].root, "center");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a element with offset", () => {
|
it("should create a element with offset", () => {
|
||||||
const newJson = Utility.jsonify(
|
const tree = new Formatter().format(
|
||||||
new HorizontalPosition({
|
new HorizontalPosition({
|
||||||
relative: HorizontalPositionRelativeFrom.MARGIN,
|
relative: HorizontalPositionRelativeFrom.MARGIN,
|
||||||
offset: 40,
|
offset: 40,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionH");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionH": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
relativeFrom: "margin",
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["40"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:posOffset");
|
|
||||||
assert.include(newJson.root[1].root[0], 40);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { PageBreak, PageBreakBefore } from "./page-break";
|
import { PageBreak, PageBreakBefore } from "./page-break";
|
||||||
|
|
||||||
@ -13,21 +13,18 @@ describe("PageBreak", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Page Break with correct attributes", () => {
|
it("should create a Page Break with correct attributes", () => {
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
const tree = new Formatter().format(pageBreak);
|
||||||
const attributes = {
|
expect(tree).to.deep.equal({
|
||||||
type: "page",
|
"w:r": [
|
||||||
};
|
{
|
||||||
assert.equal(JSON.stringify(newJson.root[1].root[0].root), JSON.stringify(attributes));
|
"w:br": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "page",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with w:r", () => {
|
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
|
||||||
assert.equal(newJson.rootKey, "w:r");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a Page Break with a Break inside", () => {
|
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
|
||||||
assert.equal(newJson.root[1].rootKey, "w:br");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -35,7 +32,9 @@ describe("PageBreak", () => {
|
|||||||
describe("PageBreakBefore", () => {
|
describe("PageBreakBefore", () => {
|
||||||
it("should create page break before", () => {
|
it("should create page break before", () => {
|
||||||
const pageBreakBefore = new PageBreakBefore();
|
const pageBreakBefore = new PageBreakBefore();
|
||||||
const newJson = Utility.jsonify(pageBreakBefore);
|
const tree = new Formatter().format(pageBreakBefore);
|
||||||
assert.equal(newJson.rootKey, "w:pageBreakBefore");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pageBreakBefore": {},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { NumberProperties } from "./unordered-list";
|
import { NumberProperties } from "./unordered-list";
|
||||||
|
|
||||||
@ -13,20 +13,25 @@ describe("NumberProperties", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Number Properties with correct root key", () => {
|
it("should create a Number Properties with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
const tree = new Formatter().format(numberProperties);
|
||||||
assert.equal(newJson.rootKey, "w:numPr");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:numPr": [
|
||||||
|
{
|
||||||
|
"w:ilvl": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:numId": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with a Indent Level inside", () => {
|
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
|
||||||
assert.equal(newJson.root[0].rootKey, "w:ilvl");
|
|
||||||
assert.equal(newJson.root[0].root[0].root.val, 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a Page Break with a Number Id inside", () => {
|
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
|
||||||
assert.equal(newJson.root[1].rootKey, "w:numId");
|
|
||||||
assert.equal(newJson.root[1].root[0].root.val, 5);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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 { Hyperlink } from "./";
|
import { Hyperlink } from "./";
|
||||||
|
|
||||||
@ -14,28 +13,23 @@ describe("Hyperlink", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a hyperlink with correct root key", () => {
|
it("should create a hyperlink with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
|
||||||
assert.equal(newJson.rootKey, "w:hyperlink");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a hyperlink with right attributes", () => {
|
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
|
||||||
const attributes = {
|
|
||||||
history: 1,
|
|
||||||
id: "rId1",
|
|
||||||
};
|
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a hyperlink with a run component", () => {
|
|
||||||
const tree = new Formatter().format(hyperlink);
|
const tree = new Formatter().format(hyperlink);
|
||||||
const runJson = {
|
expect(tree).to.deep.equal({
|
||||||
|
"w:hyperlink": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:history": 1,
|
||||||
|
"r:id": "rId1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
||||||
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
|
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
|
||||||
],
|
],
|
||||||
};
|
},
|
||||||
expect(tree["w:hyperlink"][1]).to.deep.equal(runJson);
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with optional anchor parameter", () => {
|
describe("with optional anchor parameter", () => {
|
||||||
@ -44,12 +38,23 @@ describe("Hyperlink", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should create an internal link with anchor tag", () => {
|
it("should create an internal link with anchor tag", () => {
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
const tree = new Formatter().format(hyperlink);
|
||||||
const attributes = {
|
expect(tree).to.deep.equal({
|
||||||
history: 1,
|
"w:hyperlink": [
|
||||||
anchor: "anchor",
|
{
|
||||||
};
|
_attr: {
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
"w:history": 1,
|
||||||
|
"w:anchor": "anchor",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
||||||
|
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "Anchor Text"] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user