update table-row-properties, table-cell-properties, table-cell-borders to declarative style

This commit is contained in:
Tom Hunkapiller
2021-05-22 04:03:40 +03:00
parent acc23be297
commit 2611e0c74f
8 changed files with 259 additions and 328 deletions

View File

@ -9,74 +9,68 @@ import { TableCellProperties } from "./table-cell-properties";
describe("TableCellProperties", () => {
describe("#constructor", () => {
it("creates an initially empty property object", () => {
const properties = new TableCellProperties();
const properties = new TableCellProperties({});
// The TableCellProperties is ignorable if there are no attributes,
// which results in prepForXml returning undefined, which causes
// the formatter to throw an error if that is the only object it
// has been asked to format.
expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly");
});
});
describe("#addGridSpan", () => {
it("adds grid span", () => {
const properties = new TableCellProperties();
properties.addGridSpan(1);
const properties = new TableCellProperties({ columnSpan: 1 });
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": { _attr: { "w:val": 1 } } }] });
});
});
describe("#addVerticalMerge", () => {
it("adds vertical merge", () => {
const properties = new TableCellProperties();
properties.addVerticalMerge(VerticalMergeType.CONTINUE);
const properties = new TableCellProperties({ verticalMerge: VerticalMergeType.CONTINUE });
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] });
});
});
describe("#setVerticalAlign", () => {
it("sets vertical align", () => {
const properties = new TableCellProperties();
properties.setVerticalAlign(VerticalAlign.BOTTOM);
const properties = new TableCellProperties({ verticalAlign: VerticalAlign.BOTTOM });
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": { _attr: { "w:val": "bottom" } } }] });
});
});
describe("#setWidth", () => {
it("should set width", () => {
const properties = new TableCellProperties();
properties.setWidth(1, WidthType.DXA);
const properties = new TableCellProperties({
width: {
size: 1,
type: WidthType.DXA,
},
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "dxa", "w:w": 1 } } }] });
});
it("should set width using default of AUTO", () => {
const properties = new TableCellProperties();
properties.setWidth(1);
const properties = new TableCellProperties({
width: {
size: 1,
},
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "auto", "w:w": 1 } } }] });
});
});
describe("#setShading", () => {
it("sets shading", () => {
const properties = new TableCellProperties();
properties.setShading({
fill: "test",
color: "000",
const properties = new TableCellProperties({
shading: {
fill: "test",
color: "000",
},
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": { _attr: { "w:fill": "test", "w:color": "000" } } }] });
});
});
describe("#addMargins", () => {
it("sets shading", () => {
const properties = new TableCellProperties();
properties.addMargins({});
const properties = new TableCellProperties({
margins: {},
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:tcPr": [
@ -119,17 +113,21 @@ describe("TableCellProperties", () => {
],
});
});
});
describe("#Borders", () => {
it("should return the TableCellBorders if Border has borders", () => {
const properties = new TableCellProperties();
properties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
const borders = properties.Borders;
it("should set the TableCellBorders", () => {
const properties = new TableCellProperties({
borders: {
top: {
style: BorderStyle.DASH_DOT_STROKED,
color: "red",
size: 3,
},
},
});
const tree = new Formatter().format(borders);
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
expect(tree["w:tcPr"][0]).to.deep.equal({
"w:tcBorders": [{ "w:top": { _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } } }],
});
});