2018-11-01 02:22:32 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { Formatter } from "@export/formatter";
|
2021-05-23 21:17:20 +03:00
|
|
|
import { WidthType } from "../table-width";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
2021-05-23 21:17:20 +03:00
|
|
|
import { TableCellMargin, TableCellMarginElementType } from "./table-cell-margin";
|
2018-11-01 02:22:32 +00:00
|
|
|
|
|
|
|
describe("TableCellMargin", () => {
|
|
|
|
describe("#constructor", () => {
|
|
|
|
it("should throw an error if theres no child elements", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {});
|
2019-04-18 13:55:18 +10:00
|
|
|
expect(() => new Formatter().format(cellMargin)).to.throw();
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addTopMargin", () => {
|
2019-09-29 04:17:21 +01:00
|
|
|
it("should add a table cell top margin", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
marginUnitType: WidthType.DXA,
|
|
|
|
top: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 13:55:18 +10:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
2019-04-09 05:27:18 -04:00
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
|
|
|
|
it("should add a table cell top margin using default width type", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
top: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addLeftMargin", () => {
|
2019-09-29 04:17:21 +01:00
|
|
|
it("should add a table cell left margin", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
marginUnitType: WidthType.DXA,
|
|
|
|
left: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
2019-04-18 13:55:18 +10:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
2019-04-09 05:27:18 -04:00
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
|
|
|
|
it("should add a table cell left margin using default width type", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
left: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addBottomMargin", () => {
|
2019-09-29 04:17:21 +01:00
|
|
|
it("should add a table cell bottom margin", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
marginUnitType: WidthType.DXA,
|
|
|
|
bottom: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 13:55:18 +10:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
2019-04-09 05:27:18 -04:00
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
|
|
|
|
it("should add a table cell bottom margin using default width type", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
bottom: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#addRightMargin", () => {
|
2019-09-29 04:17:21 +01:00
|
|
|
it("should add a table cell right margin", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
marginUnitType: WidthType.DXA,
|
|
|
|
right: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 13:55:18 +10:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
2019-04-09 05:27:18 -04:00
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
2019-09-29 04:17:21 +01:00
|
|
|
|
|
|
|
it("should add a table cell right margin using default width type", () => {
|
2021-05-23 21:17:20 +03:00
|
|
|
const cellMargin = new TableCellMargin(TableCellMarginElementType.TABLE, {
|
|
|
|
right: 1234,
|
2021-03-04 01:42:58 +00:00
|
|
|
});
|
|
|
|
|
2019-09-29 04:17:21 +01:00
|
|
|
const tree = new Formatter().format(cellMargin);
|
|
|
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
|
|
|
});
|
2018-11-01 02:22:32 +00:00
|
|
|
});
|
|
|
|
});
|