made all tests passing

This commit is contained in:
Dolan Miu
2016-04-09 04:53:42 +01:00
parent aed59754cc
commit 84610bd72f
9 changed files with 81 additions and 20 deletions

View File

@ -14,6 +14,7 @@ export class Body implements XmlComponent {
} }
push(component: XmlComponent) { push(component: XmlComponent) {
this.body.splice(this.body.length - 1, 0, component); //this.body.splice(this.body.length - 1, 0, component);
this.body.push(component);
} }
} }

View File

@ -0,0 +1,49 @@
import {XmlComponent} from "../../docx/xml-components";
export class Name implements XmlComponent {
private name: Array<XmlComponent>;
xmlKeys = {
}
constructor() {
this.name = new Array<XmlComponent>();
}
}
export class BasedOn {
}
export class Next {
}
export class Link {
}
export class UiPriority {
}
export class UnhideWhenUsed {
}
export class QFormat {
}
export class TableProperties {
}
export class RsId {
}
export class SemiHidden {
}

View File

@ -16,7 +16,7 @@ describe("Attribute", () => {
var newAttrs = new Attributes(); var newAttrs = new Attributes();
var stringifiedJson = JSON.stringify(newAttrs); var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); var newJson = JSON.parse(stringifiedJson);
assert.isUndefined(newJson._attrs.val); assert.isUndefined(newJson._attr.val);
}); });
it("should have val as defined with populated constructor", () => { it("should have val as defined with populated constructor", () => {
@ -25,7 +25,7 @@ describe("Attribute", () => {
}); });
var stringifiedJson = JSON.stringify(newAttrs); var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); var newJson = JSON.parse(stringifiedJson);
assert(newJson._attrs.val === "test"); assert(newJson._attr.val === "test");
}); });
it("should have space value as defined with populated constructor", () => { it("should have space value as defined with populated constructor", () => {
@ -34,7 +34,7 @@ describe("Attribute", () => {
}); });
var stringifiedJson = JSON.stringify(newAttrs); var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); var newJson = JSON.parse(stringifiedJson);
assert(newJson._attrs.space === "spaceTest"); assert(newJson._attr.space === "spaceTest");
}); });
}); });
}); });

View File

@ -2,6 +2,11 @@
/// <reference path="../typings/chai/chai.d.ts" /> /// <reference path="../typings/chai/chai.d.ts" />
import {Body} from "../docx/document/body"; import {Body} from "../docx/document/body";
import {assert} from "chai"; import {assert} from "chai";
import {SectionProperties} from "../docx/document/body/section-properties";
import {PageSize} from "../docx/document/body/page-size";
import {PageMargin} from "../docx/document/body/page-margin";
import {Columns} from "../docx/document/body/columns";
import {DocumentGrid} from "../docx/document/body/doc-grid";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); var stringifiedJson = JSON.stringify(obj);
@ -13,12 +18,18 @@ describe("Body", () => {
beforeEach(() => { beforeEach(() => {
body = new Body(); body = new Body();
body.push(new SectionProperties());
body.push(new PageSize());
body.push(new PageMargin());
body.push(new Columns());
body.push(new DocumentGrid());
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create the Section Properties", () => { it("should create the Section Properties", () => {
var newJson = jsonify(body); var newJson = jsonify(body);
console.log(newJson);
assert.isDefined(newJson.body[0].sectPr); assert.isDefined(newJson.body[0].sectPr);
}); });

View File

@ -28,8 +28,8 @@ describe("ThematicBreak", () => {
val: "single", val: "single",
sz: "6" sz: "6"
}; };
delete newJson.pBdr[0].bottom[0]._attrs.xmlKeys; delete newJson.pBdr[0].bottom[0]._attr.xmlKeys;
assert(JSON.stringify(newJson.pBdr[0].bottom[0]._attrs) === JSON.stringify(attributes)); assert(JSON.stringify(newJson.pBdr[0].bottom[0]._attr) === JSON.stringify(attributes));
}); });
}) })
}); });

