2019-03-18 23:50:21 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
|
|
|
|
import { TableCell } from "../table-cell";
|
|
|
|
import { TableRow } from "./table-row";
|
|
|
|
|
|
|
|
describe("TableRow", () => {
|
|
|
|
describe("#constructor", () => {
|
|
|
|
it("should create with no cells", () => {
|
|
|
|
const tableRow = new TableRow([]);
|
|
|
|
const tree = new Formatter().format(tableRow);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tr": null,
|
2019-03-18 23:50:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create with one cell", () => {
|
|
|
|
const tableRow = new TableRow([new TableCell()]);
|
|
|
|
const tree = new Formatter().format(tableRow);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:tr": [
|
|
|
|
{
|
|
|
|
"w:tc": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:p": null,
|
2019-03-18 23:50:21 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|