From a0d8911e1897fdf87bca924e244489f197afe485 Mon Sep 17 00:00:00 2001 From: Dolan Date: Mon, 8 Mar 2021 04:18:26 +0000 Subject: [PATCH] Add tests --- src/file/footnotes/footnote/footnote.spec.ts | 130 +++++++++++++++++++ src/file/paragraph/paragraph.spec.ts | 22 ++++ 2 files changed, 152 insertions(+) diff --git a/src/file/footnotes/footnote/footnote.spec.ts b/src/file/footnotes/footnote/footnote.spec.ts index ab1778f687..e2ce67d7b3 100644 --- a/src/file/footnotes/footnote/footnote.spec.ts +++ b/src/file/footnotes/footnote/footnote.spec.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; +import { Paragraph, TextRun } from "file/paragraph"; import { Footnote, FootnoteType } from "./footnote"; @@ -28,5 +29,134 @@ describe("Footnote", () => { expect(Object.keys(tree)).to.deep.equal(["w:footnote"]); expect(tree["w:footnote"]).to.deep.equal({ _attr: { "w:id": 1 } }); }); + + it("should append footnote ref run on the first footnote paragraph", () => { + const footnote = new Footnote({ + id: 1, + children: [new Paragraph({ children: [new TextRun("test-footnote")] })], + }); + const tree = new Formatter().format(footnote); + + expect(tree).to.deep.equal({ + "w:footnote": [ + { + _attr: { + "w:id": 1, + }, + }, + { + "w:p": [ + { + "w:r": [ + { + "w:rPr": [ + { + "w:rStyle": { + _attr: { + "w:val": "FootnoteReference", + }, + }, + }, + ], + }, + { + "w:footnoteRef": {}, + }, + ], + }, + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test-footnote", + ], + }, + ], + }, + ], + }, + ], + }); + }); + + it("should add multiple paragraphs", () => { + const footnote = new Footnote({ + id: 1, + children: [ + new Paragraph({ children: [new TextRun("test-footnote")] }), + new Paragraph({ children: [new TextRun("test-footnote-2")] }), + ], + }); + const tree = new Formatter().format(footnote); + + expect(tree).to.deep.equal({ + "w:footnote": [ + { + _attr: { + "w:id": 1, + }, + }, + { + "w:p": [ + { + "w:r": [ + { + "w:rPr": [ + { + "w:rStyle": { + _attr: { + "w:val": "FootnoteReference", + }, + }, + }, + ], + }, + { + "w:footnoteRef": {}, + }, + ], + }, + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test-footnote", + ], + }, + ], + }, + ], + }, + { + "w:p": [ + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test-footnote-2", + ], + }, + ], + }, + ], + }, + ], + }); + }); }); }); diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index fe9ab8360e..0aa4d98b2d 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -618,6 +618,28 @@ describe("Paragraph", () => { ], }); }); + + it("should not add ListParagraph style when custom is true", () => { + const paragraph = new Paragraph({ + numbering: { + reference: "test id", + level: 0, + custom: true, + }, + }); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:pPr": [ + { + "w:numPr": [{ "w:ilvl": { _attr: { "w:val": 0 } } }, { "w:numId": { _attr: { "w:val": "{test id}" } } }], + }, + ], + }, + ], + }); + }); }); it("it should add bookmark", () => {