added paragraph styles

This commit is contained in:
Dolan Miu
2016-03-29 04:10:33 +01:00
parent 18c92426ad
commit c2b215e81b
6 changed files with 214 additions and 46 deletions

29
ts/tests/attributeTest.ts Normal file
View File

@ -0,0 +1,29 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import {Attributes} from "../docx/xml-components/p";
import {assert} from "chai";
describe('Attribute', () => {
var attributes: Attributes;
beforeEach(() => {
attributes = new Attributes();
});
describe('#constructor()', () => {
it("should not add val with empty constructor", () => {
var newAttrs = new Attributes();
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
assert.isUndefined(newJson._attrs.val);
});
it("should have val as defined with populated constructor", () => {
var newAttrs = new Attributes("test");
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
assert(newJson._attrs.val === "test");
});
});
});

28
ts/tests/documentTest.ts Normal file
View 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', () => {
var document: docx.Document;
beforeEach(() => {
document = new docx.Document();
});
describe('#constructor()', () => {
it("should create valid JSON", () => {
console.log(JSON.stringify(document, null, " "));
var stringifiedJson = JSON.stringify(document);
var newJson;
try {
newJson = JSON.parse(stringifiedJson);
} catch (e) {
assert.isTrue(false);
}
assert.isTrue(true);
});
});
});

View File

@ -1,41 +0,0 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import * as docx from "../docx";
import {assert, } from "chai";
describe('Calculator', () => {
var document: docx.Document;
/*beforeEach(function () {
subject = new Calculator();
});
describe('#add', () => {
it('should add two numbers together', () => {
var result : number = subject.add(2, 3);
if (result !== 5) {
throw new Error('Expected 2 + 3 = 5 but was ' + result);
}
});
});*/
describe('#test', () => {
var document = new docx.Document();
var paragraph = new docx.Paragraph();
//var body = new docx.Body();
console.log(paragraph);
console.log(JSON.stringify(paragraph, null, " "));
console.log(document.test());
it("should create valid JSON", () => {
var stringifiedJson = JSON.stringify(document);
var newJson;
try {
newJson = JSON.parse(stringifiedJson);
} catch (e) {
assert.isTrue(false);
}
assert.isTrue(true);
});
});
});

70
ts/tests/paragraphTest.ts Normal file
View File

@ -0,0 +1,70 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import * as docx from "../docx";
import {assert} from "chai";
describe('Paragraph', () => {
var paragraph: docx.Paragraph;
beforeEach(() => {
paragraph = new docx.Paragraph();
});
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe('#constructor()', () => {
it("should create valid JSON", () => {
console.log(JSON.stringify(paragraph, null, " "));
var stringifiedJson = JSON.stringify(paragraph);
var newJson;
try {
newJson = JSON.parse(stringifiedJson);
} catch (e) {
assert.isTrue(false);
}
assert.isTrue(true);
});
});
describe("#heading1()", () => {
it("should add heading style to JSON", () => {
paragraph.heading1();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading1");
});
});
describe("#heading2()", () => {
it("should add heading style to JSON", () => {
paragraph.heading2();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading2");
});
});
describe("#heading3()", () => {
it("should add heading style to JSON", () => {
paragraph.heading3();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Heading3");
});
});
describe("#title()", () => {
it("should add title style to JSON", () => {
paragraph.title();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Title");
});
});
});