Alignment of tables

This commit is contained in:
Dolan Miu
2019-11-24 01:22:17 +00:00
parent 1bdc93ef59
commit 8bdbd1de39
5 changed files with 61 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { Paragraph } from "../paragraph";
import { AlignmentType, Paragraph } from "../paragraph";
import { Table } from "./table";
// import { WidthType } from "./table-cell";
import { RelativeHorizontalPosition, RelativeVerticalPosition, TableAnchorType } from "./table-properties";
@ -211,6 +211,29 @@ describe("Table", () => {
});
});
it("should center the table", () => {
const table = new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("hello")],
}),
],
}),
],
alignment: AlignmentType.CENTER,
});
const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({
"w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:jc": { _attr: { "w:val": "center" } } }],
});
});
it("should set the table to provided width", () => {
const table = new Table({
rows: [