2018-07-03 13:48:31 +02:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
import { Formatter } from "export/formatter";
|
2021-05-23 08:00:49 +03:00
|
|
|
import { BorderStyle } from "file/border";
|
2018-10-26 01:04:07 +01:00
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
import { PageBorderDisplay, PageBorders, PageBorderZOrder } from "./page-borders";
|
2018-07-03 13:48:31 +02:00
|
|
|
|
|
|
|
describe("PageBorders", () => {
|
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("should create empty element when no options are passed", () => {
|
|
|
|
const properties = new PageBorders();
|
2018-09-20 00:41:57 +01:00
|
|
|
expect(() => new Formatter().format(properties)).to.throw();
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should create page borders with some configuration", () => {
|
|
|
|
const properties = new PageBorders({
|
|
|
|
pageBorders: {
|
|
|
|
display: PageBorderDisplay.FIRST_PAGE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:pgBorders"]);
|
2019-04-09 05:27:18 -04:00
|
|
|
expect(tree["w:pgBorders"]).to.deep.equal({ _attr: { "w:display": "firstPage" } });
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
|
2021-03-13 19:53:36 +00:00
|
|
|
it("should create page borders with default configuration", () => {
|
|
|
|
const properties = new PageBorders({});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:pgBorders"]);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pgBorders": {
|
|
|
|
_attr: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-03 13:48:31 +02:00
|
|
|
it("should create page borders with full configuration", () => {
|
|
|
|
const properties = new PageBorders({
|
|
|
|
pageBorders: {
|
|
|
|
display: PageBorderDisplay.FIRST_PAGE,
|
|
|
|
zOrder: PageBorderZOrder.BACK,
|
|
|
|
},
|
|
|
|
pageBorderTop: {
|
|
|
|
style: BorderStyle.DOUBLE_WAVE,
|
|
|
|
size: 10,
|
|
|
|
color: "001122",
|
|
|
|
},
|
|
|
|
pageBorderRight: {
|
|
|
|
style: BorderStyle.DOUBLE,
|
|
|
|
size: 20,
|
|
|
|
color: "223344",
|
|
|
|
},
|
|
|
|
pageBorderBottom: {
|
|
|
|
style: BorderStyle.SINGLE,
|
|
|
|
size: 30,
|
|
|
|
color: "556677",
|
|
|
|
},
|
|
|
|
pageBorderLeft: {
|
|
|
|
style: BorderStyle.DOTTED,
|
|
|
|
size: 40,
|
|
|
|
color: "889900",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:pgBorders"]);
|
|
|
|
expect(tree["w:pgBorders"]).to.be.an.instanceof(Array);
|
|
|
|
expect(tree["w:pgBorders"][0]).to.deep.equal({ _attr: { "w:display": "firstPage", "w:zOrder": "back" } });
|
|
|
|
expect(tree["w:pgBorders"][1]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:top": {
|
2021-05-23 07:14:00 +03:00
|
|
|
_attr: { "w:color": "001122", "w:sz": 10, "w:val": "doubleWave" },
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
expect(tree["w:pgBorders"][2]).to.deep.equal({
|
2021-05-25 03:41:12 +03:00
|
|
|
"w:left": {
|
|
|
|
_attr: { "w:color": "889900", "w:sz": 40, "w:val": "dotted" },
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
expect(tree["w:pgBorders"][3]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:bottom": {
|
2021-05-23 07:14:00 +03:00
|
|
|
_attr: { "w:color": "556677", "w:sz": 30, "w:val": "single" },
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
expect(tree["w:pgBorders"][4]).to.deep.equal({
|
2021-05-25 03:41:12 +03:00
|
|
|
"w:right": {
|
|
|
|
_attr: { "w:color": "223344", "w:sz": 20, "w:val": "double" },
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-07-03 13:48:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|