From 5ec18d6e01523eb78ecfe7f198a00eef0acc33c2 Mon Sep 17 00:00:00 2001 From: Dolan Date: Fri, 25 Dec 2020 02:15:40 +0000 Subject: [PATCH] Add tests and simplify --- src/file/drawing/anchor/anchor.spec.ts | 125 +++++++++++++++++++++++++ src/file/drawing/anchor/anchor.ts | 6 -- 2 files changed, 125 insertions(+), 6 deletions(-) diff --git a/src/file/drawing/anchor/anchor.spec.ts b/src/file/drawing/anchor/anchor.spec.ts index 99fe0fb7b9..10d4b08d13 100644 --- a/src/file/drawing/anchor/anchor.spec.ts +++ b/src/file/drawing/anchor/anchor.spec.ts @@ -219,6 +219,131 @@ describe("Anchor", () => { assert.equal(textWrap.rootKey, "wp:wrapTopAndBottom"); }); + it("should create a Drawing with a margin", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + margins: { + top: 10, + left: 10, + bottom: 10, + right: 10, + }, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + distT: 10, + distB: 10, + distL: 10, + distR: 10, + }); + }); + + it("should create a Drawing with a default margin", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + margins: {}, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + distT: 0, + distB: 0, + distL: 0, + distR: 0, + }); + }); + + it("should create a Drawing with allowOverlap being false", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + allowOverlap: false, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + allowOverlap: "0", + }); + }); + + it("should create a Drawing with behindDocument being true", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + behindDocument: true, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + behindDoc: "1", + }); + }); + + it("should create a Drawing with locked being true", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + lockAnchor: true, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + locked: "1", + }); + }); + + it("should create a Drawing with locked being false", () => { + anchor = createAnchor({ + floating: { + verticalPosition: { + offset: 0, + }, + horizontalPosition: { + offset: 0, + }, + layoutInCell: false, + }, + }); + const newJson = Utility.jsonify(anchor); + const anchorAttributes = newJson.root[0].root; + assert.include(anchorAttributes, { + layoutInCell: "0", + }); + }); + it("should create a Drawing with a certain z-index", () => { anchor = createAnchor({ floating: { diff --git a/src/file/drawing/anchor/anchor.ts b/src/file/drawing/anchor/anchor.ts index 25890aae9c..7eb4487a89 100644 --- a/src/file/drawing/anchor/anchor.ts +++ b/src/file/drawing/anchor/anchor.ts @@ -16,12 +16,6 @@ export class Anchor extends XmlComponent { super("wp:anchor"); const floating: IFloating = { - margins: { - top: 0, - bottom: 0, - left: 0, - right: 0, - }, allowOverlap: true, behindDocument: false, lockAnchor: false,