From f07ce0bbf4488c7db1579df9257785cf992155fb Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 21 Apr 2022 21:35:56 +0100 Subject: [PATCH] #1487 Fix tests --- .../paragraph/frame/frame-properties.spec.ts | 70 +++++++++++++++++++ src/file/paragraph/frame/frame-properties.ts | 4 +- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/file/paragraph/frame/frame-properties.spec.ts b/src/file/paragraph/frame/frame-properties.spec.ts index d0cccc8c7a..33a5bb4d4a 100644 --- a/src/file/paragraph/frame/frame-properties.spec.ts +++ b/src/file/paragraph/frame/frame-properties.spec.ts @@ -82,5 +82,75 @@ describe("FrameProperties", () => { }, }); }); + + it("should create without x and y", () => { + const currentFrameProperties = new FrameProperties({ + width: 4000, + height: 1000, + anchor: { + horizontal: FrameAnchorType.MARGIN, + vertical: FrameAnchorType.MARGIN, + }, + alignment: { + x: HorizontalPositionAlign.CENTER, + y: VerticalPositionAlign.TOP, + }, + space: { + horizontal: 100, + vertical: 200, + }, + }); + + const tree = new Formatter().format(currentFrameProperties); + expect(tree).to.deep.equal({ + "w:framePr": { + _attr: { + "w:h": 1000, + "w:hAnchor": "margin", + "w:vAnchor": "margin", + "w:w": 4000, + "w:xAlign": "center", + "w:yAlign": "top", + "w:hSpace": 100, + "w:vSpace": 200, + }, + }, + }); + }); + + it("should create without alignments", () => { + const currentFrameProperties = new FrameProperties({ + position: { + x: 1000, + y: 3000, + }, + width: 4000, + height: 1000, + anchor: { + horizontal: FrameAnchorType.MARGIN, + vertical: FrameAnchorType.MARGIN, + }, + space: { + horizontal: 100, + vertical: 200, + }, + }); + + const tree = new Formatter().format(currentFrameProperties); + expect(tree).to.deep.equal({ + "w:framePr": { + _attr: { + "w:h": 1000, + "w:hAnchor": "margin", + "w:vAnchor": "margin", + "w:w": 4000, + "w:x": 1000, + "w:y": 3000, + "w:hSpace": 100, + "w:vSpace": 200, + }, + }, + }); + }); }); }); diff --git a/src/file/paragraph/frame/frame-properties.ts b/src/file/paragraph/frame/frame-properties.ts index 01a70a9579..baac4e79f4 100644 --- a/src/file/paragraph/frame/frame-properties.ts +++ b/src/file/paragraph/frame/frame-properties.ts @@ -112,8 +112,8 @@ export class FrameProperties extends XmlComponent { spaceHorizontal: options.space?.horizontal, spaceVertical: options.space?.vertical, rule: options.rule, - alignmentX: (options as IAlignmentFrameOptions).alignment.x ? (options as IAlignmentFrameOptions).alignment.x : undefined, - alignmentY: (options as IAlignmentFrameOptions).alignment.x ? (options as IAlignmentFrameOptions).alignment.y : undefined, + alignmentX: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.x : undefined, + alignmentY: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.y : undefined, lines: options.lines, wrap: options.wrap, }),