From cd501bba0a1fe9737adbe9fd93fb04af44a0c852 Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 9 Mar 2021 22:59:50 +0000 Subject: [PATCH] Add tests --- demo/42-restart-page-numbers.ts | 3 ++- .../section-properties.spec.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/demo/42-restart-page-numbers.ts b/demo/42-restart-page-numbers.ts index d31947625b..0ecfcee6cc 100644 --- a/demo/42-restart-page-numbers.ts +++ b/demo/42-restart-page-numbers.ts @@ -1,7 +1,7 @@ // Page numbers - Start from 0 on a new section // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build"; +import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "../build"; const doc = new Document(); @@ -45,6 +45,7 @@ doc.addSection({ doc.addSection({ properties: { pageNumberStart: 1, + pageNumberSeparator: PageNumberSeparator.EM_DASH }, headers: { default: new Header({ diff --git a/src/file/document/body/section-properties/section-properties.spec.ts b/src/file/document/body/section-properties/section-properties.spec.ts index 598bf09a48..9bd13aa078 100644 --- a/src/file/document/body/section-properties/section-properties.spec.ts +++ b/src/file/document/body/section-properties/section-properties.spec.ts @@ -5,6 +5,7 @@ import { Formatter } from "export/formatter"; import { FooterWrapper } from "file/footer-wrapper"; import { HeaderWrapper } from "file/header-wrapper"; import { Media } from "file/media"; +import { LineNumberRestartFormat } from "./line-number"; import { PageBorderOffsetFrom } from "./page-border"; import { PageNumberFormat } from "./page-number"; @@ -213,5 +214,20 @@ describe("SectionProperties", () => { "w:type": { _attr: { "w:val": "continuous" } }, }); }); + + it("should create section properties line number type", () => { + const properties = new SectionProperties({ + lineNumberCountBy: 2, + lineNumberStart: 2, + lineNumberRestart: LineNumberRestartFormat.CONTINUOUS, + lineNumberDistance: 4, + }); + const tree = new Formatter().format(properties); + expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); + const type = tree["w:sectPr"].find((item) => item["w:lnNumType"] !== undefined); + expect(type).to.deep.equal({ + "w:lnNumType": { _attr: { "w:countBy": 2, "w:distance": 4, "w:restart": "continuous", "w:start": 2 } }, + }); + }); }); });