2023-06-05 00:33:43 +01:00
|
|
|
import { describe, expect, it } from "vitest";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { Formatter } from "@export/formatter";
|
|
|
|
import { BorderStyle } from "@file/border";
|
2025-05-02 13:58:10 -05:00
|
|
|
import { VerticalAlignTable } from "@file/vertical-align";
|
2021-05-24 21:06:34 +03:00
|
|
|
|
2021-05-23 21:17:20 +03:00
|
|
|
import { WidthType } from "../table-width";
|
2021-05-24 21:06:34 +03:00
|
|
|
import { VerticalMergeType } 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", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({});
|
2019-04-09 05:27:18 -04:00
|
|
|
// 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
|
|
|
});
|
|
|
|
|
|
|
|
it("adds grid span", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({ columnSpan: 1 });
|
2019-04-09 05:27:18 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
it("adds vertical merge", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({ verticalMerge: 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
|
|
|
});
|
|
|
|
|
|
|
|
it("sets vertical align", () => {
|
2025-05-02 13:58:10 -05:00
|
|
|
const properties = new TableCellProperties({ verticalAlign: VerticalAlignTable.BOTTOM });
|
2019-04-09 05:27:18 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2018-11-15 03:00:26 +00:00
|
|
|
it("should set width", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({
|
|
|
|
width: {
|
|
|
|
size: 1,
|
|
|
|
type: WidthType.DXA,
|
|
|
|
},
|
|
|
|
});
|
2019-04-09 05:27:18 -04:00
|
|
|
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", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({
|
|
|
|
width: {
|
|
|
|
size: 1,
|
|
|
|
},
|
|
|
|
});
|
2019-04-09 05:27:18 -04:00
|
|
|
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
|
|
|
|
|
|
|
it("sets shading", () => {
|
2021-05-22 04:03:40 +03:00
|
|
|
const properties = new TableCellProperties({
|
|
|
|
shading: {
|
2021-05-24 08:20:08 +03:00
|
|
|
fill: "ffffff",
|
|
|
|
color: "000000",
|
2021-05-22 04:03:40 +03:00
|
|
|
},
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-04-09 05:27:18 -04:00
|
|
|
const tree = new Formatter().format(properties);
|
2021-05-24 08:20:08 +03:00
|
|
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": { _attr: { "w:fill": "ffffff", "w:color": "000000" } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2018-11-15 03:00:26 +00:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
it("should set the TableCellBorders", () => {
|
|
|
|
const properties = new TableCellProperties({
|
|
|
|
borders: {
|
|
|
|
top: {
|
|
|
|
style: BorderStyle.DASH_DOT_STROKED,
|
2021-05-24 08:42:34 +03:00
|
|
|
color: "ff0000",
|
2021-05-22 04:03:40 +03:00
|
|
|
size: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2018-11-15 03:00:26 +00:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
const tree = new Formatter().format(properties);
|
2018-11-15 03:00:26 +00:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
expect(tree["w:tcPr"][0]).to.deep.equal({
|
2021-05-24 08:42:34 +03:00
|
|
|
"w:tcBorders": [{ "w:top": { _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "ff0000" } } }],
|
2018-11-15 03:00:26 +00:00
|
|
|
});
|
|
|
|
});
|
2021-05-23 21:17:20 +03:00
|
|
|
|
|
|
|
it("should set the margins", () => {
|
|
|
|
const properties = new TableCellProperties({
|
|
|
|
margins: {
|
|
|
|
marginUnitType: WidthType.DXA,
|
|
|
|
top: 5,
|
|
|
|
left: 10,
|
|
|
|
bottom: 15,
|
|
|
|
right: 20,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree["w:tcPr"][0]).to.deep.equal({
|
|
|
|
"w:tcMar": [
|
|
|
|
{ "w:top": { _attr: { "w:type": "dxa", "w:w": 5 } } },
|
|
|
|
{ "w:left": { _attr: { "w:type": "dxa", "w:w": 10 } } },
|
|
|
|
{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 15 } } },
|
|
|
|
{ "w:right": { _attr: { "w:type": "dxa", "w:w": 20 } } },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2018-11-15 03:00:26 +00:00
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|