2018-01-25 01:21:03 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
import { Formatter } from "../../../../export/formatter";
|
|
|
|
import { SectionProperties } from "./section-properties";
|
2018-06-21 12:03:34 +02:00
|
|
|
import { FooterReferenceType, PageNumberFormat } from ".";
|
2018-01-25 01:21:03 +00:00
|
|
|
|
|
|
|
describe("SectionProperties", () => {
|
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("should create section properties with options", () => {
|
|
|
|
const properties = new SectionProperties({
|
|
|
|
width: 11906,
|
|
|
|
height: 16838,
|
|
|
|
top: 1440,
|
|
|
|
right: 1440,
|
|
|
|
bottom: 1440,
|
|
|
|
left: 1440,
|
|
|
|
header: 708,
|
|
|
|
footer: 708,
|
|
|
|
gutter: 0,
|
|
|
|
space: 708,
|
|
|
|
linePitch: 360,
|
2018-06-21 12:03:34 +02:00
|
|
|
headerId: 100,
|
|
|
|
footerId: 200,
|
|
|
|
footerType: FooterReferenceType.EVEN,
|
|
|
|
pageNumberStart: 10,
|
|
|
|
pageNumberFormatType: PageNumberFormat.CARDINAL_TEXT,
|
2018-01-25 01:21:03 +00:00
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
|
|
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
2018-01-28 20:23:30 +00:00
|
|
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
|
|
|
"w:pgMar": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:bottom": 1440,
|
|
|
|
"w:footer": 708,
|
|
|
|
"w:top": 1440,
|
|
|
|
"w:right": 1440,
|
|
|
|
"w:left": 1440,
|
|
|
|
"w:header": 708,
|
|
|
|
"w:gutter": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-06-21 12:03:34 +02:00
|
|
|
|
|
|
|
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": [{ _attr: { "w:space": 708 } }] });
|
|
|
|
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] });
|
|
|
|
expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": [{ _attr: { "r:id": "rId100", "w:type": "default" } }] });
|
|
|
|
expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": [{ _attr: { "r:id": "rId200", "w:type": "even" } }] });
|
|
|
|
expect(tree["w:sectPr"][6]).to.deep.equal({ "w:pgNumType": [{ _attr: { "w:fmt": "cardinalText", "w:start": 10 } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should create section properties with no options", () => {
|
|
|
|
const properties = new SectionProperties();
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
|
|
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
2018-01-28 20:23:30 +00:00
|
|
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
|
|
|
"w:pgMar": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:bottom": 1440,
|
|
|
|
"w:footer": 708,
|
|
|
|
"w:top": 1440,
|
|
|
|
"w:right": 1440,
|
|
|
|
"w:left": 1440,
|
|
|
|
"w:header": 708,
|
|
|
|
"w:gutter": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-06-21 12:03:34 +02:00
|
|
|
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": [{ _attr: { "w:space": 708 } }] });
|
|
|
|
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] });
|
|
|
|
expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": [{ _attr: { "r:id": "rId0", "w:type": "default" } }] });
|
|
|
|
expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": [{ _attr: { "r:id": "rId0", "w:type": "default" } }] });
|
|
|
|
expect(tree["w:sectPr"][6]).to.deep.equal({ "w:pgNumType": [{ _attr: { "w:fmt": "decimal" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should create section properties with changed options", () => {
|
|
|
|
const properties = new SectionProperties({
|
|
|
|
top: 0,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
|
|
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
2018-01-28 20:23:30 +00:00
|
|
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
|
|
|
"w:pgMar": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:bottom": 1440,
|
|
|
|
"w:footer": 708,
|
|
|
|
"w:top": 0,
|
|
|
|
"w:right": 1440,
|
|
|
|
"w:left": 1440,
|
|
|
|
"w:header": 708,
|
|
|
|
"w:gutter": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create section properties with changed options", () => {
|
|
|
|
const properties = new SectionProperties({
|
|
|
|
bottom: 0,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
|
|
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
2018-01-28 20:23:30 +00:00
|
|
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
|
|
|
"w:pgMar": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:bottom": 0,
|
|
|
|
"w:footer": 708,
|
|
|
|
"w:top": 1440,
|
|
|
|
"w:right": 1440,
|
|
|
|
"w:left": 1440,
|
|
|
|
"w:header": 708,
|
|
|
|
"w:gutter": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create section properties with changed options", () => {
|
|
|
|
const properties = new SectionProperties({
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
|
|
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
2018-01-28 20:23:30 +00:00
|
|
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 0, "w:w": 0, "w:orient": "portrait" } }] });
|
2018-01-25 01:21:03 +00:00
|
|
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
|
|
|
"w:pgMar": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:bottom": 1440,
|
|
|
|
"w:footer": 708,
|
|
|
|
"w:top": 1440,
|
|
|
|
"w:right": 1440,
|
|
|
|
"w:left": 1440,
|
|
|
|
"w:header": 708,
|
|
|
|
"w:gutter": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|