listing stuff
This commit is contained in:
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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, "");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -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");
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Spacing } from "../../../docx/paragraph/spacing";
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
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