added Spacing for paragraphs and ParagraphStyle

This commit is contained in:
felipe
2017-03-09 12:12:33 +01:00
parent 449d1bc2c3
commit 20ec9b679e
6 changed files with 93 additions and 0 deletions

View File

@ -188,4 +188,21 @@ describe("Paragraph", () => {
})
});
});
describe("#spacing", () => {
it("should set the paragraph spacing to the given values", () => {
paragraph.spacing({before: 90, line: 50});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"_attr": {}},
{"w:spacing": [{"_attr": {"w:before": 90, "w:line": 50}}]},
],
},
]
})
});
});
});

View File

@ -0,0 +1,24 @@
import { expect } from "chai";
import { Spacing } from "../../../docx/paragraph/spacing";
import { Formatter } from "../../../export/formatter";
describe("Spacing", () => {
describe("#constructor", () => {
it("should set the properties given", () => {
const spacing = new Spacing({before: 100, after: 120, line: 150});
const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({
"w:spacing": [{_attr: {"w:after": 120, "w:before": 100, "w:line": 150}}],
});
});
it("should only set the given properties", () => {
const spacing = new Spacing({before: 100});
const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({
"w:spacing": [{_attr: {"w:before": 100}}],
});
});
});
});

View File

@ -171,6 +171,22 @@ describe("ParagraphStyle", () => {
],
});
});
it("#spacing", () => {
const style = new ParagraphStyle("myStyleId")
.spacing({before: 50, after: 150});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [
{_attr: {}},
{"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]},
]},
{"w:rPr": []},
],
});
});
});
describe("formatting methods: run properties", () => {