diff --git a/src/file/file.spec.ts b/src/file/file.spec.ts index c9ec7b3a3e..0ad7474644 100644 --- a/src/file/file.spec.ts +++ b/src/file/file.spec.ts @@ -5,7 +5,7 @@ import { Formatter } from "export/formatter"; import { File } from "./file"; import { Footer, Header } from "./header"; -import { Paragraph } from "./paragraph"; +import { HyperlinkRef, Paragraph } from "./paragraph"; import { Table, TableCell, TableRow } from "./table"; import { TableOfContents } from "./table-of-contents"; @@ -89,6 +89,94 @@ describe("File", () => { expect(tree["w:body"][1]["w:sectPr"][8]["w:footerReference"]._attr["w:type"]).to.equal("first"); expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"]._attr["w:type"]).to.equal("even"); }); + + it("should add child", () => { + const doc = new File(undefined, undefined, [ + { + children: [new Paragraph("test")], + }, + ]); + + const tree = new Formatter().format(doc.Document.Body); + + expect(tree).to.deep.equal({ + "w:body": [ + { + "w:p": {}, + }, + { + "w:p": [ + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test", + ], + }, + ], + }, + ], + }, + { + "w:sectPr": [ + { + "w:pgSz": { + _attr: { + "w:h": 16838, + "w:orient": "portrait", + "w:w": 11906, + }, + }, + }, + { + "w:pgMar": { + _attr: { + "w:bottom": 1440, + "w:footer": 708, + "w:gutter": 0, + "w:header": 708, + "w:left": 1440, + "w:mirrorMargins": false, + "w:right": 1440, + "w:top": 1440, + }, + }, + }, + { + "w:cols": { + _attr: { + "w:num": 1, + "w:space": 708, + }, + }, + }, + { + "w:docGrid": { + _attr: { + "w:linePitch": 360, + }, + }, + }, + ], + }, + ], + }); + }); + + it("should add hyperlink child", () => { + const doc = new File(undefined, undefined, [ + { + children: [new HyperlinkRef("test")], + }, + ]); + + expect(doc.HyperlinkCache).to.deep.equal({}); + }); }); describe("#addSection", () => { @@ -102,6 +190,16 @@ describe("File", () => { expect(spy.called).to.equal(true); }); + it("should add hyperlink child", () => { + const doc = new File(); + + doc.addSection({ + children: [new HyperlinkRef("test")], + }); + + expect(doc.HyperlinkCache).to.deep.equal({}); + }); + it("should call the underlying document's add when adding a Table", () => { const file = new File(); const spy = sinon.spy(file.Document, "add"); diff --git a/src/file/file.ts b/src/file/file.ts index 583d4ace3a..59af9fa7f7 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -41,7 +41,7 @@ export interface ISectionOptions { readonly size?: IPageSizeAttributes; readonly margins?: IPageMarginAttributes; readonly properties?: SectionPropertiesOptions; - readonly children: Array; + readonly children: Array; } export class File {