Files
docx-js/src/file/paragraph/links/hyperlink.spec.ts

57 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-05-06 22:20:56 -05:00
import { assert, expect } from "chai";
2018-10-26 01:04:07 +01:00
import { Formatter } from "export/formatter";
import { Utility } from "tests/utility";
2018-05-06 22:20:56 -05:00
import { Hyperlink } from "./";
describe("Hyperlink", () => {
let hyperlink: Hyperlink;
2018-05-06 23:18:00 -05:00
beforeEach(() => {
hyperlink = new Hyperlink("https://example.com", 0);
});
2018-05-06 22:20:56 -05:00
describe("#constructor()", () => {
it("should create a hyperlink with correct root key", () => {
const newJson = Utility.jsonify(hyperlink);
assert.equal(newJson.rootKey, "w:hyperlink");
});
it("should create a hyperlink with right attributes", () => {
const newJson = Utility.jsonify(hyperlink);
const attributes = {
history: 1,
2018-07-24 16:56:27 -04:00
id: "rId1",
2018-05-06 22:20:56 -05:00
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
it("should create a hyperlink with a run component", () => {
const tree = new Formatter().format(hyperlink);
2018-05-06 23:18:00 -05:00
const runJson = {
2018-05-06 22:20:56 -05:00
"w:r": [
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
2018-05-06 23:18:00 -05:00
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
],
};
expect(tree["w:hyperlink"][1]).to.deep.equal(runJson);
2018-05-06 22:20:56 -05:00
});
2018-07-24 16:56:27 -04:00
describe("with optional anchor parameter", () => {
beforeEach(() => {
hyperlink = new Hyperlink("Anchor Text", 0, "anchor");
});
it("should create an internal link with anchor tag", () => {
const newJson = Utility.jsonify(hyperlink);
const attributes = {
history: 1,
anchor: "anchor",
};
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
});
});
2018-05-06 22:20:56 -05:00
});
});