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";
|
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
import { TextRun } from "../run";
|
|
|
|
import { ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./hyperlink";
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
describe("ConcreteHyperlink", () => {
|
|
|
|
let hyperlink: ConcreteHyperlink;
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2018-05-06 23:18:00 -05:00
|
|
|
beforeEach(() => {
|
2021-02-27 19:23:29 +00:00
|
|
|
hyperlink = new ConcreteHyperlink(
|
2021-08-27 16:53:11 -06:00
|
|
|
[
|
|
|
|
new TextRun({
|
|
|
|
text: "https://example.com",
|
|
|
|
style: "Hyperlink",
|
|
|
|
}),
|
|
|
|
],
|
2021-02-27 19:23:29 +00:00
|
|
|
"superid",
|
|
|
|
);
|
2018-05-06 23:18:00 -05:00
|
|
|
});
|
|
|
|
|
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,
|
2019-11-08 10:50:18 +01:00
|
|
|
"r:id": "rIdsuperid",
|
2019-06-27 01:35:58 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"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(() => {
|
2021-02-27 19:23:29 +00:00
|
|
|
hyperlink = new ConcreteHyperlink(
|
2021-08-27 16:53:11 -06:00
|
|
|
[
|
|
|
|
new TextRun({
|
|
|
|
text: "Anchor Text",
|
|
|
|
style: "Hyperlink",
|
|
|
|
}),
|
|
|
|
],
|
2021-02-27 19:23:29 +00:00
|
|
|
"superid2",
|
|
|
|
"anchor",
|
|
|
|
);
|
2018-07-24 16:56:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
2019-12-24 00:44:15 +00:00
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
describe("ExternalHyperlink", () => {
|
2019-12-24 00:44:15 +00:00
|
|
|
describe("#constructor()", () => {
|
2021-02-27 19:23:29 +00:00
|
|
|
it("should create", () => {
|
|
|
|
const externalHyperlink = new ExternalHyperlink({
|
2021-08-27 16:53:11 -06:00
|
|
|
children: [new TextRun("test")],
|
2021-02-27 19:23:29 +00:00
|
|
|
link: "http://www.google.com",
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(externalHyperlink.options.link).to.equal("http://www.google.com");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("InternalHyperlink", () => {
|
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("should create", () => {
|
|
|
|
const internalHyperlink = new InternalHyperlink({
|
|
|
|
child: new TextRun("test"),
|
|
|
|
anchor: "test-id",
|
|
|
|
});
|
|
|
|
|
|
|
|
const tree = new Formatter().format(internalHyperlink);
|
2019-12-24 00:44:15 +00:00
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:hyperlink": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:anchor": "test-id",
|
|
|
|
"w:history": 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"w:r": [
|
|
|
|
{
|
|
|
|
"w:t": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"xml:space": "preserve",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"test",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2019-12-24 00:44:15 +00:00
|
|
|
});
|
|
|
|
});
|