Made project Prettier compliant
This commit is contained in:
@ -9,14 +9,14 @@ describe("GridCol", () => {
|
||||
const grid = new GridCol(1234);
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:gridCol": [{_attr: {"w:w": 1234}}],
|
||||
"w:gridCol": [{ _attr: { "w:w": 1234 } }],
|
||||
});
|
||||
});
|
||||
|
||||
it("does not set a width attribute if not given", () => {
|
||||
const grid = new GridCol();
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({"w:gridCol": []});
|
||||
expect(tree).to.deep.equal({ "w:gridCol": [] });
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -28,9 +28,9 @@ describe("TableGrid", () => {
|
||||
const tree = new Formatter().format(grid);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblGrid": [
|
||||
{"w:gridCol": [{_attr: {"w:w": 1234}}]},
|
||||
{"w:gridCol": [{_attr: {"w:w": 321}}]},
|
||||
{"w:gridCol": [{_attr: {"w:w": 123}}]},
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 1234 } }] },
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 321 } }] },
|
||||
{ "w:gridCol": [{ _attr: { "w:w": 123 } }] },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -7,15 +7,15 @@ export class TableGrid extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class GridColAttributes extends XmlAttributeComponent<{w: number}> {
|
||||
protected xmlKeys = {w: "w:w"};
|
||||
class GridColAttributes extends XmlAttributeComponent<{ w: number }> {
|
||||
protected xmlKeys = { w: "w:w" };
|
||||
}
|
||||
|
||||
export class GridCol extends XmlComponent {
|
||||
constructor(width?: number) {
|
||||
super("w:gridCol");
|
||||
if (width !== undefined) {
|
||||
this.root.push(new GridColAttributes({w: width}));
|
||||
this.root.push(new GridColAttributes({ w: width }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ describe("TableProperties", () => {
|
||||
it("creates an initially empty property object", () => {
|
||||
const tp = new TableProperties();
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({"w:tblPr": []});
|
||||
expect(tree).to.deep.equal({ "w:tblPr": [] });
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,9 +17,7 @@ describe("TableProperties", () => {
|
||||
const tp = new TableProperties().setWidth("dxa", 1234);
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblW": [{_attr: {"w:type": "dxa", "w:w": 1234}}]},
|
||||
],
|
||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -29,9 +27,7 @@ describe("TableProperties", () => {
|
||||
const tp = new TableProperties().fixedWidthLayout();
|
||||
const tree = new Formatter().format(tp);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
|
||||
],
|
||||
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -24,25 +24,25 @@ interface ITableWidth {
|
||||
}
|
||||
|
||||
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
|
||||
protected xmlKeys = {type: "w:type", w: "w:w"};
|
||||
protected xmlKeys = { type: "w:type", w: "w:w" };
|
||||
}
|
||||
|
||||
class PreferredTableWidth extends XmlComponent {
|
||||
constructor(type: WidthTypes, w: number | string) {
|
||||
super("w:tblW");
|
||||
this.root.push(new TableWidthAttributes({type, w}));
|
||||
this.root.push(new TableWidthAttributes({ type, w }));
|
||||
}
|
||||
}
|
||||
|
||||
type TableLayoutOptions = "autofit" | "fixed";
|
||||
|
||||
class TableLayoutAttributes extends XmlAttributeComponent<{type: TableLayoutOptions}> {
|
||||
protected xmlKeys = {type: "w:type"};
|
||||
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutOptions }> {
|
||||
protected xmlKeys = { type: "w:type" };
|
||||
}
|
||||
|
||||
class TableLayout extends XmlComponent {
|
||||
constructor(type: TableLayoutOptions) {
|
||||
super("w:tblLayout");
|
||||
this.root.push(new TableLayoutAttributes({type}));
|
||||
this.root.push(new TableLayoutAttributes({ type }));
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,16 @@ describe("Table", () => {
|
||||
it("creates a table with the correct number of rows and columns", () => {
|
||||
const table = new Table(3, 2);
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = {"w:tc": [{"w:tcPr": []}, {"w:p": [{"w:pPr": []}]}]};
|
||||
const cell = { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] };
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tbl": [
|
||||
{"w:tblPr": []},
|
||||
{"w:tblGrid": [
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
]},
|
||||
{"w:tr": [{"w:trPr": []}, cell, cell]},
|
||||
{"w:tr": [{"w:trPr": []}, cell, cell]},
|
||||
{"w:tr": [{"w:trPr": []}, cell, cell]},
|
||||
{ "w:tblPr": [] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell, cell] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -29,27 +28,39 @@ describe("Table", () => {
|
||||
describe("#getRow and Row#getCell", () => {
|
||||
it("returns the correct row", () => {
|
||||
const table = new Table(2, 2);
|
||||
table.getRow(0).getCell(0).addContent(new Paragraph("A1"));
|
||||
table.getRow(0).getCell(1).addContent(new Paragraph("B1"));
|
||||
table.getRow(1).getCell(0).addContent(new Paragraph("A2"));
|
||||
table.getRow(1).getCell(1).addContent(new Paragraph("B2"));
|
||||
table
|
||||
.getRow(0)
|
||||
.getCell(0)
|
||||
.addContent(new Paragraph("A1"));
|
||||
table
|
||||
.getRow(0)
|
||||
.getCell(1)
|
||||
.addContent(new Paragraph("B1"));
|
||||
table
|
||||
.getRow(1)
|
||||
.getCell(0)
|
||||
.addContent(new Paragraph("A2"));
|
||||
table
|
||||
.getRow(1)
|
||||
.getCell(1)
|
||||
.addContent(new Paragraph("B2"));
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({"w:tc": [
|
||||
{"w:tcPr": []},
|
||||
{"w:p": [
|
||||
{"w:pPr": []},
|
||||
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]},
|
||||
]},
|
||||
]});
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tbl": [
|
||||
{"w:tblPr": []},
|
||||
{"w:tblGrid": [
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
]},
|
||||
{"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]},
|
||||
{"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]},
|
||||
{ "w:tblPr": [] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -63,22 +74,22 @@ describe("Table", () => {
|
||||
table.getCell(1, 0).addContent(new Paragraph("A2"));
|
||||
table.getCell(1, 1).addContent(new Paragraph("B2"));
|
||||
const tree = new Formatter().format(table);
|
||||
const cell = (c) => ({"w:tc": [
|
||||
{"w:tcPr": []},
|
||||
{"w:p": [
|
||||
{"w:pPr": []},
|
||||
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]},
|
||||
]},
|
||||
]});
|
||||
const cell = (c) => ({
|
||||
"w:tc": [
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tbl": [
|
||||
{"w:tblPr": []},
|
||||
{"w:tblGrid": [
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
{"w:gridCol": [{_attr: {"w:w": 1}}]},
|
||||
]},
|
||||
{"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]},
|
||||
{"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]},
|
||||
{ "w:tblPr": [] },
|
||||
{
|
||||
"w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
|
||||
},
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
|
||||
{ "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -88,11 +99,12 @@ describe("Table", () => {
|
||||
it("sets the preferred width on the table", () => {
|
||||
const table = new Table(2, 2).setWidth("pct", 1000);
|
||||
const tree = new Formatter().format(table);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array")
|
||||
.with.has.length.at.least(1);
|
||||
expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblW": [{_attr: {"w:type": "pct", "w:w": 1000}}]},
|
||||
],
|
||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -101,11 +113,12 @@ describe("Table", () => {
|
||||
it("sets the table to fixed width layout", () => {
|
||||
const table = new Table(2, 2).fixedWidthLayout();
|
||||
const tree = new Formatter().format(table);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array")
|
||||
.with.has.length.at.least(1);
|
||||
expect(tree["w:tbl"][0]).to.deep.equal({
|
||||
"w:tblPr": [
|
||||
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
|
||||
],
|
||||
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -115,15 +128,16 @@ describe("Table", () => {
|
||||
it("inserts a paragraph at the end of the cell if it is empty", () => {
|
||||
const table = new Table(1, 1);
|
||||
const tree = new Formatter().format(table);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array");
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array");
|
||||
const row = tree["w:tbl"].find((x) => x["w:tr"]);
|
||||
expect(row).not.to.be.undefined;
|
||||
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
|
||||
expect(row["w:tr"])
|
||||
.to.be.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [
|
||||
{"w:tcPr": []},
|
||||
{"w:p": [{"w:pPr": []}]},
|
||||
],
|
||||
"w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -131,14 +145,18 @@ describe("Table", () => {
|
||||
const parentTable = new Table(1, 1);
|
||||
parentTable.getCell(0, 0).addContent(new Table(1, 1));
|
||||
const tree = new Formatter().format(parentTable);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array");
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array");
|
||||
const row = tree["w:tbl"].find((x) => x["w:tr"]);
|
||||
expect(row).not.to.be.undefined;
|
||||
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
|
||||
expect(row["w:tr"])
|
||||
.to.be.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
const cell = row["w:tr"].find((x) => x["w:tc"]);
|
||||
expect(cell).not.to.be.undefined;
|
||||
expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({
|
||||
"w:p": [{"w:pPr": []}],
|
||||
"w:p": [{ "w:pPr": [] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -146,17 +164,23 @@ describe("Table", () => {
|
||||
const parentTable = new Table(1, 1);
|
||||
parentTable.getCell(0, 0).addContent(new Paragraph("Hello"));
|
||||
const tree = new Formatter().format(parentTable);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array");
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array");
|
||||
const row = tree["w:tbl"].find((x) => x["w:tr"]);
|
||||
expect(row).not.to.be.undefined;
|
||||
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
|
||||
expect(row["w:tr"])
|
||||
.to.be.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [
|
||||
{"w:tcPr": []},
|
||||
{"w:p": [
|
||||
{"w:pPr": []},
|
||||
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, "Hello"]}]},
|
||||
]},
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [
|
||||
{ "w:pPr": [] },
|
||||
{ "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Hello"] }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -168,20 +192,25 @@ describe("Table", () => {
|
||||
const para = table.getCell(0, 0).createParagraph("Test paragraph");
|
||||
expect(para).to.be.an.instanceof(Paragraph);
|
||||
const tree = new Formatter().format(table);
|
||||
expect(tree).to.have.property("w:tbl").which.is.an("array");
|
||||
expect(tree)
|
||||
.to.have.property("w:tbl")
|
||||
.which.is.an("array");
|
||||
const row = tree["w:tbl"].find((x) => x["w:tr"]);
|
||||
expect(row).not.to.be.undefined;
|
||||
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
|
||||
expect(row["w:tr"])
|
||||
.to.be.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
|
||||
"w:tc": [
|
||||
{"w:tcPr": []},
|
||||
{"w:p": [
|
||||
{"w:pPr": []},
|
||||
{"w:r": [
|
||||
{"w:rPr": []},
|
||||
{"w:t": [{_attr: {"xml:space": "preserve"}}, "Test paragraph"]},
|
||||
]},
|
||||
]},
|
||||
{ "w:tcPr": [] },
|
||||
{
|
||||
"w:p": [
|
||||
{ "w:pPr": [] },
|
||||
{
|
||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Test paragraph"] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user