From 68cb57aea632b168d652767a4a7e0c4f2adaa016 Mon Sep 17 00:00:00 2001 From: Ivan Lopez Date: Sun, 6 May 2018 23:18:00 -0500 Subject: [PATCH] fix style issues --- src/file/paragraph/links/hyperlink.spec.ts | 17 ++++++++++------- src/file/paragraph/links/hyperlink.ts | 7 ++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/file/paragraph/links/hyperlink.spec.ts b/src/file/paragraph/links/hyperlink.spec.ts index 9e3aebc29f..e3f0b58c49 100644 --- a/src/file/paragraph/links/hyperlink.spec.ts +++ b/src/file/paragraph/links/hyperlink.spec.ts @@ -7,15 +7,17 @@ import { Hyperlink } from "./"; describe("Hyperlink", () => { let hyperlink: Hyperlink; + beforeEach(() => { + hyperlink = new Hyperlink("https://example.com", 0); + }); + describe("#constructor()", () => { it("should create a hyperlink with correct root key", () => { - hyperlink = new Hyperlink("https://example.com", 0); const newJson = Utility.jsonify(hyperlink); assert.equal(newJson.rootKey, "w:hyperlink"); }); it("should create a hyperlink with right attributes", () => { - hyperlink = new Hyperlink("https://example.com", 0); const newJson = Utility.jsonify(hyperlink); const attributes = { id: "rId1", @@ -25,13 +27,14 @@ describe("Hyperlink", () => { }); it("should create a hyperlink with a run component", () => { - hyperlink = new Hyperlink("https://example.com", 0); const tree = new Formatter().format(hyperlink); - expect(tree["w:hyperlink"][1]).to.deep.equal({ + const runJson = { "w:r": [ - { "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink"} }] }] }, - { "w:t": [{_attr: {"xml:space": "preserve"}}, "https://example.com"]}, - ]}); + { "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink" } }] }] }, + { "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] }, + ], + }; + expect(tree["w:hyperlink"][1]).to.deep.equal(runJson); }); }); }); diff --git a/src/file/paragraph/links/hyperlink.ts b/src/file/paragraph/links/hyperlink.ts index f700ae0a4d..53f72e72bd 100644 --- a/src/file/paragraph/links/hyperlink.ts +++ b/src/file/paragraph/links/hyperlink.ts @@ -1,4 +1,5 @@ // http://officeopenxml.com/WPhyperlink.php + import { XmlComponent } from "file/xml-components"; import { TextRun } from "../run"; import { HyperlinkAttributes } from "./hyperlink-attributes"; @@ -10,11 +11,11 @@ export class Hyperlink extends XmlComponent { super("w:hyperlink"); this.linkId = relationshipsCount + 1; - this.root.push(new HyperlinkAttributes({ + const attributes = new HyperlinkAttributes({ id: `rId${this.linkId}`, history: 1, - })); + }); + this.root.push(attributes); this.root.push(new TextRun(text).style("Hyperlink")); - return this; } }