fix some linter warnings
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import { BaseXmlComponent } from "../docx/xml-components";
|
import { BaseXmlComponent } from "../docx/xml-components";
|
||||||
|
|
||||||
export class Formatter {
|
export class Formatter {
|
||||||
public format(input: BaseXmlComponent): Object {
|
public format(input: BaseXmlComponent): any {
|
||||||
return input.toXml();
|
return input.toXml();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Formatter } from "../../export/formatter";
|
|
||||||
import * as docx from "../../docx";
|
|
||||||
import { Attributes } from "../../docx/xml-components";
|
|
||||||
import { Properties } from "../../properties";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
|
||||||
function jsonify(obj: Object) {
|
import * as docx from "../../docx";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
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);
|
return JSON.parse(stringifiedJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,59 +19,56 @@ describe("Formatter", () => {
|
|||||||
|
|
||||||
describe("#format()", () => {
|
describe("#format()", () => {
|
||||||
it("should format simple paragraph", () => {
|
it("should format simple paragraph", () => {
|
||||||
let paragraph = new docx.Paragraph();
|
const paragraph = new docx.Paragraph();
|
||||||
let newJson = formatter.format(paragraph);
|
const newJson = formatter.format(paragraph);
|
||||||
newJson = jsonify(newJson);
|
|
||||||
assert.isDefined(newJson["w:p"]);
|
assert.isDefined(newJson["w:p"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should remove xmlKeys", () => {
|
it("should remove xmlKeys", () => {
|
||||||
let paragraph = new docx.Paragraph();
|
const paragraph = new docx.Paragraph();
|
||||||
let newJson = formatter.format(paragraph);
|
const newJson = formatter.format(paragraph);
|
||||||
let stringifiedJson = JSON.stringify(newJson);
|
const stringifiedJson = JSON.stringify(newJson);
|
||||||
assert(stringifiedJson.indexOf("xmlKeys") < 0);
|
assert(stringifiedJson.indexOf("xmlKeys") < 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format simple paragraph with bold text", () => {
|
it("should format simple paragraph with bold text", () => {
|
||||||
let paragraph = new docx.Paragraph();
|
const paragraph = new docx.Paragraph();
|
||||||
paragraph.addText(new docx.TextRun("test").bold());
|
paragraph.addText(new docx.TextRun("test").bold());
|
||||||
let newJson = formatter.format(paragraph);
|
const newJson = formatter.format(paragraph);
|
||||||
newJson = jsonify(newJson);
|
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]._attr["w:val"]);
|
||||||
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format attributes (rsidSect)", () => {
|
it("should format attributes (rsidSect)", () => {
|
||||||
let attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
rsidSect: "test2"
|
rsidSect: "test2",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
let newJson = formatter.format(attributes);
|
||||||
newJson = jsonify(newJson);
|
newJson = jsonify(newJson);
|
||||||
assert.isDefined(newJson["_attr"]["w:rsidSect"]);
|
assert.isDefined(newJson._attr["w:rsidSect"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format attributes (val)", () => {
|
it("should format attributes (val)", () => {
|
||||||
let attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
val: "test"
|
val: "test",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
let newJson = formatter.format(attributes);
|
||||||
newJson = jsonify(newJson);
|
newJson = jsonify(newJson);
|
||||||
assert.isDefined(newJson["_attr"]["w:val"]);
|
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", () => {
|
||||||
let paragraph = new docx.Paragraph();
|
const paragraph = new docx.Paragraph();
|
||||||
let newJson = formatter.format(paragraph);
|
const newJson = formatter.format(paragraph);
|
||||||
assert.isDefined(newJson["w:p"]);
|
assert.isDefined(newJson["w:p"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format Properties object correctly", () => {
|
it("should format Properties object correctly", () => {
|
||||||
let properties = new Properties({
|
const properties = new Properties({
|
||||||
title: "test document",
|
title: "test document",
|
||||||
creator: "Dolan"
|
creator: "Dolan",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(properties);
|
const newJson = formatter.format(properties);
|
||||||
newJson = jsonify(newJson);
|
|
||||||
assert.isDefined(newJson["cp:coreProperties"]);
|
assert.isDefined(newJson["cp:coreProperties"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user