listing stuff
This commit is contained in:
@ -1,15 +1,11 @@
|
|||||||
import { Body } from "../../../docx/document/body";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { SectionProperties } from "../../../docx/document/body/section-properties";
|
import { Body } from "../../../docx/document/body";
|
||||||
import { PageSize } from "../../../docx/document/body/page-size";
|
|
||||||
import { PageMargin } from "../../../docx/document/body/page-margin";
|
|
||||||
import { Columns } from "../../../docx/document/body/columns";
|
import { Columns } from "../../../docx/document/body/columns";
|
||||||
import { DocumentGrid } from "../../../docx/document/body/doc-grid";
|
import { DocumentGrid } from "../../../docx/document/body/doc-grid";
|
||||||
|
import { PageMargin } from "../../../docx/document/body/page-margin";
|
||||||
function jsonify(obj: Object) {
|
import { PageSize } from "../../../docx/document/body/page-size";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
import { SectionProperties } from "../../../docx/document/body/section-properties";
|
||||||
return JSON.parse(stringifiedJson);
|
import { Utility } from "../../utility";
|
||||||
}
|
|
||||||
|
|
||||||
describe("Body", () => {
|
describe("Body", () => {
|
||||||
let body: Body;
|
let body: Body;
|
||||||
@ -26,28 +22,28 @@ describe("Body", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
|
|
||||||
it("should create the Section Properties", () => {
|
it("should create the Section Properties", () => {
|
||||||
let newJson = jsonify(body);
|
const newJson = Utility.jsonify(body);
|
||||||
assert.equal(newJson.root[0].rootKey, "w:sectPr");
|
assert.equal(newJson.root[0].rootKey, "w:sectPr");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create the Page Size", () => {
|
it("should create the Page Size", () => {
|
||||||
let newJson = jsonify(body);
|
const newJson = Utility.jsonify(body);
|
||||||
assert.equal(newJson.root[1].rootKey, "w:pgSz");
|
assert.equal(newJson.root[1].rootKey, "w:pgSz");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create the Page Margin", () => {
|
it("should create the Page Margin", () => {
|
||||||
let newJson = jsonify(body);
|
const newJson = Utility.jsonify(body);
|
||||||
assert.equal(newJson.root[2].rootKey, "w:pgMar");
|
assert.equal(newJson.root[2].rootKey, "w:pgMar");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create the Columns", () => {
|
it("should create the Columns", () => {
|
||||||
let newJson = jsonify(body);
|
const newJson = Utility.jsonify(body);
|
||||||
assert.equal(newJson.root[3].rootKey, "w:cols");
|
assert.equal(newJson.root[3].rootKey, "w:cols");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create the Document Grid", () => {
|
it("should create the Document Grid", () => {
|
||||||
let newJson = jsonify(body);
|
const newJson = Utility.jsonify(body);
|
||||||
assert.equal(newJson.root[4].rootKey, "w:docGrid");
|
assert.equal(newJson.root[4].rootKey, "w:docGrid");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as docx from "../../../docx";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
import * as docx from "../../../docx";
|
||||||
|
|
||||||
describe("Document", () => {
|
describe("Document", () => {
|
||||||
let document: docx.Document;
|
let document: docx.Document;
|
||||||
@ -11,7 +11,7 @@ describe("Document", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
|
|
||||||
it("should create valid JSON", () => {
|
it("should create valid JSON", () => {
|
||||||
let stringifiedJson = JSON.stringify(document);
|
const stringifiedJson = JSON.stringify(document);
|
||||||
let newJson;
|
let newJson;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -22,4 +22,4 @@ describe("Document", () => {
|
|||||||
assert.isTrue(true);
|
assert.isTrue(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
import { ThematicBreak } from "../../../docx/paragraph/border";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
import { ThematicBreak } from "../../../docx/paragraph/border";
|
||||||
function jsonify(obj: Object) {
|
import { Utility } from "../../utility";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
|
||||||
return JSON.parse(stringifiedJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Border", () => {
|
describe("Border", () => {
|
||||||
|
// TODO: Need tests here
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ThematicBreak", () => {
|
describe("ThematicBreak", () => {
|
||||||
@ -19,14 +15,14 @@ describe("ThematicBreak", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Thematic Break with correct border properties", () => {
|
it("should create a Thematic Break with correct border properties", () => {
|
||||||
let newJson = jsonify(thematicBreak);
|
const newJson = Utility.jsonify(thematicBreak);
|
||||||
let attributes = {
|
const attributes = {
|
||||||
color: "auto",
|
color: "auto",
|
||||||
space: "1",
|
space: "1",
|
||||||
val: "single",
|
val: "single",
|
||||||
sz: "6"
|
sz: "6",
|
||||||
};
|
};
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { PageBreak } from "../../../docx/paragraph/page-break";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
import { PageBreak } from "../../../docx/paragraph/page-break";
|
||||||
function jsonify(obj: Object) {
|
import { Utility } from "../../utility";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
|
||||||
return JSON.parse(stringifiedJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("PageBreak", () => {
|
describe("PageBreak", () => {
|
||||||
let pageBreak: PageBreak;
|
let pageBreak: PageBreak;
|
||||||
@ -15,21 +11,21 @@ describe("PageBreak", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Page Break with correct attributes", () => {
|
it("should create a Page Break with correct attributes", () => {
|
||||||
let newJson = jsonify(pageBreak);
|
const newJson = Utility.jsonify(pageBreak);
|
||||||
let attributes = {
|
const attributes = {
|
||||||
type: "page"
|
type: "page",
|
||||||
};
|
};
|
||||||
assert.equal(JSON.stringify(newJson.root[1].root[0].root), JSON.stringify(attributes));
|
assert.equal(JSON.stringify(newJson.root[1].root[0].root), JSON.stringify(attributes));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with w:r", () => {
|
it("should create a Page Break with w:r", () => {
|
||||||
let newJson = jsonify(pageBreak);
|
const newJson = Utility.jsonify(pageBreak);
|
||||||
assert.equal(newJson.rootKey, "w:r");
|
assert.equal(newJson.rootKey, "w:r");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with a Break inside", () => {
|
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");
|
assert.equal(newJson.root[1].rootKey, "w:br");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { Style } from "../../../docx/paragraph/style";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
import { Style } from "../../../docx/paragraph/style";
|
||||||
function jsonify(obj: Object) {
|
import { Utility } from "../../utility";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
|
||||||
return JSON.parse(stringifiedJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("ParagraphStyle", () => {
|
describe("ParagraphStyle", () => {
|
||||||
let style: Style;
|
let style: Style;
|
||||||
@ -12,15 +8,14 @@ describe("ParagraphStyle", () => {
|
|||||||
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");
|
||||||
let newJson = jsonify(style);
|
const newJson = Utility.jsonify(style);
|
||||||
assert.equal(newJson.root[0].root.val, "test");
|
assert.equal(newJson.root[0].root.val, "test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a style with blank val", () => {
|
it("should create a style with blank val", () => {
|
||||||
style = new Style("");
|
style = new Style("");
|
||||||
let newJson = jsonify(style);
|
const newJson = Utility.jsonify(style);
|
||||||
assert.equal(newJson.root[0].root.val, "");
|
assert.equal(newJson.root[0].root.val, "");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
|
|
||||||
import * as docx from "../../../docx";
|
import * as docx from "../../../docx";
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../../export/formatter";
|
||||||
import { Numbering } from "../../../numbering";
|
import { Numbering } from "../../../numbering";
|
||||||
|
import { Utility } from "../../utility";
|
||||||
function jsonify(obj: object) {
|
|
||||||
const stringifiedJson = JSON.stringify(obj);
|
|
||||||
return JSON.parse(stringifiedJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Paragraph", () => {
|
describe("Paragraph", () => {
|
||||||
let paragraph: docx.Paragraph;
|
let paragraph: docx.Paragraph;
|
||||||
@ -40,7 +35,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#heading1()", () => {
|
describe("#heading1()", () => {
|
||||||
it("should add heading style to JSON", () => {
|
it("should add heading style to JSON", () => {
|
||||||
paragraph.heading1();
|
paragraph.heading1();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -48,7 +43,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#heading2()", () => {
|
describe("#heading2()", () => {
|
||||||
it("should add heading style to JSON", () => {
|
it("should add heading style to JSON", () => {
|
||||||
paragraph.heading2();
|
paragraph.heading2();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
|
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
|
||||||
});
|
});
|
||||||
@ -57,7 +52,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#heading3()", () => {
|
describe("#heading3()", () => {
|
||||||
it("should add heading style to JSON", () => {
|
it("should add heading style to JSON", () => {
|
||||||
paragraph.heading3();
|
paragraph.heading3();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
|
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
|
||||||
});
|
});
|
||||||
@ -66,7 +61,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#title()", () => {
|
describe("#title()", () => {
|
||||||
it("should add title style to JSON", () => {
|
it("should add title style to JSON", () => {
|
||||||
paragraph.title();
|
paragraph.title();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
|
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
|
||||||
});
|
});
|
||||||
@ -75,7 +70,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#center()", () => {
|
describe("#center()", () => {
|
||||||
it("should add center alignment to JSON", () => {
|
it("should add center alignment to JSON", () => {
|
||||||
paragraph.center();
|
paragraph.center();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
|
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
|
||||||
});
|
});
|
||||||
@ -84,7 +79,7 @@ describe("Paragraph", () => {
|
|||||||
describe("#thematicBreak()", () => {
|
describe("#thematicBreak()", () => {
|
||||||
it("should add thematic break to JSON", () => {
|
it("should add thematic break to JSON", () => {
|
||||||
paragraph.thematicBreak();
|
paragraph.thematicBreak();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
|
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -92,13 +87,13 @@ describe("Paragraph", () => {
|
|||||||
describe("#pageBreak()", () => {
|
describe("#pageBreak()", () => {
|
||||||
it("should add page break to JSON", () => {
|
it("should add page break to JSON", () => {
|
||||||
paragraph.pageBreak();
|
paragraph.pageBreak();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
|
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add page break with 'page' type", () => {
|
it("should add page break with 'page' type", () => {
|
||||||
paragraph.pageBreak();
|
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");
|
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -106,13 +101,13 @@ describe("Paragraph", () => {
|
|||||||
describe("#bullet()", () => {
|
describe("#bullet()", () => {
|
||||||
it("should add list paragraph style to JSON", () => {
|
it("should add list paragraph style to JSON", () => {
|
||||||
paragraph.bullet();
|
paragraph.bullet();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("it should add numbered properties", () => {
|
it("it should add numbered properties", () => {
|
||||||
paragraph.bullet();
|
paragraph.bullet();
|
||||||
const newJson = jsonify(paragraph);
|
const newJson = Utility.jsonify(paragraph);
|
||||||
assert.isDefined(newJson.root[0].root[2]);
|
assert.isDefined(newJson.root[0].root[2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -125,7 +120,7 @@ describe("Paragraph", () => {
|
|||||||
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
|
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
|
||||||
|
|
||||||
paragraph.setNumbering(letterNumbering, 0);
|
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");
|
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Spacing } from "../../../docx/paragraph/spacing";
|
import { Spacing } from "../../../docx/paragraph/spacing";
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../../export/formatter";
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { NumberProperties } from "../../../docx/paragraph/unordered-list";
|
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
import { NumberProperties } from "../../../docx/paragraph/unordered-list";
|
||||||
function jsonify(obj: Object) {
|
import { Utility } from "../../utility";
|
||||||
let stringifiedJson = JSON.stringify(obj);
|
|
||||||
return JSON.parse(stringifiedJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("NumberProperties", () => {
|
describe("NumberProperties", () => {
|
||||||
let numberProperties: NumberProperties;
|
let numberProperties: NumberProperties;
|
||||||
@ -15,18 +11,18 @@ describe("NumberProperties", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Number Properties with correct root key", () => {
|
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");
|
assert.equal(newJson.rootKey, "w:numPr");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with a Indent Level inside", () => {
|
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].rootKey, "w:ilvl");
|
||||||
assert.equal(newJson.root[0].root[0].root.val, 10);
|
assert.equal(newJson.root[0].root[0].root.val, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Page Break with a Number Id inside", () => {
|
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].rootKey, "w:numId");
|
||||||
assert.equal(newJson.root[1].root[0].root.val, 5);
|
assert.equal(newJson.root[1].root[0].root.val, 5);
|
||||||
});
|
});
|
||||||
|
6
ts/tests/utility.ts
Normal file
6
ts/tests/utility.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export class Utility {
|
||||||
|
public static jsonify(obj: Object) {
|
||||||
|
const stringifiedJson = JSON.stringify(obj);
|
||||||
|
return JSON.parse(stringifiedJson);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user