2018-11-01 02:22:32 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
import { Formatter } from "export/formatter";
|
2018-11-15 03:00:26 +00:00
|
|
|
import { BorderStyle } from "file/styles";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2019-09-26 02:03:17 +01:00
|
|
|
import { VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components";
|
2018-11-01 02:22:32 +00:00
|
|
|
import { TableCellProperties } from "./table-cell-properties";
|
|
|
|
|
|
|
|
describe("TableCellProperties", () => {
|
|
|
|
describe("#constructor", () => {
|
|
|
|
it("creates an initially empty property object", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
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");
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addGridSpan", () => {
|
|
|
|
it("adds grid span", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.addGridSpan(1);
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": { _attr: { "w:val": 1 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addVerticalMerge", () => {
|
|
|
|
it("adds vertical merge", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
2019-09-26 02:03:17 +01:00
|
|
|
properties.addVerticalMerge(VerticalMergeType.CONTINUE);
|
2019-04-09 05:27:18 -04:00
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#setVerticalAlign", () => {
|
|
|
|
it("sets vertical align", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.setVerticalAlign(VerticalAlign.BOTTOM);
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": { _attr: { "w:val": "bottom" } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#setWidth", () => {
|
2018-11-15 03:00:26 +00:00
|
|
|
it("should set width", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.setWidth(1, WidthType.DXA);
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "dxa", "w:w": 1 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2018-11-15 03:00:26 +00:00
|
|
|
|
|
|
|
it("should set width using default of AUTO", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.setWidth(1);
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "auto", "w:w": 1 } } }] });
|
2018-11-15 03:00:26 +00:00
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#setShading", () => {
|
|
|
|
it("sets shading", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.setShading({
|
2018-11-01 02:22:32 +00:00
|
|
|
fill: "test",
|
|
|
|
color: "000",
|
|
|
|
});
|
2019-04-09 05:27:18 -04:00
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": { _attr: { "w:fill": "test", "w:color": "000" } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
2018-11-15 03:00:26 +00:00
|
|
|
|
|
|
|
describe("#Borders", () => {
|
|
|
|
it("should return the TableCellBorders if Border has borders", () => {
|
2019-04-09 05:27:18 -04:00
|
|
|
const properties = new TableCellProperties();
|
|
|
|
properties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
|
|
|
|
const borders = properties.Borders;
|
2018-11-15 03:00:26 +00:00
|
|
|
|
|
|
|
const tree = new Formatter().format(borders);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tcBorders": [{ "w:top": { _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } } }],
|
2018-11-15 03:00:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|