removed empty Attributes from ParagraphProperties

I checked the spec, and "w:pPr" does not take any attributes. I also
converted the paragraph tests to use the deep.equal style to get rid
of some more jsonify!
This commit is contained in:
felipe
2017-03-10 10:32:40 +01:00
parent 958b5ea307
commit 7ff838357a
3 changed files with 103 additions and 51 deletions

View File

@ -4,7 +4,6 @@ export class ParagraphProperties extends XmlComponent {
constructor() { constructor() {
super("w:pPr"); super("w:pPr");
this.root.push(new Attributes());
} }
public push(item: XmlComponent): void { public push(item: XmlComponent): void {

View File

@ -35,80 +35,135 @@ describe("Paragraph", () => {
describe("#heading1()", () => { describe("#heading1()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading1(); paragraph.heading1();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1"); expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading1"}}]}],
},
],
});
}); });
}); });
describe("#heading2()", () => { describe("#heading2()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading2(); paragraph.heading2();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2"); "w:p": [
{
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading2"}}]}],
},
],
});
}); });
}); });
describe("#heading3()", () => { describe("#heading3()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading3(); paragraph.heading3();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3"); "w:p": [
{
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading3"}}]}],
},
],
});
}); });
}); });
describe("#title()", () => { describe("#title()", () => {
it("should add title style to JSON", () => { it("should add title style to JSON", () => {
paragraph.title(); paragraph.title();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title"); "w:p": [
{
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Title"}}]}],
},
],
});
}); });
}); });
describe("#center()", () => { describe("#center()", () => {
it("should add center alignment to JSON", () => { it("should add center alignment to JSON", () => {
paragraph.center(); paragraph.center();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
assert.equal(newJson.root[0].root[1].root[0].root.val, "center"); "w:p": [
{
"w:pPr": [{"w:jc": [{_attr: {"w:val": "center"}}]}],
},
],
});
}); });
}); });
describe("#thematicBreak()", () => { describe("#thematicBreak()", () => {
it("should add thematic break to JSON", () => { it("should add thematic break to JSON", () => {
paragraph.thematicBreak(); paragraph.thematicBreak();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr"); expect(tree).to.deep.equal({
"w:p": [{
"w:pPr": [{
"w:pBdr": [{
"w:bottom": [{
_attr: {
"w:val": "single",
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
},
}],
}],
}],
}],
});
}); });
}); });
describe("#pageBreak()", () => { describe("#pageBreak()", () => {
it("should add page break to JSON", () => { it("should add page break to JSON", () => {
paragraph.pageBreak(); paragraph.pageBreak();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br"); expect(tree).to.deep.equal({
}); "w:p": [{
"w:pPr": [{
it("should add page break with 'page' type", () => { "w:r": [
paragraph.pageBreak(); {"w:rPr": []},
const newJson = Utility.jsonify(paragraph); {"w:br": [{_attr: {"w:type": "page"}}]},
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page"); ],
}],
}],
});
}); });
}); });
describe("#bullet()", () => { describe("#bullet()", () => {
it("should add list paragraph style to JSON", () => { it("should add list paragraph style to JSON", () => {
paragraph.bullet(); paragraph.bullet();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph"); expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}],
});
}); });
it("it should add numbered properties", () => { it("it should add numbered properties", () => {
paragraph.bullet(); paragraph.bullet();
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.isDefined(newJson.root[0].root[2]); expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2);
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
"w:numPr": [
{"w:ilvl": [{_attr: {"w:val": 0}}]},
{"w:numId": [{_attr: {"w:val": 1}}]},
],
});
}); });
}); });
@ -120,8 +175,12 @@ describe("Paragraph", () => {
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract); const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
paragraph.setNumbering(letterNumbering, 0); paragraph.setNumbering(letterNumbering, 0);
const newJson = Utility.jsonify(paragraph); const tree = new Formatter().format(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph"); expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}],
});
}); });
it("it should add numbered properties", () => { it("it should add numbered properties", () => {
@ -136,7 +195,6 @@ describe("Paragraph", () => {
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [
{_attr: {}},
{"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}]}, {"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}]},
{ {
"w:numPr": [ "w:numPr": [
@ -159,7 +217,6 @@ describe("Paragraph", () => {
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [
{_attr: {}},
{"w:pStyle": [{_attr: {"w:val": "myFancyStyle"}}]}, {"w:pStyle": [{_attr: {"w:val": "myFancyStyle"}}]},
], ],
}, },
@ -176,7 +233,6 @@ describe("Paragraph", () => {
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [
{_attr: {}},
{"w:ind": [{_attr: {"w:left": 720}}]}, {"w:ind": [{_attr: {"w:left": 720}}]},
], ],
}, },
@ -193,7 +249,6 @@ describe("Paragraph", () => {
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [
{_attr: {}},
{"w:spacing": [{_attr: {"w:before": 90, "w:line": 50}}]}, {"w:spacing": [{_attr: {"w:before": 90, "w:line": 50}}]},
], ],
}, },

View File

@ -25,7 +25,7 @@ describe("Styles", () => {
expect(tree).to.deep.equal([{ expect(tree).to.deep.equal([{
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
], ],
}]); }]);
@ -38,7 +38,7 @@ describe("Styles", () => {
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
{"w:name": [{_attr: {"w:val": "Paragraph Style"}}]}, {"w:name": [{_attr: {"w:val": "Paragraph Style"}}]},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
], ],
}]); }]);
@ -118,7 +118,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
], ],
}); });
@ -131,7 +131,7 @@ describe("ParagraphStyle", () => {
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:name": [{_attr: {"w:val": "Style Name"}}]}, {"w:name": [{_attr: {"w:val": "Style Name"}}]},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
], ],
}); });
@ -146,7 +146,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
{"w:basedOn": [{_attr: {"w:val": "otherId"}}]}, {"w:basedOn": [{_attr: {"w:val": "otherId"}}]},
], ],
@ -160,7 +160,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
{"w:qFormat": []}, {"w:qFormat": []},
], ],
@ -174,7 +174,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": []}, {"w:rPr": []},
{"w:next": [{_attr: {"w:val": "otherId"}}]}, {"w:next": [{_attr: {"w:val": "otherId"}}]},
], ],
@ -191,7 +191,6 @@ describe("ParagraphStyle", () => {
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [ {"w:pPr": [
{_attr: {}},
{"w:ind": [{_attr: {"w:left": 720}}]}, {"w:ind": [{_attr: {"w:left": 720}}]},
]}, ]},
{"w:rPr": []}, {"w:rPr": []},
@ -207,7 +206,6 @@ describe("ParagraphStyle", () => {
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [ {"w:pPr": [
{_attr: {}},
{"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]}, {"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]},
]}, ]},
{"w:rPr": []}, {"w:rPr": []},
@ -224,7 +222,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:sz": [{_attr: {"w:val": 24}}]}, {"w:sz": [{_attr: {"w:val": 24}}]},
]}, ]},
@ -239,7 +237,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:b": [{_attr: {"w:val": true}}]}, {"w:b": [{_attr: {"w:val": true}}]},
]}, ]},
@ -254,7 +252,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:i": [{_attr: {"w:val": true}}]}, {"w:i": [{_attr: {"w:val": true}}]},
]}, ]},
@ -270,7 +268,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:u": [{_attr: {"w:val": "single"}}]}, {"w:u": [{_attr: {"w:val": "single"}}]},
]}, ]},
@ -285,7 +283,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:u": [{_attr: {"w:val": "double"}}]}, {"w:u": [{_attr: {"w:val": "double"}}]},
]}, ]},
@ -300,7 +298,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]}, {"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]},
]}, ]},
@ -316,7 +314,7 @@ describe("ParagraphStyle", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]}, {"w:pPr": []},
{"w:rPr": [ {"w:rPr": [
{"w:color": [{_attr: {"w:val": "123456"}}]}, {"w:color": [{_attr: {"w:val": "123456"}}]},
]}, ]},