wrote lots of tests

This commit is contained in:
Dolan Miu
2016-07-18 19:17:19 +01:00
parent d23583f9b5
commit 078196c6d6
8 changed files with 151 additions and 6 deletions

View File

@ -5,7 +5,7 @@ abstract class VerticalAlign extends XmlComponent {
constructor(type: string) {
super("w:vertAlign");
this.root.push(new Attributes({
val: "superscript"
val: type
}));
}
}

View File

@ -14,7 +14,7 @@ describe("PageBreak", () => {
});
describe("#constructor()", () => {
it("should create a Tab Stop with correct attributes", () => {
it("should create a Page Break with correct attributes", () => {
let newJson = jsonify(pageBreak);
let attributes = {
type: "page"

View File

@ -6,7 +6,7 @@ function jsonify(obj: Object) {
return JSON.parse(stringifiedJson);
}
describe.only("Break", () => {
describe("Break", () => {
let currentBreak: Break;
beforeEach(() => {

View File

@ -1,6 +1,3 @@
/// <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";

View File

@ -0,0 +1,53 @@
import {SubScript, SuperScript} from "../../../docx/run/script";
import {assert} from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("SubScript", () => {
let subScript: SubScript;
beforeEach(() => {
subScript = new SubScript();
});
describe("#constructor()", () => {
it("should create a Sub Script with correct attributes", () => {
let newJson = jsonify(subScript);
let attributes = {
val: "subscript"
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
it("should create a Sub Script with correct root key", () => {
let newJson = jsonify(subScript);
assert.equal(newJson.rootKey, "w:vertAlign");
});
});
});
describe("SuperScript", () => {
let superScript: SuperScript;
beforeEach(() => {
superScript = new SuperScript();
});
describe("#constructor()", () => {
it("should create a Super Script with correct attributes", () => {
let newJson = jsonify(superScript);
let attributes = {
val: "superscript"
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
it("should create a Super Script with correct root key", () => {
let newJson = jsonify(superScript);
assert.equal(newJson.rootKey, "w:vertAlign");
});
});
});

View File

@ -0,0 +1,37 @@
import {Strike, DoubleStrike} from "../../../docx/run/strike";
import {assert} from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Strike", () => {
let strike: Strike;
beforeEach(() => {
strike = new Strike();
});
describe("#constructor()", () => {
it("should create a Strike with correct root key", () => {
let newJson = jsonify(strike);
assert.equal(newJson.rootKey, "w:strike");
});
});
});
describe("DoubleStrike", () => {
let strike: DoubleStrike;
beforeEach(() => {
strike = new DoubleStrike();
});
describe("#constructor()", () => {
it("should create a Double Strike with correct root key", () => {
let newJson = jsonify(strike);
assert.equal(newJson.rootKey, "w:dstrike");
});
});
});

View File

@ -0,0 +1,22 @@
import {Tab} from "../../../docx/run/tab";
import {assert} from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Tab", () => {
let tab: Tab;
beforeEach(() => {
tab = new Tab();
});
describe("#constructor()", () => {
it("should create a Tab with correct root key", () => {
let newJson = jsonify(tab);
assert.equal(newJson.rootKey, "w:tab");
});
});
});

View File

@ -0,0 +1,36 @@
import {XmlUnitComponent} from "../../../docx/xml-components";
import {assert} from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
class TestComponent extends XmlUnitComponent {
}
describe("XmlUnitComponent", () => {
let xmlComponent: TestComponent;
beforeEach(() => {
xmlComponent = new TestComponent("w:test");
});
describe("#constructor()", () => {
it("should create an Xml Component which has the correct rootKey", () => {
let newJson = jsonify(xmlComponent);
assert.equal(newJson.rootKey, "w:test");
});
});
describe("#replaceKey", () => {
it("should not replace the key to the specified root key as root is null", () => {
xmlComponent.replaceKey();
let newJson = jsonify(xmlComponent);
assert.isUndefined(newJson["w:test"]);
});
});
});