Add tests and clean up code

This commit is contained in:
Dolan
2019-09-29 04:17:21 +01:00
parent c5eb3d5670
commit 172c333357
21 changed files with 797 additions and 148 deletions

View File

@ -8,7 +8,7 @@ import { Table } from "./table";
// import { WidthType } from "./table-cell";
import { RelativeHorizontalPosition, RelativeVerticalPosition, TableAnchorType } from "./table-properties";
import { TableCell } from "./table-cell";
import { TableCell, WidthType } from "./table-cell";
import { TableLayoutType } from "./table-properties/table-layout";
import { TableRow } from "./table-row";
@ -210,6 +210,45 @@ describe("Table", () => {
"w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }],
});
});
it("should set the table to provided width", () => {
const table = new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("hello")],
}),
],
}),
],
width: {
size: 100,
type: WidthType.PERCENTAGE,
},
layout: TableLayoutType.FIXED,
});
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,
{
"w:tblW": {
_attr: {
"w:type": "pct",
"w:w": "100%",
},
},
},
{ "w:tblLayout": { _attr: { "w:type": "fixed" } } },
],
});
});
});
describe("Cell", () => {