View File

@ -41,7 +41,7 @@ describe("Formatter", () => {
paragraph.addText(new docx.TextRun("test").bold()); paragraph.addText(new docx.TextRun("test").bold());
var newJson = formatter.format(paragraph); var newJson = formatter.format(paragraph);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["w:p"][3]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attrs"]["w:val"]); assert.isDefined(newJson["w:p"][3]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
}); });
it("should format attributes (rsidSect)", () => { it("should format attributes (rsidSect)", () => {
@ -50,7 +50,7 @@ describe("Formatter", () => {
}); });
var newJson = formatter.format(attributes); var newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["_attrs"]["w:rsidSect"]); assert.isDefined(newJson["_attr"]["w:rsidSect"]);
}); });
it("should format attributes (val)", () => { it("should format attributes (val)", () => {
@ -59,7 +59,7 @@ describe("Formatter", () => {
}); });
var newJson = formatter.format(attributes); var newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["_attrs"]["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", () => {

View File

@ -29,7 +29,7 @@ describe("Packer", () => {
it("should create a standard docx file", (done) => { it("should create a standard docx file", (done) => {
packer.pack(); packer.pack();
setTimeout(done, 3000); setTimeout(done, 1900);
}); });
}); });
}); });

View File

@ -8,20 +8,20 @@ function jsonify(obj: Object) {
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Style", () => { describe("ParagraphStyle", () => {
var style: Style; var style: Style;
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a style with given value", () => { it("should create a style with given value", () => {
style = new Style("test"); style = new Style("test");
var newJson = jsonify(style); var newJson = jsonify(style);
assert(newJson.pStyle[0]._attrs.val === "test"); assert(newJson.pStyle[0]._attr.val === "test");
}); });
it("should create a style with blank val", () => { it("should create a style with blank val", () => {
style = new Style(""); style = new Style("");
var newJson = jsonify(style); var newJson = jsonify(style);
assert(newJson.pStyle[0]._attrs.val === ""); assert(newJson.pStyle[0]._attr.val === "");
}); });
}); });

View File

@ -35,7 +35,7 @@ describe("Paragraph", () => {
paragraph.heading1(); paragraph.heading1();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading1"); assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Heading1");
}); });
}); });
@ -44,7 +44,7 @@ describe("Paragraph", () => {
paragraph.heading2(); paragraph.heading2();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading2"); assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Heading2");
}); });
}); });
@ -53,7 +53,7 @@ describe("Paragraph", () => {
paragraph.heading3(); paragraph.heading3();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading3"); assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Heading3");
}); });
}); });
@ -62,7 +62,7 @@ describe("Paragraph", () => {
paragraph.title(); paragraph.title();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Title"); assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "Title");
}); });
}); });
@ -71,7 +71,7 @@ describe("Paragraph", () => {
paragraph.center(); paragraph.center();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].jc[0]._attrs.val === "center"); assert(newJson.p[1].pPr[1].jc[0]._attr.val === "center");
}); });
}); });
@ -94,7 +94,7 @@ describe("Paragraph", () => {
it("should add page break with 'page' type", () => { it("should add page break with 'page' type", () => {
paragraph.pageBreak(); paragraph.pageBreak();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].r[1].br[0]._attrs.type === "page"); assert(newJson.p[1].pPr[1].r[1].br[0]._attr.type === "page");
}); });
}); });
@ -102,7 +102,7 @@ describe("Paragraph", () => {
it("should add list paragraph style to JSON", () => { it("should add list paragraph style to JSON", () => {
paragraph.bullet(); paragraph.bullet();
var newJson = jsonify(paragraph); var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "ListParagraph"); assert(newJson.p[1].pPr[1].pStyle[0]._attr.val === "ListParagraph");
}); });
it("it should add numbered properties", () => { it("it should add numbered properties", () => {