fixed all tslint errors
This commit is contained in:
@ -4,36 +4,36 @@ import {Attributes} from "../docx/xml-components";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("Attribute", () => {
|
||||
var attributes: Attributes;
|
||||
let attributes: Attributes;
|
||||
|
||||
beforeEach(() => {
|
||||
attributes = new Attributes();
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should not add val with empty constructor", () => {
|
||||
var newAttrs = new Attributes();
|
||||
var stringifiedJson = JSON.stringify(newAttrs);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
let newAttrs = new Attributes();
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.isUndefined(newJson.root.val);
|
||||
});
|
||||
|
||||
it("should have val as defined with populated constructor", () => {
|
||||
var newAttrs = new Attributes({
|
||||
let newAttrs = new Attributes({
|
||||
val: "test"
|
||||
});
|
||||
var stringifiedJson = JSON.stringify(newAttrs);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root.val, "test");
|
||||
});
|
||||
|
||||
it("should have space value as defined with populated constructor", () => {
|
||||
var newAttrs = new Attributes({
|
||||
let newAttrs = new Attributes({
|
||||
space: "spaceTest"
|
||||
});
|
||||
var stringifiedJson = JSON.stringify(newAttrs);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root.space, "spaceTest");
|
||||
});
|
||||
});
|
||||
|
@ -9,12 +9,12 @@ import {Columns} from "../docx/document/body/columns";
|
||||
import {DocumentGrid} from "../docx/document/body/doc-grid";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Body", () => {
|
||||
var body: Body;
|
||||
let body: Body;
|
||||
|
||||
beforeEach(() => {
|
||||
body = new Body();
|
||||
@ -28,27 +28,27 @@ describe("Body", () => {
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create the Section Properties", () => {
|
||||
var newJson = jsonify(body);
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[0].rootKey, "w:sectPr");
|
||||
});
|
||||
|
||||
it("should create the Page Size", () => {
|
||||
var newJson = jsonify(body);
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[1].rootKey, "w:pgSz");
|
||||
});
|
||||
|
||||
it("should create the Page Margin", () => {
|
||||
var newJson = jsonify(body);
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[2].rootKey, "w:pgMar");
|
||||
});
|
||||
|
||||
it("should create the Columns", () => {
|
||||
var newJson = jsonify(body);
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[3].rootKey, "w:cols");
|
||||
});
|
||||
|
||||
it("should create the Document Grid", () => {
|
||||
var newJson = jsonify(body);
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[4].rootKey, "w:docGrid");
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ import {ThematicBreak} from "../docx/paragraph/border";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ describe("Border", () => {
|
||||
});
|
||||
|
||||
describe("ThematicBreak", () => {
|
||||
var thematicBreak: ThematicBreak;
|
||||
let thematicBreak: ThematicBreak;
|
||||
|
||||
beforeEach(() => {
|
||||
thematicBreak = new ThematicBreak();
|
||||
@ -21,8 +21,8 @@ describe("ThematicBreak", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Thematic Break with correct border properties", () => {
|
||||
var newJson = jsonify(thematicBreak);
|
||||
var attributes = {
|
||||
let newJson = jsonify(thematicBreak);
|
||||
let attributes = {
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
@ -30,5 +30,5 @@ describe("ThematicBreak", () => {
|
||||
};
|
||||
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
@ -4,18 +4,17 @@ import * as docx from "../docx";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("Document", () => {
|
||||
var document: docx.Document;
|
||||
let document: docx.Document;
|
||||
|
||||
beforeEach(() => {
|
||||
document = new docx.Document();
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create valid JSON", () => {
|
||||
//console.log(JSON.stringify(document, null, " "));
|
||||
var stringifiedJson = JSON.stringify(document);
|
||||
var newJson;
|
||||
let stringifiedJson = JSON.stringify(document);
|
||||
let newJson;
|
||||
|
||||
try {
|
||||
newJson = JSON.parse(stringifiedJson);
|
||||
|
@ -10,70 +10,70 @@ import {Properties} from "../properties";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Formatter", () => {
|
||||
var formatter: Formatter;
|
||||
let formatter: Formatter;
|
||||
|
||||
beforeEach(() => {
|
||||
formatter = new Formatter();
|
||||
});
|
||||
|
||||
describe('#format()', () => {
|
||||
describe("#format()", () => {
|
||||
it("should format simple paragraph", () => {
|
||||
var paragraph = new docx.Paragraph();
|
||||
var newJson = formatter.format(paragraph);
|
||||
let paragraph = new docx.Paragraph();
|
||||
let newJson = formatter.format(paragraph);
|
||||
newJson = jsonify(newJson);
|
||||
assert.isDefined(newJson["w:p"]);
|
||||
});
|
||||
|
||||
it("should remove xmlKeys", () => {
|
||||
var paragraph = new docx.Paragraph();
|
||||
var newJson = formatter.format(paragraph);
|
||||
var stringifiedJson = JSON.stringify(newJson);
|
||||
let paragraph = new docx.Paragraph();
|
||||
let newJson = formatter.format(paragraph);
|
||||
let stringifiedJson = JSON.stringify(newJson);
|
||||
assert(stringifiedJson.indexOf("xmlKeys") < 0);
|
||||
});
|
||||
|
||||
it("should format simple paragraph with bold text", () => {
|
||||
var paragraph = new docx.Paragraph();
|
||||
let paragraph = new docx.Paragraph();
|
||||
paragraph.addText(new docx.TextRun("test").bold());
|
||||
var newJson = formatter.format(paragraph);
|
||||
let 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"]);
|
||||
});
|
||||
|
||||
it("should format attributes (rsidSect)", () => {
|
||||
var attributes = new Attributes({
|
||||
let attributes = new Attributes({
|
||||
rsidSect: "test2"
|
||||
});
|
||||
var newJson = formatter.format(attributes);
|
||||
let newJson = formatter.format(attributes);
|
||||
newJson = jsonify(newJson);
|
||||
assert.isDefined(newJson["_attr"]["w:rsidSect"]);
|
||||
});
|
||||
|
||||
it("should format attributes (val)", () => {
|
||||
var attributes = new Attributes({
|
||||
let attributes = new Attributes({
|
||||
val: "test"
|
||||
});
|
||||
var newJson = formatter.format(attributes);
|
||||
let newJson = formatter.format(attributes);
|
||||
newJson = jsonify(newJson);
|
||||
assert.isDefined(newJson["_attr"]["w:val"]);
|
||||
});
|
||||
|
||||
it("should should change 'p' tag into 'w:p' tag", () => {
|
||||
var paragraph = new docx.Paragraph();
|
||||
var newJson = formatter.format(paragraph);
|
||||
let paragraph = new docx.Paragraph();
|
||||
let newJson = formatter.format(paragraph);
|
||||
assert.isDefined(newJson["w:p"]);
|
||||
});
|
||||
|
||||
it("should format Properties object correctly", () => {
|
||||
var properties = new Properties({
|
||||
let properties = new Properties({
|
||||
title: "test document",
|
||||
creator: "Dolan"
|
||||
});
|
||||
var newJson = formatter.format(properties);
|
||||
let newJson = formatter.format(properties);
|
||||
newJson = jsonify(newJson);
|
||||
assert.isDefined(newJson["cp:coreProperties"]);
|
||||
});
|
||||
|
@ -5,35 +5,35 @@
|
||||
|
||||
import {LocalPacker} from "../export/packer/local";
|
||||
import {assert} from "chai";
|
||||
import {Document} from "../docx/document"
|
||||
import {Properties} from "../properties"
|
||||
import {DefaultStyle} from "../styles/sample"
|
||||
import {Paragraph} from "../docx/paragraph"
|
||||
import {DefaultStylesFactory} from "../styles/factory"
|
||||
import {Document} from "../docx/document";
|
||||
import {Properties} from "../properties";
|
||||
import {DefaultStyle} from "../styles/sample";
|
||||
import {Paragraph} from "../docx/paragraph";
|
||||
import {DefaultStylesFactory} from "../styles/factory";
|
||||
|
||||
describe.only("Packer", () => {
|
||||
var packer: LocalPacker;
|
||||
var stylesFactory: DefaultStylesFactory;
|
||||
let packer: LocalPacker;
|
||||
let stylesFactory: DefaultStylesFactory;
|
||||
|
||||
beforeEach(() => {
|
||||
var document = new Document();
|
||||
var paragraph = new Paragraph("test text");
|
||||
var heading = new Paragraph("Hello world").heading1();
|
||||
let document = new Document();
|
||||
let paragraph = new Paragraph("test text");
|
||||
let heading = new Paragraph("Hello world").heading1();
|
||||
document.addParagraph(new Paragraph("title").title());
|
||||
document.addParagraph(heading);
|
||||
document.addParagraph(new Paragraph("heading 2").heading2());
|
||||
document.addParagraph(paragraph);
|
||||
var properties = new Properties({
|
||||
let properties = new Properties({
|
||||
creator: "Shan Fu",
|
||||
revision: "1",
|
||||
lastModifiedBy: "Shan Fu"
|
||||
});
|
||||
stylesFactory = new DefaultStylesFactory();
|
||||
packer = new LocalPacker(document, stylesFactory.newInstance(), properties, "build/tests/test.docx");
|
||||
//packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
|
||||
// packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
|
||||
});
|
||||
|
||||
describe('#pack()', () => {
|
||||
describe("#pack()", () => {
|
||||
|
||||
it("should create a standard docx file", (done) => {
|
||||
packer.pack();
|
||||
|
@ -4,23 +4,23 @@ import {Style} from "../docx/paragraph/style";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("ParagraphStyle", () => {
|
||||
var style: Style;
|
||||
let style: Style;
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a style with given value", () => {
|
||||
style = new Style("test");
|
||||
var newJson = jsonify(style);
|
||||
let newJson = jsonify(style);
|
||||
assert.equal(newJson.root[0].root.val, "test");
|
||||
});
|
||||
|
||||
it("should create a style with blank val", () => {
|
||||
style = new Style("");
|
||||
var newJson = jsonify(style);
|
||||
let newJson = jsonify(style);
|
||||
assert.equal(newJson.root[0].root.val, "");
|
||||
});
|
||||
});
|
||||
|
@ -4,22 +4,22 @@ import * as docx from "../docx";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Paragraph", () => {
|
||||
var paragraph: docx.Paragraph;
|
||||
let paragraph: docx.Paragraph;
|
||||
|
||||
beforeEach(() => {
|
||||
paragraph = new docx.Paragraph();
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create valid JSON", () => {
|
||||
var stringifiedJson = JSON.stringify(paragraph);
|
||||
var newJson;
|
||||
let stringifiedJson = JSON.stringify(paragraph);
|
||||
let newJson;
|
||||
|
||||
try {
|
||||
newJson = JSON.parse(stringifiedJson);
|
||||
@ -30,8 +30,8 @@ describe("Paragraph", () => {
|
||||
});
|
||||
|
||||
it("should create have valid properties", () => {
|
||||
var stringifiedJson = JSON.stringify(paragraph);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
let stringifiedJson = JSON.stringify(paragraph);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root[0].rootKey, "w:pPr");
|
||||
});
|
||||
});
|
||||
@ -39,7 +39,7 @@ describe("Paragraph", () => {
|
||||
describe("#heading1()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading1();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
|
||||
});
|
||||
});
|
||||
@ -47,7 +47,7 @@ describe("Paragraph", () => {
|
||||
describe("#heading2()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading2();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
|
||||
});
|
||||
@ -56,7 +56,7 @@ describe("Paragraph", () => {
|
||||
describe("#heading3()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading3();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
|
||||
});
|
||||
@ -65,7 +65,7 @@ describe("Paragraph", () => {
|
||||
describe("#title()", () => {
|
||||
it("should add title style to JSON", () => {
|
||||
paragraph.title();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
|
||||
});
|
||||
@ -74,7 +74,7 @@ describe("Paragraph", () => {
|
||||
describe("#center()", () => {
|
||||
it("should add center alignment to JSON", () => {
|
||||
paragraph.center();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
|
||||
});
|
||||
@ -83,7 +83,7 @@ describe("Paragraph", () => {
|
||||
describe("#thematicBreak()", () => {
|
||||
it("should add thematic break to JSON", () => {
|
||||
paragraph.thematicBreak();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
|
||||
});
|
||||
});
|
||||
@ -91,13 +91,13 @@ describe("Paragraph", () => {
|
||||
describe("#pageBreak()", () => {
|
||||
it("should add page break to JSON", () => {
|
||||
paragraph.pageBreak();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
|
||||
});
|
||||
|
||||
it("should add page break with 'page' type", () => {
|
||||
paragraph.pageBreak();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
|
||||
});
|
||||
});
|
||||
@ -105,13 +105,13 @@ describe("Paragraph", () => {
|
||||
describe("#bullet()", () => {
|
||||
it("should add list paragraph style to JSON", () => {
|
||||
paragraph.bullet();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
|
||||
});
|
||||
|
||||
it("it should add numbered properties", () => {
|
||||
paragraph.bullet();
|
||||
var newJson = jsonify(paragraph);
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.isDefined(newJson.root[0].root[2]);
|
||||
});
|
||||
});
|
||||
|
@ -4,12 +4,12 @@ import {Properties} from "../properties";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Properties", () => {
|
||||
var properties: Properties;
|
||||
let properties: Properties;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@ -20,8 +20,8 @@ describe("Properties", () => {
|
||||
properties = new Properties({
|
||||
title: "test document"
|
||||
});
|
||||
var newJson = jsonify(properties);
|
||||
let newJson = jsonify(properties);
|
||||
assert(newJson.root[1].root === "test document");
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
@ -1,54 +1,54 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
import {Run} from "../docx/run";
|
||||
import {TextRun} from "../docx//run/text-run"
|
||||
import {TextRun} from "../docx//run/text-run";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Run", () => {
|
||||
var run: Run;
|
||||
let run: Run;
|
||||
|
||||
beforeEach(() => {
|
||||
run = new Run();
|
||||
});
|
||||
|
||||
describe('#bold()', () => {
|
||||
describe("#bold()", () => {
|
||||
it("it should add bold to the properties", () => {
|
||||
run.bold();
|
||||
var newJson = jsonify(run);
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#italic()', () => {
|
||||
describe("#italic()", () => {
|
||||
it("it should add italics to the properties", () => {
|
||||
run.italic();
|
||||
var newJson = jsonify(run);
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#underline()', () => {
|
||||
describe("#underline()", () => {
|
||||
it("it should add underline to the properties", () => {
|
||||
run.underline();
|
||||
var newJson = jsonify(run);
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('TextRun', () => {
|
||||
var run: TextRun;
|
||||
describe("TextRun", () => {
|
||||
let run: TextRun;
|
||||
|
||||
describe('#constructor()', () => {
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should add text into run", () => {
|
||||
run = new TextRun("test");
|
||||
var newJson = jsonify(run);
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[1].root, "test");
|
||||
});
|
||||
});
|
||||
|
@ -4,19 +4,19 @@ import {Styles} from "../styles";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("Styles", () => {
|
||||
var styles: Styles;
|
||||
let styles: Styles;
|
||||
|
||||
beforeEach(() => {
|
||||
styles = new Styles();
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create styles with correct rootKey", () => {
|
||||
var styles = new Styles();
|
||||
var stringifiedJson = JSON.stringify(styles);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
|
||||
let styles = new Styles();
|
||||
let stringifiedJson = JSON.stringify(styles);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
|
||||
assert.equal(newJson.rootKey, "w:styles");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user