fix style issues

This commit is contained in:
Ivan Lopez
2018-05-06 23:18:00 -05:00
parent 9d7fd55e4c
commit 68cb57aea6
2 changed files with 14 additions and 10 deletions

View File

@ -7,15 +7,17 @@ import { Hyperlink } from "./";
describe("Hyperlink", () => { describe("Hyperlink", () => {
let hyperlink: Hyperlink; let hyperlink: Hyperlink;
beforeEach(() => {
hyperlink = new Hyperlink("https://example.com", 0);
});
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a hyperlink with correct root key", () => { it("should create a hyperlink with correct root key", () => {
hyperlink = new Hyperlink("https://example.com", 0);
const newJson = Utility.jsonify(hyperlink); const newJson = Utility.jsonify(hyperlink);
assert.equal(newJson.rootKey, "w:hyperlink"); assert.equal(newJson.rootKey, "w:hyperlink");
}); });
it("should create a hyperlink with right attributes", () => { it("should create a hyperlink with right attributes", () => {
hyperlink = new Hyperlink("https://example.com", 0);
const newJson = Utility.jsonify(hyperlink); const newJson = Utility.jsonify(hyperlink);
const attributes = { const attributes = {
id: "rId1", id: "rId1",
@ -25,13 +27,14 @@ describe("Hyperlink", () => {
}); });
it("should create a hyperlink with a run component", () => { it("should create a hyperlink with a run component", () => {
hyperlink = new Hyperlink("https://example.com", 0);
const tree = new Formatter().format(hyperlink); const tree = new Formatter().format(hyperlink);
expect(tree["w:hyperlink"][1]).to.deep.equal({ const runJson = {
"w:r": [ "w:r": [
{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink"} }] }] }, { "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink" } }] }] },
{ "w:t": [{_attr: {"xml:space": "preserve"}}, "https://example.com"]}, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
]}); ],
};
expect(tree["w:hyperlink"][1]).to.deep.equal(runJson);
}); });
}); });
}); });

View File

@ -1,4 +1,5 @@
// http://officeopenxml.com/WPhyperlink.php // http://officeopenxml.com/WPhyperlink.php
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { TextRun } from "../run"; import { TextRun } from "../run";
import { HyperlinkAttributes } from "./hyperlink-attributes"; import { HyperlinkAttributes } from "./hyperlink-attributes";
@ -10,11 +11,11 @@ export class Hyperlink extends XmlComponent {
super("w:hyperlink"); super("w:hyperlink");
this.linkId = relationshipsCount + 1; this.linkId = relationshipsCount + 1;
this.root.push(new HyperlinkAttributes({ const attributes = new HyperlinkAttributes({
id: `rId${this.linkId}`, id: `rId${this.linkId}`,
history: 1, history: 1,
})); });
this.root.push(attributes);
this.root.push(new TextRun(text).style("Hyperlink")); this.root.push(new TextRun(text).style("Hyperlink"));
return this;
} }
} }