2019-03-18 23:50:21 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
import { Paragraph } from "file/paragraph";
|
2019-06-25 14:48:45 +02:00
|
|
|
import { HeightRule } from "file/table/table-row/table-row-height";
|
|
|
|
import { EMPTY_OBJECT } from "file/xml-components";
|
2019-03-18 23:50:21 +00:00
|
|
|
import { TableCell } from "../table-cell";
|
|
|
|
import { TableRow } from "./table-row";
|
|
|
|
|
|
|
|
describe("TableRow", () => {
|
|
|
|
describe("#constructor", () => {
|
|
|
|
it("should create with no cells", () => {
|
2019-09-13 00:51:20 +01:00
|
|
|
const tableRow = new TableRow({
|
|
|
|
children: [],
|
|
|
|
});
|
2019-03-18 23:50:21 +00:00
|
|
|
const tree = new Formatter().format(tableRow);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-10 13:47:38 -04:00
|
|
|
"w:tr": EMPTY_OBJECT,
|
2019-03-18 23:50:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create with one cell", () => {
|
2019-09-13 00:51:20 +01:00
|
|
|
const tableRow = new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
2019-03-18 23:50:21 +00:00
|
|
|
const tree = new Formatter().format(tableRow);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:tr": [
|
|
|
|
{
|
|
|
|
"w:tc": [
|
|
|
|
{
|
2019-04-10 13:47:38 -04:00
|
|
|
"w:p": EMPTY_OBJECT,
|
2019-03-18 23:50:21 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-25 14:48:45 +02:00
|
|
|
it("should set row height", () => {
|
2019-09-13 00:51:20 +01:00
|
|
|
const tableRow = new TableRow({
|
|
|
|
children: [],
|
|
|
|
height: {
|
|
|
|
height: 100,
|
|
|
|
rule: HeightRule.EXACT,
|
|
|
|
},
|
|
|
|
});
|
2019-06-25 14:48:45 +02:00
|
|
|
const tree = new Formatter().format(tableRow);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:tr": [
|
|
|
|
{
|
|
|
|
"w:trPr": [
|
|
|
|
{
|
|
|
|
"w:trHeight": {
|
|
|
|
_attr: {
|
|
|
|
"w:hRule": "exact",
|
|
|
|
"w:val": 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-13 00:51:20 +01:00
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
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.addCellToIndex(
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
0,
|
|
|
|
);
|
2019-09-13 00:51:20 +01:00
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
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",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-03-18 23:50:21 +00:00
|
|
|
});
|