rearranged test locations
This commit is contained in:
55
ts/tests/docx/document/bodyTest.ts
Normal file
55
ts/tests/docx/document/bodyTest.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
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) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Body", () => {
|
||||
let body: 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", () => {
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[0].rootKey, "w:sectPr");
|
||||
});
|
||||
|
||||
it("should create the Page Size", () => {
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[1].rootKey, "w:pgSz");
|
||||
});
|
||||
|
||||
it("should create the Page Margin", () => {
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[2].rootKey, "w:pgMar");
|
||||
});
|
||||
|
||||
it("should create the Columns", () => {
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[3].rootKey, "w:cols");
|
||||
});
|
||||
|
||||
it("should create the Document Grid", () => {
|
||||
let newJson = jsonify(body);
|
||||
assert.equal(newJson.root[4].rootKey, "w:docGrid");
|
||||
});
|
||||
});
|
||||
});
|
28
ts/tests/docx/document/documentTest.ts
Normal file
28
ts/tests/docx/document/documentTest.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import * as docx from "../../../docx";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("Document", () => {
|
||||
let document: docx.Document;
|
||||
|
||||
beforeEach(() => {
|
||||
document = new docx.Document();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create valid JSON", () => {
|
||||
let stringifiedJson = JSON.stringify(document);
|
||||
let newJson;
|
||||
|
||||
try {
|
||||
newJson = JSON.parse(stringifiedJson);
|
||||
} catch (e) {
|
||||
assert.isTrue(false);
|
||||
}
|
||||
assert.isTrue(true);
|
||||
});
|
||||
});
|
||||
});
|
41
ts/tests/docx/document/xml-components/attributeTest.ts
Normal file
41
ts/tests/docx/document/xml-components/attributeTest.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/// <reference path="../../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import {Attributes} from "../../../../docx/xml-components";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe("Attribute", () => {
|
||||
let attributes: Attributes;
|
||||
|
||||
beforeEach(() => {
|
||||
attributes = new Attributes();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should not add val with empty constructor", () => {
|
||||
let newAttrs = new Attributes();
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.isUndefined(newJson.root.val);
|
||||
});
|
||||
|
||||
it("should have val as defined with populated constructor", () => {
|
||||
let newAttrs = new Attributes({
|
||||
val: "test"
|
||||
});
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root.val, "test");
|
||||
});
|
||||
|
||||
it("should have space value as defined with populated constructor", () => {
|
||||
let newAttrs = new Attributes({
|
||||
space: "spaceTest"
|
||||
});
|
||||
let stringifiedJson = JSON.stringify(newAttrs);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root.space, "spaceTest");
|
||||
});
|
||||
});
|
||||
});
|
35
ts/tests/docx/paragraph/borderTest.ts
Normal file
35
ts/tests/docx/paragraph/borderTest.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import {ThematicBreak} from "../../../docx/paragraph/border";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Border", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("ThematicBreak", () => {
|
||||
let thematicBreak: ThematicBreak;
|
||||
|
||||
beforeEach(() => {
|
||||
thematicBreak = new ThematicBreak();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Thematic Break with correct border properties", () => {
|
||||
let newJson = jsonify(thematicBreak);
|
||||
let attributes = {
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6"
|
||||
};
|
||||
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
||||
});
|
||||
});
|
||||
});
|
29
ts/tests/docx/paragraph/paragraphStyleTest.ts
Normal file
29
ts/tests/docx/paragraph/paragraphStyleTest.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import {Style} from "../../../docx/paragraph/style";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("ParagraphStyle", () => {
|
||||
let style: Style;
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a style with given value", () => {
|
||||
style = new Style("test");
|
||||
let newJson = 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);
|
||||
assert.equal(newJson.root[0].root.val, "");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
119
ts/tests/docx/paragraph/paragraphTest.ts
Normal file
119
ts/tests/docx/paragraph/paragraphTest.ts
Normal file
@ -0,0 +1,119 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import * as docx from "../../../docx";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Paragraph", () => {
|
||||
let paragraph: docx.Paragraph;
|
||||
|
||||
beforeEach(() => {
|
||||
paragraph = new docx.Paragraph();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create valid JSON", () => {
|
||||
let stringifiedJson = JSON.stringify(paragraph);
|
||||
let newJson;
|
||||
|
||||
try {
|
||||
newJson = JSON.parse(stringifiedJson);
|
||||
} catch (e) {
|
||||
assert.isTrue(false);
|
||||
}
|
||||
assert.isTrue(true);
|
||||
});
|
||||
|
||||
it("should create have valid properties", () => {
|
||||
let stringifiedJson = JSON.stringify(paragraph);
|
||||
let newJson = JSON.parse(stringifiedJson);
|
||||
assert.equal(newJson.root[0].rootKey, "w:pPr");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading1()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading1();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading2()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading2();
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading3()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading3();
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#title()", () => {
|
||||
it("should add title style to JSON", () => {
|
||||
paragraph.title();
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#center()", () => {
|
||||
it("should add center alignment to JSON", () => {
|
||||
paragraph.center();
|
||||
let newJson = jsonify(paragraph);
|
||||
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#thematicBreak()", () => {
|
||||
it("should add thematic break to JSON", () => {
|
||||
paragraph.thematicBreak();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pageBreak()", () => {
|
||||
it("should add page break to JSON", () => {
|
||||
paragraph.pageBreak();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
|
||||
});
|
||||
|
||||
it("should add page break with 'page' type", () => {
|
||||
paragraph.pageBreak();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#bullet()", () => {
|
||||
it("should add list paragraph style to JSON", () => {
|
||||
paragraph.bullet();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
|
||||
});
|
||||
|
||||
it("it should add numbered properties", () => {
|
||||
paragraph.bullet();
|
||||
let newJson = jsonify(paragraph);
|
||||
assert.isDefined(newJson.root[0].root[2]);
|
||||
});
|
||||
});
|
||||
});
|
56
ts/tests/docx/run/runTest.ts
Normal file
56
ts/tests/docx/run/runTest.ts
Normal file
@ -0,0 +1,56 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import {Run} from "../../../docx/run";
|
||||
import {TextRun} from "../../../docx/run/text-run";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Run", () => {
|
||||
let run: Run;
|
||||
|
||||
beforeEach(() => {
|
||||
run = new Run();
|
||||
});
|
||||
|
||||
describe("#bold()", () => {
|
||||
it("it should add bold to the properties", () => {
|
||||
run.bold();
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#italic()", () => {
|
||||
it("it should add italics to the properties", () => {
|
||||
run.italic();
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#underline()", () => {
|
||||
it("it should add underline to the properties", () => {
|
||||
run.underline();
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("TextRun", () => {
|
||||
let run: TextRun;
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should add text into run", () => {
|
||||
run = new TextRun("test");
|
||||
let newJson = jsonify(run);
|
||||
assert.equal(newJson.root[1].root, "test");
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user