Rework the way attributes are stored in ImportedXmlComponent to match elsewhere (required allowing for a null xmlKeys in the XmlAttributeComponent interface). Rework the way paragraphs get added to the end of table cells if needed. The goal in both reworks is to not mess around with the objects output from `prepForXml` if we can avoid it. Made the output of RunProperties, ParagraphProperties, TableCellProperties, TableRowProperties, and TableProperties all optional based on whether they contain any attributes or children. Changed code in PageBorders, TableCellMargin, and TableCellBorders that implemented this same thing by overriding `prepForXml` so that it uses the new XmlComponent subclass instead. Removed commented out code that attempted to fix-up XML output and make proper empty elements. Fixed all affected tests. Turn off `no-null-keyword` in the linter as we need to use null to signal to the `xml` library to create an empty element with no attributes (`undefined` will not work in its place). Fixes #306
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import { expect } from "chai";
|
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
import { WidthType } from "../table-cell";
|
|
import { TableProperties } from "./table-properties";
|
|
|
|
describe("TableProperties", () => {
|
|
describe("#constructor", () => {
|
|
it("creates an initially empty property object", () => {
|
|
const tp = new TableProperties();
|
|
// The TableProperties 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(tp)).to.throw("XMLComponent did not format correctly");
|
|
});
|
|
});
|
|
|
|
describe("#setWidth", () => {
|
|
it("should add a table width property", () => {
|
|
const tp = new TableProperties().setWidth(1234, WidthType.DXA);
|
|
const tree = new Formatter().format(tp);
|
|
expect(tree).to.deep.equal({
|
|
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "dxa", "w:w": 1234 } } }],
|
|
});
|
|
});
|
|
|
|
it("should add a table width property with default of AUTO", () => {
|
|
const tp = new TableProperties().setWidth(1234);
|
|
const tree = new Formatter().format(tp);
|
|
expect(tree).to.deep.equal({
|
|
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "auto", "w:w": 1234 } } }],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("#setFixedWidthLayout", () => {
|
|
it("sets the table to fixed width layout", () => {
|
|
const tp = new TableProperties().setFixedWidthLayout();
|
|
const tree = new Formatter().format(tp);
|
|
expect(tree).to.deep.equal({
|
|
"w:tblPr": [{ "w:tblLayout": { _attr: { "w:type": "fixed" } } }],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("#cellMargin", () => {
|
|
it("adds a table cell top margin", () => {
|
|
const tp = new TableProperties();
|
|
tp.CellMargin.addTopMargin(1234, WidthType.DXA);
|
|
const tree = new Formatter().format(tp);
|
|
expect(tree).to.deep.equal({
|
|
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "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:type": "dxa", "w:w": 1234 } } }] }],
|
|
});
|
|
});
|
|
});
|
|
});
|