From 84610bd72f6ac1eb0bab93afa54158f44d9de6b0 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sat, 9 Apr 2016 04:53:42 +0100 Subject: [PATCH] made all tests passing --- ts/docx/document/body/index.ts | 3 ++- ts/styles/style/components.ts | 49 ++++++++++++++++++++++++++++++++++ ts/tests/attributeTest.ts | 6 ++--- ts/tests/bodyTest.ts | 11 ++++++++ ts/tests/borderTest.ts | 4 +-- ts/tests/formatterTest.ts | 6 ++--- ts/tests/localPackerTest.ts | 2 +- ts/tests/paragraphStyleTest.ts | 6 ++--- ts/tests/paragraphTest.ts | 14 +++++----- 9 files changed, 81 insertions(+), 20 deletions(-) diff --git a/ts/docx/document/body/index.ts b/ts/docx/document/body/index.ts index efae74c4d3..a157928dbf 100644 --- a/ts/docx/document/body/index.ts +++ b/ts/docx/document/body/index.ts @@ -14,6 +14,7 @@ export class Body implements 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); } } diff --git a/ts/styles/style/components.ts b/ts/styles/style/components.ts index e69de29bb2..164a31ee15 100644 --- a/ts/styles/style/components.ts +++ b/ts/styles/style/components.ts @@ -0,0 +1,49 @@ +import {XmlComponent} from "../../docx/xml-components"; + +export class Name implements XmlComponent { + private name: Array; + + xmlKeys = { + + } + + constructor() { + this.name = new Array(); + } +} + +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 { + +} \ No newline at end of file diff --git a/ts/tests/attributeTest.ts b/ts/tests/attributeTest.ts index 0651e85ecb..b293425a81 100644 --- a/ts/tests/attributeTest.ts +++ b/ts/tests/attributeTest.ts @@ -16,7 +16,7 @@ describe("Attribute", () => { var newAttrs = new Attributes(); var stringifiedJson = JSON.stringify(newAttrs); var newJson = JSON.parse(stringifiedJson); - assert.isUndefined(newJson._attrs.val); + assert.isUndefined(newJson._attr.val); }); it("should have val as defined with populated constructor", () => { @@ -25,7 +25,7 @@ describe("Attribute", () => { }); var stringifiedJson = JSON.stringify(newAttrs); 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", () => { @@ -34,7 +34,7 @@ describe("Attribute", () => { }); var stringifiedJson = JSON.stringify(newAttrs); var newJson = JSON.parse(stringifiedJson); - assert(newJson._attrs.space === "spaceTest"); + assert(newJson._attr.space === "spaceTest"); }); }); }); \ No newline at end of file diff --git a/ts/tests/bodyTest.ts b/ts/tests/bodyTest.ts index 96e454c5d8..70aff66ca7 100644 --- a/ts/tests/bodyTest.ts +++ b/ts/tests/bodyTest.ts @@ -2,6 +2,11 @@ /// import {Body} from "../docx/document/body"; 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) { var stringifiedJson = JSON.stringify(obj); @@ -13,12 +18,18 @@ describe("Body", () => { beforeEach(() => { 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()", () => { it("should create the Section Properties", () => { var newJson = jsonify(body); + console.log(newJson); assert.isDefined(newJson.body[0].sectPr); }); diff --git a/ts/tests/borderTest.ts b/ts/tests/borderTest.ts index 5de067f29f..b81e8d0633 100644 --- a/ts/tests/borderTest.ts +++ b/ts/tests/borderTest.ts @@ -28,8 +28,8 @@ describe("ThematicBreak", () => { val: "single", sz: "6" }; - delete newJson.pBdr[0].bottom[0]._attrs.xmlKeys; - assert(JSON.stringify(newJson.pBdr[0].bottom[0]._attrs) === JSON.stringify(attributes)); + delete newJson.pBdr[0].bottom[0]._attr.xmlKeys; + assert(JSON.stringify(newJson.pBdr[0].bottom[0]._attr) === JSON.stringify(attributes)); }); }) }); \ No newline at end of file diff --git a/ts/tests/formatterTest.ts b/ts/tests/formatterTest.ts index dd27502723..146e180dd7 100644 --- a/ts/tests/formatterTest.ts +++ b/ts/tests/formatterTest.ts @@ -41,7 +41,7 @@ describe("Formatter", () => { paragraph.addText(new docx.TextRun("test").bold()); var newJson = formatter.format(paragraph); 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)", () => { @@ -50,7 +50,7 @@ describe("Formatter", () => { }); var newJson = formatter.format(attributes); newJson = jsonify(newJson); - assert.isDefined(newJson["_attrs"]["w:rsidSect"]); + assert.isDefined(newJson["_attr"]["w:rsidSect"]); }); it("should format attributes (val)", () => { @@ -59,7 +59,7 @@ describe("Formatter", () => { }); var newJson = formatter.format(attributes); 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", () => { diff --git a/ts/tests/localPackerTest.ts b/ts/tests/localPackerTest.ts index c8f65001d0..b8d1b55265 100644 --- a/ts/tests/localPackerTest.ts +++ b/ts/tests/localPackerTest.ts @@ -29,7 +29,7 @@ describe("Packer", () => { it("should create a standard docx file", (done) => { packer.pack(); - setTimeout(done, 3000); + setTimeout(done, 1900); }); }); }); \ No newline at end of file diff --git a/ts/tests/paragraphStyleTest.ts b/ts/tests/paragraphStyleTest.ts index 9f46c767a0..8f1be7b26d 100644 --- a/ts/tests/paragraphStyleTest.ts +++ b/ts/tests/paragraphStyleTest.ts @@ -8,20 +8,20 @@ function jsonify(obj: Object) { return JSON.parse(stringifiedJson); } -describe("Style", () => { +describe("ParagraphStyle", () => { var style: Style; describe("#constructor()", () => { it("should create a style with given value", () => { style = new Style("test"); 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", () => { style = new Style(""); var newJson = jsonify(style); - assert(newJson.pStyle[0]._attrs.val === ""); + assert(newJson.pStyle[0]._attr.val === ""); }); }); diff --git a/ts/tests/paragraphTest.ts b/ts/tests/paragraphTest.ts index 49ad10b32c..591b68ee08 100644 --- a/ts/tests/paragraphTest.ts +++ b/ts/tests/paragraphTest.ts @@ -35,7 +35,7 @@ describe("Paragraph", () => { paragraph.heading1(); 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(); 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(); 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(); 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(); 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", () => { paragraph.pageBreak(); 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", () => { paragraph.bullet(); 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", () => {