From 766bcabcb8e6ad5ed58f04f24f4bca33ee94819d Mon Sep 17 00:00:00 2001 From: felipe Date: Thu, 9 Mar 2017 12:42:19 +0100 Subject: [PATCH] allow Underline to be called with type and color; fix default --- ts/docx/run/formatting.ts | 1 + ts/docx/run/underline.ts | 4 ++-- ts/tests/docx/run/underlineTests.ts | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ts/docx/run/formatting.ts b/ts/docx/run/formatting.ts index 2471b359cd..ccad4cc349 100644 --- a/ts/docx/run/formatting.ts +++ b/ts/docx/run/formatting.ts @@ -1,4 +1,5 @@ import { Attributes, XmlComponent } from "../xml-components"; +export { Underline } from './underline'; export class Bold extends XmlComponent { diff --git a/ts/docx/run/underline.ts b/ts/docx/run/underline.ts index cac9538a6b..1a6fda2334 100644 --- a/ts/docx/run/underline.ts +++ b/ts/docx/run/underline.ts @@ -13,8 +13,8 @@ abstract class BaseUnderline extends XmlComponent { export class Underline extends BaseUnderline { - constructor() { - super(""); + constructor(underlineType: string = "single", color?: string) { + super(underlineType, color); } } diff --git a/ts/tests/docx/run/underlineTests.ts b/ts/tests/docx/run/underlineTests.ts index fa40923306..2fb34172f5 100644 --- a/ts/tests/docx/run/underlineTests.ts +++ b/ts/tests/docx/run/underlineTests.ts @@ -1,7 +1,8 @@ -import { assert } from "chai"; +import { assert, expect } from "chai"; import { TextRun } from "../../../docx/run/text-run"; import * as u from "../../../docx/run/underline"; +import { Formatter } from "../../../export/formatter"; function jsonify(obj: object) { const stringifiedJson = JSON.stringify(obj); @@ -17,6 +18,22 @@ describe("Underline", () => { const newJson = jsonify(underline); 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"}}], + }); + }); }); });