From a954c69458eb80e05bb4bd689e6ed3dfe4b1ac7a Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 22 Mar 2018 23:04:46 +0000 Subject: [PATCH] Fix tests --- src/file/table/properties.ts | 6 ++- src/file/table/table.spec.ts | 87 +++++++++++++++++++++++++++++++++--- src/file/table/table.ts | 1 + 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/file/table/properties.ts b/src/file/table/properties.ts index 3e9bb43e24..1478399dae 100644 --- a/src/file/table/properties.ts +++ b/src/file/table/properties.ts @@ -5,7 +5,6 @@ export type WidthTypes = "dxa" | "pct" | "nil" | "auto"; export class TableProperties extends XmlComponent { constructor() { super("w:tblPr"); - this.root.push(new TableBorders()); } public setWidth(type: WidthTypes, w: number | string): TableProperties { @@ -17,6 +16,11 @@ export class TableProperties extends XmlComponent { this.root.push(new TableLayout("fixed")); return this; } + + public setBorder(): TableProperties { + this.root.push(new TableBorders()); + return this; + } } interface ITableWidth { diff --git a/src/file/table/table.spec.ts b/src/file/table/table.spec.ts index fc42be5164..84cbe99590 100644 --- a/src/file/table/table.spec.ts +++ b/src/file/table/table.spec.ts @@ -5,6 +5,83 @@ import { Formatter } from "../../export/formatter"; import { Paragraph } from "../paragraph"; import { Table } from "./"; +const DEFAULT_TABLE_PROPERTIES = { + "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("Table", () => { describe("#constructor", () => { it("creates a table with the correct number of rows and columns", () => { @@ -13,7 +90,7 @@ describe("Table", () => { const cell = { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] }; expect(tree).to.deep.equal({ "w:tbl": [ - { "w:tblPr": [] }, + { "w:tblPr": [DEFAULT_TABLE_PROPERTIES] }, { "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], }, @@ -55,7 +132,7 @@ describe("Table", () => { }); expect(tree).to.deep.equal({ "w:tbl": [ - { "w:tblPr": [] }, + { "w:tblPr": [DEFAULT_TABLE_PROPERTIES] }, { "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], }, @@ -84,7 +161,7 @@ describe("Table", () => { }); expect(tree).to.deep.equal({ "w:tbl": [ - { "w:tblPr": [] }, + { "w:tblPr": [DEFAULT_TABLE_PROPERTIES] }, { "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], }, @@ -104,7 +181,7 @@ describe("Table", () => { .which.is.an("array") .with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }], + "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }], }); }); }); @@ -118,7 +195,7 @@ describe("Table", () => { .which.is.an("array") .with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }], + "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }], }); }); }); diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 6a7bb1a928..8fdec3d37c 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -12,6 +12,7 @@ export class Table extends XmlComponent { super("w:tbl"); this.properties = new TableProperties(); this.root.push(this.properties); + this.properties.setBorder(); const gridCols: number[] = []; for (let i = 0; i < cols; i++) {