diff --git a/ts/tests/docx/document/bodyTest.ts b/ts/tests/docx/document/bodyTest.ts index 6fb47558fd..bbb8dcf42e 100644 --- a/ts/tests/docx/document/bodyTest.ts +++ b/ts/tests/docx/document/bodyTest.ts @@ -1,15 +1,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 { Body } from "../../../docx/document/body"; import { Columns } from "../../../docx/document/body/columns"; import { DocumentGrid } from "../../../docx/document/body/doc-grid"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { PageMargin } from "../../../docx/document/body/page-margin"; +import { PageSize } from "../../../docx/document/body/page-size"; +import { SectionProperties } from "../../../docx/document/body/section-properties"; +import { Utility } from "../../utility"; describe("Body", () => { let body: Body; @@ -26,28 +22,28 @@ describe("Body", () => { describe("#constructor()", () => { it("should create the Section Properties", () => { - let newJson = jsonify(body); + const newJson = Utility.jsonify(body); assert.equal(newJson.root[0].rootKey, "w:sectPr"); }); it("should create the Page Size", () => { - let newJson = jsonify(body); + const newJson = Utility.jsonify(body); assert.equal(newJson.root[1].rootKey, "w:pgSz"); }); it("should create the Page Margin", () => { - let newJson = jsonify(body); + const newJson = Utility.jsonify(body); assert.equal(newJson.root[2].rootKey, "w:pgMar"); }); it("should create the Columns", () => { - let newJson = jsonify(body); + const newJson = Utility.jsonify(body); assert.equal(newJson.root[3].rootKey, "w:cols"); }); it("should create the Document Grid", () => { - let newJson = jsonify(body); + const newJson = Utility.jsonify(body); assert.equal(newJson.root[4].rootKey, "w:docGrid"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/document/documentTest.ts b/ts/tests/docx/document/documentTest.ts index 02e67e71e2..43b352a1a7 100644 --- a/ts/tests/docx/document/documentTest.ts +++ b/ts/tests/docx/document/documentTest.ts @@ -1,5 +1,5 @@ -import * as docx from "../../../docx"; import { assert } from "chai"; +import * as docx from "../../../docx"; describe("Document", () => { let document: docx.Document; @@ -11,7 +11,7 @@ describe("Document", () => { describe("#constructor()", () => { it("should create valid JSON", () => { - let stringifiedJson = JSON.stringify(document); + const stringifiedJson = JSON.stringify(document); let newJson; try { @@ -22,4 +22,4 @@ describe("Document", () => { assert.isTrue(true); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/borderTest.ts b/ts/tests/docx/paragraph/borderTest.ts index 761a066c2d..e7af104bd3 100644 --- a/ts/tests/docx/paragraph/borderTest.ts +++ b/ts/tests/docx/paragraph/borderTest.ts @@ -1,13 +1,9 @@ -import { ThematicBreak } from "../../../docx/paragraph/border"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { ThematicBreak } from "../../../docx/paragraph/border"; +import { Utility } from "../../utility"; describe("Border", () => { - + // TODO: Need tests here }); describe("ThematicBreak", () => { @@ -19,14 +15,14 @@ describe("ThematicBreak", () => { describe("#constructor()", () => { it("should create a Thematic Break with correct border properties", () => { - let newJson = jsonify(thematicBreak); - let attributes = { + const newJson = Utility.jsonify(thematicBreak); + const attributes = { color: "auto", space: "1", val: "single", - sz: "6" + sz: "6", }; assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/pageBreakTests.ts b/ts/tests/docx/paragraph/pageBreakTests.ts index b142a6f314..28c2b15257 100644 --- a/ts/tests/docx/paragraph/pageBreakTests.ts +++ b/ts/tests/docx/paragraph/pageBreakTests.ts @@ -1,10 +1,6 @@ -import { PageBreak } from "../../../docx/paragraph/page-break"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { PageBreak } from "../../../docx/paragraph/page-break"; +import { Utility } from "../../utility"; describe("PageBreak", () => { let pageBreak: PageBreak; @@ -15,21 +11,21 @@ describe("PageBreak", () => { describe("#constructor()", () => { it("should create a Page Break with correct attributes", () => { - let newJson = jsonify(pageBreak); - let attributes = { - type: "page" + const newJson = Utility.jsonify(pageBreak); + const attributes = { + type: "page", }; assert.equal(JSON.stringify(newJson.root[1].root[0].root), JSON.stringify(attributes)); }); it("should create a Page Break with w:r", () => { - let newJson = jsonify(pageBreak); + const newJson = Utility.jsonify(pageBreak); assert.equal(newJson.rootKey, "w:r"); }); it("should create a Page Break with a Break inside", () => { - let newJson = jsonify(pageBreak); + const newJson = Utility.jsonify(pageBreak); assert.equal(newJson.root[1].rootKey, "w:br"); }); }); -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/paragraphStyleTest.ts b/ts/tests/docx/paragraph/paragraphStyleTest.ts index af05ac460a..1b9ceae4a6 100644 --- a/ts/tests/docx/paragraph/paragraphStyleTest.ts +++ b/ts/tests/docx/paragraph/paragraphStyleTest.ts @@ -1,10 +1,6 @@ -import { Style } from "../../../docx/paragraph/style"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Style } from "../../../docx/paragraph/style"; +import { Utility } from "../../utility"; describe("ParagraphStyle", () => { let style: Style; @@ -12,15 +8,14 @@ describe("ParagraphStyle", () => { describe("#constructor()", () => { it("should create a style with given value", () => { style = new Style("test"); - let newJson = jsonify(style); + const newJson = Utility.jsonify(style); assert.equal(newJson.root[0].root.val, "test"); }); it("should create a style with blank val", () => { style = new Style(""); - let newJson = jsonify(style); + const newJson = Utility.jsonify(style); assert.equal(newJson.root[0].root.val, ""); }); }); - -}); \ No newline at end of file +}); diff --git a/ts/tests/docx/paragraph/paragraphTests.ts b/ts/tests/docx/paragraph/paragraphTests.ts index fbab274f26..6116a206c6 100644 --- a/ts/tests/docx/paragraph/paragraphTests.ts +++ b/ts/tests/docx/paragraph/paragraphTests.ts @@ -1,13 +1,8 @@ import { assert, expect } from "chai"; - import * as docx from "../../../docx"; import { Formatter } from "../../../export/formatter"; import { Numbering } from "../../../numbering"; - -function jsonify(obj: object) { - const stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { Utility } from "../../utility"; describe("Paragraph", () => { let paragraph: docx.Paragraph; @@ -40,7 +35,7 @@ describe("Paragraph", () => { describe("#heading1()", () => { it("should add heading style to JSON", () => { paragraph.heading1(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1"); }); }); @@ -48,7 +43,7 @@ describe("Paragraph", () => { describe("#heading2()", () => { it("should add heading style to JSON", () => { paragraph.heading2(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2"); }); @@ -57,7 +52,7 @@ describe("Paragraph", () => { describe("#heading3()", () => { it("should add heading style to JSON", () => { paragraph.heading3(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3"); }); @@ -66,7 +61,7 @@ describe("Paragraph", () => { describe("#title()", () => { it("should add title style to JSON", () => { paragraph.title(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "Title"); }); @@ -75,7 +70,7 @@ describe("Paragraph", () => { describe("#center()", () => { it("should add center alignment to JSON", () => { paragraph.center(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "center"); }); @@ -84,7 +79,7 @@ describe("Paragraph", () => { describe("#thematicBreak()", () => { it("should add thematic break to JSON", () => { paragraph.thematicBreak(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr"); }); }); @@ -92,13 +87,13 @@ describe("Paragraph", () => { describe("#pageBreak()", () => { it("should add page break to JSON", () => { paragraph.pageBreak(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br"); }); it("should add page break with 'page' type", () => { paragraph.pageBreak(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page"); }); }); @@ -106,13 +101,13 @@ describe("Paragraph", () => { describe("#bullet()", () => { it("should add list paragraph style to JSON", () => { paragraph.bullet(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph"); }); it("it should add numbered properties", () => { paragraph.bullet(); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.isDefined(newJson.root[0].root[2]); }); }); @@ -125,7 +120,7 @@ describe("Paragraph", () => { const letterNumbering = numbering.createConcreteNumbering(numberedAbstract); paragraph.setNumbering(letterNumbering, 0); - const newJson = jsonify(paragraph); + const newJson = Utility.jsonify(paragraph); assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph"); }); diff --git a/ts/tests/docx/paragraph/spacingTest.ts b/ts/tests/docx/paragraph/spacingTest.ts index e09e9e9042..f5b458e2bd 100644 --- a/ts/tests/docx/paragraph/spacingTest.ts +++ b/ts/tests/docx/paragraph/spacingTest.ts @@ -1,5 +1,4 @@ import { expect } from "chai"; - import { Spacing } from "../../../docx/paragraph/spacing"; import { Formatter } from "../../../export/formatter"; diff --git a/ts/tests/docx/paragraph/unorderedListTests.ts b/ts/tests/docx/paragraph/unorderedListTests.ts index ab1b14f474..f6a4636b65 100644 --- a/ts/tests/docx/paragraph/unorderedListTests.ts +++ b/ts/tests/docx/paragraph/unorderedListTests.ts @@ -1,10 +1,6 @@ -import { NumberProperties } from "../../../docx/paragraph/unordered-list"; import { assert } from "chai"; - -function jsonify(obj: Object) { - let stringifiedJson = JSON.stringify(obj); - return JSON.parse(stringifiedJson); -} +import { NumberProperties } from "../../../docx/paragraph/unordered-list"; +import { Utility } from "../../utility"; describe("NumberProperties", () => { let numberProperties: NumberProperties; @@ -15,18 +11,18 @@ describe("NumberProperties", () => { describe("#constructor()", () => { it("should create a Number Properties with correct root key", () => { - let newJson = jsonify(numberProperties); + const newJson = Utility.jsonify(numberProperties); assert.equal(newJson.rootKey, "w:numPr"); }); it("should create a Page Break with a Indent Level inside", () => { - let newJson = jsonify(numberProperties); + const newJson = Utility.jsonify(numberProperties); assert.equal(newJson.root[0].rootKey, "w:ilvl"); assert.equal(newJson.root[0].root[0].root.val, 10); }); it("should create a Page Break with a Number Id inside", () => { - let newJson = jsonify(numberProperties); + const newJson = Utility.jsonify(numberProperties); assert.equal(newJson.root[1].rootKey, "w:numId"); assert.equal(newJson.root[1].root[0].root.val, 5); }); diff --git a/ts/tests/utility.ts b/ts/tests/utility.ts new file mode 100644 index 0000000000..51389b6b37 --- /dev/null +++ b/ts/tests/utility.ts @@ -0,0 +1,6 @@ +export class Utility { + public static jsonify(obj: Object) { + const stringifiedJson = JSON.stringify(obj); + return JSON.parse(stringifiedJson); + } +}