Add tests
This commit is contained in:
550
src/file/table/table-properties/table-borders.spec.ts
Normal file
550
src/file/table/table-properties/table-borders.spec.ts
Normal file
@ -0,0 +1,550 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { BorderStyle } from "file/styles";
|
||||
|
||||
import { TableBorders } from "./table-borders";
|
||||
|
||||
describe("TableBorders", () => {
|
||||
describe("#constructor", () => {
|
||||
describe("default borders", () => {
|
||||
it("should add a table cell top border using default width type", () => {
|
||||
const tableBorders = new TableBorders({});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("top border", () => {
|
||||
it("should add a table cell top border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
top: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("left border", () => {
|
||||
it("should add a table cell left border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
left: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("bottom border", () => {
|
||||
it("should add a table cell bottom border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
bottom: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("right border", () => {
|
||||
it("should add a table cell right border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
right: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("inside horizontal border", () => {
|
||||
it("should add a table cell inside horizontal border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
insideHorizontal: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("inside vertical border", () => {
|
||||
it("should add a table cell inside horizontal border", () => {
|
||||
const tableBorders = new TableBorders({
|
||||
insideVertical: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -58,7 +58,7 @@ export class TableBorders extends XmlComponent {
|
||||
}
|
||||
|
||||
if (options.right) {
|
||||
this.root.push(new TableBordersElement("w:right", options.right.style, 4, 0, "auto"));
|
||||
this.root.push(new TableBordersElement("w:right", options.right.style, options.right.size, 0, options.right.color));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:right", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user