Add tests and clean up code
This commit is contained in:
@ -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",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user