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

62 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-06-27 01:35:58 +01:00
import { expect } from "chai";
2018-05-06 22:20:56 -05:00
2018-10-26 01:04:07 +01:00
import { Formatter } from "export/formatter";
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 tree = new Formatter().format(hyperlink);
2019-06-27 01:35:58 +01:00
expect(tree).to.deep.equal({
"w:hyperlink": [
{
_attr: {
"w:history": 1,
"r:id": "rId1",
},
},
{
"w:r": [
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
],
},
2018-05-06 23:18:00 -05:00
],
2019-06-27 01:35:58 +01:00
});
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", () => {
2019-06-27 01:35:58 +01:00
const tree = new Formatter().format(hyperlink);
expect(tree).to.deep.equal({
"w:hyperlink": [
{
_attr: {
"w:history": 1,
"w:anchor": "anchor",
},
},
{
"w:r": [
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "Anchor Text"] },
],
},
],
});
2018-07-24 16:56:27 -04:00
});
});
2018-05-06 22:20:56 -05:00
});
});