Files
docx-js/src/file/table/properties.spec.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-03-10 17:38:04 +01:00
import { expect } from "chai";
import { Formatter } from "../../export/formatter";
import { TableProperties } from "./properties";
2018-08-23 00:55:33 +01:00
import { WidthType } from "./table-cell";
2017-03-10 17:38:04 +01:00
describe("TableProperties", () => {
describe("#constructor", () => {
it("creates an initially empty property object", () => {
const tp = new TableProperties();
const tree = new Formatter().format(tp);
2018-01-23 01:33:12 +00:00
expect(tree).to.deep.equal({ "w:tblPr": [] });
2017-03-10 17:38:04 +01:00
});
});
describe("#setWidth", () => {
it("adds a table width property", () => {
2018-08-23 00:55:33 +01:00
const tp = new TableProperties().setWidth(WidthType.DXA, 1234);
2017-03-10 17:38:04 +01:00
const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({
2018-01-23 01:33:12 +00:00
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }],
2017-03-10 17:38:04 +01:00
});
});
});
2018-08-07 01:25:28 +01:00
describe("#setFixedWidthLayout", () => {
it("sets the table to fixed width layout", () => {
2018-08-07 01:25:28 +01:00
const tp = new TableProperties().setFixedWidthLayout();
const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({
2018-01-23 01:33:12 +00:00
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
});
});
});
2018-08-23 00:55:33 +01:00
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:sz": "dxa", "w:w": 1234 } }] }] }],
});
});
});
2017-03-10 17:38:04 +01:00
});