fixing tests

This commit is contained in:
Dolan Miu
2016-05-01 22:24:20 +01:00
parent 3f8d23662e
commit 879ac13863
9 changed files with 35 additions and 30 deletions

View File

@ -6,11 +6,6 @@ import {Paragraph} from "../paragraph";
export class Document extends XmlComponent {
private body: Body;
xmlKeys = {
document: "w:document",
body: "w:body"
};
constructor() {
super("w:document");
this.root.push(new DocumentAttributes({
@ -36,7 +31,13 @@ export class Document extends XmlComponent {
this.root.push(this.body);
}
addParagraph(paragraph: Paragraph) {
addParagraph(paragraph: Paragraph): void {
this.body.push(paragraph);
}
clearVariables(): void {
console.log("clearing");
this.body.clearVariables();
delete this.body;
}
}

View File

@ -8,6 +8,8 @@ export abstract class BaseXmlComponent {
}
abstract replaceKey(): void;
clearVariables(): void {
};
}
export abstract class XmlComponent extends BaseXmlComponent {
@ -23,7 +25,9 @@ export abstract class XmlComponent extends BaseXmlComponent {
//console.log(this.root);
if (this.root !== undefined) {
this.root.forEach(root => {
if (root && root instanceof BaseXmlComponent) {
root.replaceKey();
}
});
this[this.rootKey] = this.root;
delete this.root;

View File

@ -5,8 +5,9 @@ export class Formatter {
format(input: any): Object {
this.replaceKeys(input);
input.clearVariables();
var newJson = this.clense(input);
console.log(JSON.stringify(newJson, null, " "));
return newJson;
}

View File

@ -46,6 +46,7 @@ export abstract class Packer {
prefix: "root"
});*/
var xmlDocument = xml(this.formatter.format(this.document));
console.log(xmlDocument);
var xmlStyle = xml(this.style);
var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } });

View File

@ -2,13 +2,13 @@ import {XmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/xml-components/document-attributes";
abstract class Component extends XmlComponent {
protected createNullBlockOrValue(value: string): XmlComponent {
/*if (value === undefined) {
protected createNullBlockOrValue(value: string): any {
if (value === undefined) {
return [{}];
} else {
return value;
}*/
return null;
}
//return null;
}
}
export class Title extends Component {

View File

@ -36,12 +36,11 @@ describe("Formatter", () => {
assert(stringifiedJson.indexOf("xmlKeys") < 0);
});
it.only("should format simple paragraph with bold text", () => {
it("should format simple paragraph with bold text", () => {
var paragraph = new docx.Paragraph();
paragraph.addText(new docx.TextRun("test").bold());
var newJson = formatter.format(paragraph);
newJson = jsonify(newJson);
console.log(JSON.stringify(newJson, null, " "));
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
});

View File

@ -25,7 +25,7 @@ describe("Packer", () => {
packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
});
describe('#pack()', () => {
describe.only('#pack()', () => {
it("should create a standard docx file", (done) => {
packer.pack();

View File

@ -15,13 +15,14 @@ describe("ParagraphStyle", () => {
it("should create a style with given value", () => {
style = new Style("test");
var newJson = jsonify(style);
assert(newJson.pStyle[0]._attr.val === "test");
console.log(newJson.root[0].root.val);
assert.equal(newJson.root[0].root.val, "test");
});
it("should create a style with blank val", () => {
style = new Style("");
var newJson = jsonify(style);
assert(newJson.pStyle[0]._attr.val === "");
assert.equal(newJson.root[0].root.val, "");
});
});

View File

@ -34,8 +34,7 @@ describe("Paragraph", () => {
it("should add heading style to JSON", () => {
paragraph.heading1();
var newJson = jsonify(paragraph);
assert(newJson.root[1].root[1].root[0]._attr.val === "Heading1");
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
});
});
@ -44,7 +43,7 @@ describe("Paragraph", () => {
paragraph.heading2();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Heading2");
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
});
});
@ -53,7 +52,7 @@ describe("Paragraph", () => {
paragraph.heading3();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Heading3");
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
});
});
@ -62,7 +61,7 @@ describe("Paragraph", () => {
paragraph.title();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Title");
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
});
});
@ -71,7 +70,7 @@ describe("Paragraph", () => {
paragraph.center();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].jc[0]._attr.val === "center");
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
});
});
@ -79,8 +78,7 @@ describe("Paragraph", () => {
it("should add thematic break to JSON", () => {
paragraph.thematicBreak();
var newJson = jsonify(paragraph);
assert.isDefined(newJson.p[1].pPr[1].pBdr);
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
});
});
@ -88,13 +86,13 @@ describe("Paragraph", () => {
it("should add page break to JSON", () => {
paragraph.pageBreak();
var newJson = jsonify(paragraph);
assert.isDefined(newJson.p[1].pPr[1].r[1].br);
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);
assert(newJson.p[1].pPr[1].r[1].br[0]._attr.type === "page");
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
});
});
@ -102,13 +100,13 @@ describe("Paragraph", () => {
it("should add list paragraph style to JSON", () => {
paragraph.bullet();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "ListParagraph");
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
});
it("it should add numbered properties", () => {
paragraph.bullet();
var newJson = jsonify(paragraph);
assert.isDefined(newJson.p[1].pPr[2].numPr);
assert.isDefined(newJson.root[0].root[2]);
});
});
});