From bd1f5898a8f3b389f02afd1a182096a7eaa70c35 Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 19 Nov 2019 22:06:10 +0000 Subject: [PATCH] Add tests --- .../table-properties/table-borders.spec.ts | 550 ++++++++++++++++++ .../table/table-properties/table-borders.ts | 2 +- 2 files changed, 551 insertions(+), 1 deletion(-) create mode 100644 src/file/table/table-properties/table-borders.spec.ts diff --git a/src/file/table/table-properties/table-borders.spec.ts b/src/file/table/table-properties/table-borders.spec.ts new file mode 100644 index 0000000000..679192f120 --- /dev/null +++ b/src/file/table/table-properties/table-borders.spec.ts @@ -0,0 +1,550 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { BorderStyle } from "file/styles"; + +import { TableBorders } from "./table-borders"; + +describe("TableBorders", () => { + describe("#constructor", () => { + describe("default borders", () => { + it("should add a table cell top border using default width type", () => { + const tableBorders = new TableBorders({}); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("top border", () => { + it("should add a table cell top border", () => { + const tableBorders = new TableBorders({ + top: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + + const tree = new Formatter().format(tableBorders); + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("left border", () => { + it("should add a table cell left border", () => { + const tableBorders = new TableBorders({ + left: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("bottom border", () => { + it("should add a table cell bottom border", () => { + const tableBorders = new TableBorders({ + bottom: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("right border", () => { + it("should add a table cell right border", () => { + const tableBorders = new TableBorders({ + right: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("inside horizontal border", () => { + it("should add a table cell inside horizontal border", () => { + const tableBorders = new TableBorders({ + insideHorizontal: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + ], + }); + }); + }); + + describe("inside vertical border", () => { + it("should add a table cell inside horizontal border", () => { + const tableBorders = new TableBorders({ + insideVertical: { + style: BorderStyle.DOUBLE, + size: 1, + color: "red", + }, + }); + const tree = new Formatter().format(tableBorders); + + expect(tree).to.deep.equal({ + "w:tblBorders": [ + { + "w:top": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:left": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:bottom": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:right": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideH": { + _attr: { + "w:color": "auto", + "w:space": 0, + "w:sz": 4, + "w:val": "single", + }, + }, + }, + { + "w:insideV": { + _attr: { + "w:color": "red", + "w:space": 0, + "w:sz": 1, + "w:val": "double", + }, + }, + }, + ], + }); + }); + }); + }); +}); diff --git a/src/file/table/table-properties/table-borders.ts b/src/file/table/table-properties/table-borders.ts index fa83621968..7c7ac96ca9 100644 --- a/src/file/table/table-properties/table-borders.ts +++ b/src/file/table/table-properties/table-borders.ts @@ -58,7 +58,7 @@ export class TableBorders extends XmlComponent { } if (options.right) { - this.root.push(new TableBordersElement("w:right", options.right.style, 4, 0, "auto")); + this.root.push(new TableBordersElement("w:right", options.right.style, options.right.size, 0, options.right.color)); } else { this.root.push(new TableBordersElement("w:right", BorderStyle.SINGLE, 4, 0, "auto")); }