Add tests
This commit is contained in:
@ -179,7 +179,7 @@ export class TableCellWidth extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
interface ITableCellShadingAttributesProperties {
|
||||
export interface ITableCellShadingAttributesProperties {
|
||||
fill?: string;
|
||||
color?: string;
|
||||
val?: string;
|
||||
@ -197,7 +197,7 @@ class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShading
|
||||
* Table cell shading element.
|
||||
*/
|
||||
export class TableCellShading extends XmlComponent {
|
||||
constructor(attrs: object) {
|
||||
constructor(attrs: ITableCellShadingAttributesProperties) {
|
||||
super("w:shd");
|
||||
this.root.push(new TableCellShadingAttributes(attrs));
|
||||
}
|
||||
|
64
src/file/table/table-cell/table-cell-properties.spec.ts
Normal file
64
src/file/table/table-cell/table-cell-properties.spec.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { VerticalAlign, VMergeType, WidthType } from "./table-cell-components";
|
||||
import { TableCellProperties } from "./table-cell-properties";
|
||||
|
||||
describe("TableCellProperties", () => {
|
||||
describe("#constructor", () => {
|
||||
it("creates an initially empty property object", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addGridSpan", () => {
|
||||
it("adds grid span", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.addGridSpan(1);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": [{ _attr: { "w:val": 1 } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addVerticalMerge", () => {
|
||||
it("adds vertical merge", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.addVerticalMerge(VMergeType.CONTINUE);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setVerticalAlign", () => {
|
||||
it("sets vertical align", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setVerticalAlign(VerticalAlign.BOTTOM);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": [{ _attr: { "w:val": "bottom" } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setWidth", () => {
|
||||
it("sets width", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setWidth(1, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "dxa", "w:w": 1 } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setShading", () => {
|
||||
it("sets shading", () => {
|
||||
const cellMargain = new TableCellProperties();
|
||||
cellMargain.setShading({
|
||||
fill: "test",
|
||||
color: "000",
|
||||
});
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": [{ _attr: { "w:fill": "test", "w:color": "000" } }] }] });
|
||||
});
|
||||
});
|
||||
});
|
@ -2,6 +2,7 @@ import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import {
|
||||
GridSpan,
|
||||
ITableCellShadingAttributesProperties,
|
||||
TableCellBorders,
|
||||
TableCellShading,
|
||||
TableCellWidth,
|
||||
@ -49,7 +50,7 @@ export class TableCellProperties extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public setShading(attrs: object): TableCellProperties {
|
||||
public setShading(attrs: ITableCellShadingAttributesProperties): TableCellProperties {
|
||||
this.root.push(new TableCellShading(attrs));
|
||||
|
||||
return this;
|
||||
|
51
src/file/table/table-properties/table-cell-margin.spec.ts
Normal file
51
src/file/table/table-properties/table-cell-margin.spec.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { WidthType } from "../table-cell";
|
||||
import { TableCellMargin } from "./table-cell-margin";
|
||||
|
||||
describe("TableCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should throw an error if theres no child elements", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
expect(() => new Formatter().format(cellMargain)).to.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addTopMargin", () => {
|
||||
it("adds a table cell top margin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addTopMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addLeftMargin", () => {
|
||||
it("adds a table cell left margin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addLeftMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addBottomMargin", () => {
|
||||
it("adds a table cell bottom margin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addBottomMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addRightMargin", () => {
|
||||
it("adds a table cell right margin", () => {
|
||||
const cellMargain = new TableCellMargin();
|
||||
cellMargain.addRightMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(cellMargain);
|
||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
||||
});
|
||||
});
|
||||
});
|
@ -43,5 +43,14 @@ describe("TableProperties", () => {
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
|
||||
});
|
||||
});
|
||||
|
||||
it("adds a table cell left margin", () => {
|
||||
const tp = new TableProperties();
|
||||
tp.CellMargin.addLeftMargin(1234, WidthType.DXA);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user