Bookmark tests
This commit is contained in:
@ -1,9 +1,12 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
|
import * as shortid from "shortid";
|
||||||
|
import { stub } from "sinon";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting";
|
import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting";
|
||||||
|
import { Bookmark } from "./links";
|
||||||
import { Paragraph } from "./paragraph";
|
import { Paragraph } from "./paragraph";
|
||||||
|
|
||||||
describe("Paragraph", () => {
|
describe("Paragraph", () => {
|
||||||
@ -638,6 +641,49 @@ describe("Paragraph", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("it should add bookmark", () => {
|
||||||
|
stub(shortid, "generate").callsFake(() => {
|
||||||
|
return "test-unique-id";
|
||||||
|
});
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [new Bookmark("test-id", "test")],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(paragraph);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:p": [
|
||||||
|
{
|
||||||
|
"w:bookmarkStart": {
|
||||||
|
_attr: {
|
||||||
|
"w:id": "test-unique-id",
|
||||||
|
"w:name": "test-id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:t": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xml:space": "preserve",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:bookmarkEnd": {
|
||||||
|
_attr: {
|
||||||
|
"w:id": "test-unique-id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#style", () => {
|
describe("#style", () => {
|
||||||
it("should set the paragraph style to the given styleId", () => {
|
it("should set the paragraph style to the given styleId", () => {
|
||||||
const paragraph = new Paragraph({
|
const paragraph = new Paragraph({
|
||||||
|
Reference in New Issue
Block a user