2019-03-05 01:39:51 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
|
|
|
|
import { TableCell } from "./table-cell";
|
|
|
|
import { TableColumn } from "./table-column";
|
|
|
|
|
2019-04-10 13:47:38 -04:00
|
|
|
import { EMPTY_OBJECT } from "file/xml-components";
|
|
|
|
|
2019-03-05 01:39:51 +00:00
|
|
|
describe("TableColumn", () => {
|
|
|
|
let cells: TableCell[];
|
|
|
|
beforeEach(() => {
|
|
|
|
cells = [new TableCell(), new TableCell(), new TableCell()];
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#getCell", () => {
|
|
|
|
it("should get the correct cell", () => {
|
|
|
|
const tableColumn = new TableColumn(cells);
|
|
|
|
const cell = tableColumn.getCell(0);
|
|
|
|
|
|
|
|
expect(cell).to.deep.equal(cells[0]);
|
|
|
|
|
|
|
|
const cell2 = tableColumn.getCell(1);
|
|
|
|
|
|
|
|
expect(cell2).to.deep.equal(cells[1]);
|
|
|
|
});
|
2019-03-05 01:45:04 +00:00
|
|
|
|
|
|
|
it("should throw an error if index is out of bounds", () => {
|
|
|
|
const tableColumn = new TableColumn(cells);
|
|
|
|
|
|
|
|
expect(() => tableColumn.getCell(9)).to.throw();
|
|
|
|
});
|
2019-03-05 01:39:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#mergeCells", () => {
|
|
|
|
it("should add vMerge to correct cells", () => {
|
|
|
|
const tableColumn = new TableColumn(cells);
|
|
|
|
tableColumn.mergeCells(0, 2);
|
|
|
|
|
|
|
|
const tree = new Formatter().format(cells[0]);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-10 13:47:38 -04:00
|
|
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, { "w:p": EMPTY_OBJECT }],
|
2019-03-05 01:39:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const tree2 = new Formatter().format(cells[1]);
|
2019-05-16 11:15:20 -04:00
|
|
|
expect(tree2).to.deep.equal({
|
|
|
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": EMPTY_OBJECT }],
|
|
|
|
});
|
2019-03-05 01:39:51 +00:00
|
|
|
|
|
|
|
const tree3 = new Formatter().format(cells[2]);
|
|
|
|
expect(tree3).to.deep.equal({
|
2019-04-10 13:47:38 -04:00
|
|
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": EMPTY_OBJECT }],
|
2019-03-05 01:39:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|