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

@ -2,6 +2,7 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { Paragraph } from "file/paragraph";
import { HeightRule } from "file/table/table-row/table-row-height";
import { EMPTY_OBJECT } from "file/xml-components";
import { TableCell } from "../table-cell";
@ -41,6 +42,52 @@ describe("TableRow", () => {
});
});
it("should create with cant split", () => {
const tableRow = new TableRow({
children: [],
cantSplit: true,
});
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": [
{
"w:trPr": [
{
"w:cantSplit": {
_attr: {
"w:val": true,
},
},
},
],
},
],
});
});
it("should create with table header", () => {
const tableRow = new TableRow({
children: [],
tableHeader: true,
});
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": [
{
"w:trPr": [
{
"w:tblHeader": {
_attr: {
"w:val": true,
},
},
},
],
},
],
});
});
it("should set row height", () => {
const tableRow = new TableRow({
children: [],
@ -69,21 +116,70 @@ describe("TableRow", () => {
});
});
// describe("#mergeCells", () => {
// it("should merge the cell", () => {
// const tableRow = new TableRow({
// children: [
// new TableCell({
// children: [],
// }),
// new TableCell({
// children: [],
// }),
// ],
// });
describe("#addCellToIndex", () => {
it("should add cell to correct index with no initial properties", () => {
const tableRow = new TableRow({
children: [
new TableCell({
children: [new Paragraph("test")],
}),
],
tableHeader: true,
});
// tableRow.mergeCells(0, 1);
// expect(() => tableRow.getCell(1)).to.throw();
// });
// });
tableRow.addCellToIndex(
new TableCell({
children: [],
}),
0,
);
const tree = new Formatter().format(tableRow);
expect(tree).to.deep.equal({
"w:tr": [
{
"w:trPr": [
{
"w:tblHeader": {
_attr: {
"w:val": true,
},
},
},
],
},
{
"w:tc": [
{
"w:p": {},
},
],
},
{
"w:tc": [
{
"w:p": [
{
"w:r": [
{
"w:t": [
{
_attr: {
"xml:space": "preserve",
},
},
"test",
],
},
],
},
],
},
],
},
],
});
});
});
});