Declarative tables

This commit is contained in:
Dolan
2019-09-13 00:51:20 +01:00
parent 59fc1ed632
commit 418adca9f3
21 changed files with 978 additions and 536 deletions

View File

@ -10,7 +10,9 @@ import { TableRow } from "./table-row";
describe("TableRow", () => {
describe("#constructor", () => {
it("should create with no cells", () => {
const tableRow = new TableRow([]);
const tableRow = new TableRow({
children: [],
});
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": EMPTY_OBJECT,
@ -18,7 +20,13 @@ describe("TableRow", () => {
});
it("should create with one cell", () => {
const tableRow = new TableRow([new TableCell()]);
const tableRow = new TableRow({
children: [
new TableCell({
children: [],
}),
],
});
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": [
@ -32,46 +40,15 @@ describe("TableRow", () => {
],
});
});
});
describe("#getCell", () => {
it("should get the cell", () => {
const cell = new TableCell();
const tableRow = new TableRow([cell]);
expect(tableRow.getCell(0)).to.equal(cell);
});
it("should throw an error if index is out of bounds", () => {
const cell = new TableCell();
const tableRow = new TableRow([cell]);
expect(() => tableRow.getCell(1)).to.throw();
});
});
describe("#addGridSpan", () => {
it("should merge the cell", () => {
const tableRow = new TableRow([new TableCell(), new TableCell()]);
tableRow.addGridSpan(0, 2);
expect(() => tableRow.getCell(1)).to.throw();
});
});
describe("#mergeCells", () => {
it("should merge the cell", () => {
const tableRow = new TableRow([new TableCell(), new TableCell()]);
tableRow.mergeCells(0, 1);
expect(() => tableRow.getCell(1)).to.throw();
});
});
describe("#setHeight", () => {
it("should set row height", () => {
const tableRow = new TableRow([]);
tableRow.setHeight(100, HeightRule.EXACT);
const tableRow = new TableRow({
children: [],
height: {
height: 100,
rule: HeightRule.EXACT,
},
});
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": [
@ -91,4 +68,22 @@ describe("TableRow", () => {
});
});
});
// describe("#mergeCells", () => {
// it("should merge the cell", () => {
// const tableRow = new TableRow({
// children: [
// new TableCell({
// children: [],
// }),
// new TableCell({
// children: [],
// }),
// ],
// });
// tableRow.mergeCells(0, 1);
// expect(() => tableRow.getCell(1)).to.throw();
// });
// });
});