allow Underline to be called with type and color; fix default

This commit is contained in:
felipe
2017-03-09 12:42:19 +01:00
parent f06094c91d
commit 766bcabcb8
3 changed files with 21 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { Attributes, XmlComponent } from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
export { Underline } from './underline';
export class Bold extends XmlComponent { export class Bold extends XmlComponent {

View File

@ -13,8 +13,8 @@ abstract class BaseUnderline extends XmlComponent {
export class Underline extends BaseUnderline { export class Underline extends BaseUnderline {
constructor() { constructor(underlineType: string = "single", color?: string) {
super(""); super(underlineType, color);
} }
} }

View File

@ -1,7 +1,8 @@
import { assert } from "chai"; import { assert, expect } from "chai";
import { TextRun } from "../../../docx/run/text-run"; import { TextRun } from "../../../docx/run/text-run";
import * as u from "../../../docx/run/underline"; import * as u from "../../../docx/run/underline";
import { Formatter } from "../../../export/formatter";
function jsonify(obj: object) { function jsonify(obj: object) {
const stringifiedJson = JSON.stringify(obj); const stringifiedJson = JSON.stringify(obj);
@ -17,6 +18,22 @@ describe("Underline", () => {
const newJson = jsonify(underline); const newJson = jsonify(underline);
assert.equal(newJson.rootKey, "w:u"); assert.equal(newJson.rootKey, "w:u");
}); });
it("should default to 'single' and no color", () => {
const underline = new u.Underline();
const tree = new Formatter().format(underline);
expect(tree).to.deep.equal({
"w:u": [{_attr: {"w:val": "single"}}],
});
});
it("should use the given style type and color", () => {
const underline = new u.Underline("double", "FF00CC");
const tree = new Formatter().format(underline);
expect(tree).to.deep.equal({
"w:u": [{_attr: {"w:val": "double", "w:color": "FF00CC"}}],
});
});
}); });
}); });