From 47533cf4e29f881c9327232d1b40bcf9ea0ac39c Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 24 Dec 2019 03:39:55 +0000 Subject: [PATCH] Bookmark tests --- src/file/paragraph/paragraph.spec.ts | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index b4a797a8c2..cdbe99c7d8 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -1,9 +1,12 @@ import { assert, expect } from "chai"; +import * as shortid from "shortid"; +import { stub } from "sinon"; import { Formatter } from "export/formatter"; import { EMPTY_OBJECT } from "file/xml-components"; import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting"; +import { Bookmark } from "./links"; import { Paragraph } from "./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", () => { it("should set the paragraph style to the given styleId", () => { const paragraph = new Paragraph({