Add tests

This commit is contained in:
Dolan
2018-11-01 02:22:32 +00:00
parent a84eb16392
commit 61411fd0f3
16 changed files with 673 additions and 223 deletions

8
.nycrc
View File

@ -1,9 +1,9 @@
{
"check-coverage": true,
"lines": 84.56,
"functions": 77.50,
"branches": 71.40,
"statements": 84.30,
"lines": 87.17,
"functions": 83.12,
"branches": 71.22,
"statements": 86.95,
"include": [
"src/**/*.ts"
],

View File

@ -21,7 +21,7 @@ describe("Body", () => {
});
});
describe("addSection", () => {
describe("#addSection", () => {
it("should add section with options", () => {
body.addSection({
width: 10000,
@ -39,5 +39,93 @@ describe("Body", () => {
const newSection = formatted[1]["w:sectPr"];
expect(newSection[0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 10000, "w:w": 10000, "w:orient": "portrait" } }] });
});
it("should add section with default parameters", () => {
body.addSection({
width: 10000,
height: 10000,
});
const tree = new Formatter().format(body);
expect(tree).to.deep.equal({
"w:body": [
{
"w:p": [
{ "w:pPr": [] },
{
"w:pPr": [
{
"w:sectPr": [
{ "w:pgSz": [{ _attr: { "w:w": 11906, "w:h": 16838, "w:orient": "portrait" } }] },
{
"w:pgMar": [
{
_attr: {
"w:top": 1440,
"w:right": 1440,
"w:bottom": 1440,
"w:left": 1440,
"w:header": 708,
"w:footer": 708,
"w:gutter": 0,
"w:mirrorMargins": false,
},
},
],
},
{ "w:cols": [{ _attr: { "w:space": 708 } }] },
{ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] },
{ "w:pgNumType": [{ _attr: { "w:fmt": "decimal" } }] },
],
},
],
},
],
},
{
"w:sectPr": [
{ "w:pgSz": [{ _attr: { "w:w": 10000, "w:h": 10000, "w:orient": "portrait" } }] },
{
"w:pgMar": [
{
_attr: {
"w:top": 1440,
"w:right": 1440,
"w:bottom": 1440,
"w:left": 1440,
"w:header": 708,
"w:footer": 708,
"w:gutter": 0,
"w:mirrorMargins": false,
},
},
],
},
{ "w:cols": [{ _attr: { "w:space": 708 } }] },
{ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] },
{ "w:pgNumType": [{ _attr: { "w:fmt": "decimal" } }] },
],
},
],
});
});
});
describe("#getParagraphs", () => {
it("should get no paragraphs", () => {
const paragraphs = body.getParagraphs();
expect(paragraphs).to.be.an.instanceof(Array);
});
});
describe("#DefaultSection", () => {
it("should get section", () => {
const section = body.DefaultSection;
const tree = new Formatter().format(section);
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
});
});
});

View File

@ -38,8 +38,6 @@ export class Body extends XmlComponent {
public prepForXml(): IXmlableObject | undefined {
if (this.sections.length === 1) {
this.root.push(this.sections[0]);
} else if (this.sections.length > 1) {
throw new Error("Invalid usage of sections. At the end of the body element there must be ONE section.");
}
return super.prepForXml();

View File

@ -103,7 +103,7 @@ describe("Anchor", () => {
assert.equal(graphic.rootKey, "a:graphic");
});
it("should create a Drawing with text wrapping", () => {
it("should create a Drawing with square text wrapping", () => {
anchor = createDrawing({
textWrapping: {
textWrapStyle: TextWrapStyle.SQUARE,
@ -116,5 +116,44 @@ describe("Anchor", () => {
const textWrap = newJson.root[6];
assert.equal(textWrap.rootKey, "wp:wrapSquare");
});
it("should create a Drawing with no text wrapping", () => {
anchor = createDrawing({
textWrapping: {
textWrapStyle: TextWrapStyle.NONE,
},
});
const newJson = Utility.jsonify(anchor);
assert.equal(newJson.root.length, 10);
const textWrap = newJson.root[6];
assert.equal(textWrap.rootKey, "wp:wrapNone");
});
it("should create a Drawing with tight text wrapping", () => {
anchor = createDrawing({
textWrapping: {
textWrapStyle: TextWrapStyle.TIGHT,
},
});
const newJson = Utility.jsonify(anchor);
assert.equal(newJson.root.length, 10);
const textWrap = newJson.root[6];
assert.equal(textWrap.rootKey, "wp:wrapTight");
});
it("should create a Drawing with tight text wrapping", () => {
anchor = createDrawing({
textWrapping: {
textWrapStyle: TextWrapStyle.TOP_AND_BOTTOM,
},
});
const newJson = Utility.jsonify(anchor);
assert.equal(newJson.root.length, 10);
const textWrap = newJson.root[6];
assert.equal(textWrap.rootKey, "wp:wrapTopAndBottom");
});
});
});

View File

@ -0,0 +1,29 @@
import { expect } from "chai";
import * as sinon from "sinon";
import { HeaderWrapper } from "./header-wrapper";
import { Media } from "./media";
import { Paragraph } from "./paragraph";
import { Table } from "./table";
describe("HeaderWrapper", () => {
describe("#addParagraph", () => {
it("should call the underlying header's addParagraph", () => {
const file = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(file.Header, "addParagraph");
file.addParagraph(new Paragraph());
expect(spy.called).to.equal(true);
});
});
describe("#addTable", () => {
it("should call the underlying header's addParagraph", () => {
const file = new HeaderWrapper(new Media(), 1);
const spy = sinon.spy(file.Header, "addTable");
file.addTable(new Table(1, 1));
expect(spy.called).to.equal(true);
});
});
});

View File

@ -0,0 +1,112 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { File } from "../file";
import { Media } from "./media";
describe("Media", () => {
describe("#addImage", () => {
it("Add image", () => {
// tslint:disable-next-line:no-any
const file = new File();
const image = Media.addImage(file, "");
let tree = new Formatter().format(image.Paragraph);
expect(tree["w:p"]).to.be.an.instanceof(Array);
tree = new Formatter().format(image.Run);
expect(tree["w:r"]).to.be.an.instanceof(Array);
});
});
describe("#addMedia", () => {
it("should add media", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const image = new Media().addMedia("", 1);
expect(image.fileName).to.equal("test.png");
expect(image.referenceId).to.equal(1);
expect(image.dimensions).to.deep.equal({
pixels: {
x: 100,
y: 100,
},
emus: {
x: 952500,
y: 952500,
},
});
});
it("should return UInt8Array if atob is present", () => {
// tslint:disable-next-line
((process as any).atob as any) = () => "atob result";
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const image = new Media().addMedia("", 1);
expect(image.stream).to.be.an.instanceof(Uint8Array);
});
});
describe("#getMedia", () => {
it("should get media", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const media = new Media();
media.addMedia("", 1);
const image = media.getMedia("test.png");
expect(image.fileName).to.equal("test.png");
expect(image.referenceId).to.equal(1);
expect(image.dimensions).to.deep.equal({
pixels: {
x: 100,
y: 100,
},
emus: {
x: 952500,
y: 952500,
},
});
});
it("Get media", () => {
const media = new Media();
expect(() => media.getMedia("test.png")).to.throw();
});
});
describe("#Array", () => {
it("Get images as array", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const media = new Media();
media.addMedia("", 1);
const array = media.Array;
expect(array).to.be.an.instanceof(Array);
expect(array.length).to.equal(1);
const image = array[0];
expect(image.fileName).to.equal("test.png");
expect(image.referenceId).to.equal(1);
expect(image.dimensions).to.deep.equal({
pixels: {
x: 100,
y: 100,
},
emus: {
x: 952500,
y: 952500,
},
});
});
});
});

View File

@ -2,7 +2,7 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { Spacing } from "./spacing";
import { ContextualSpacing, Spacing } from "./spacing";
describe("Spacing", () => {
describe("#constructor", () => {
@ -23,3 +23,23 @@ describe("Spacing", () => {
});
});
});
describe("ContextualSpacing", () => {
describe("#constructor", () => {
it("should create", () => {
const spacing = new ContextualSpacing(true);
const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({
"w:contextualSpacing": [{ _attr: { "w:val": 1 } }],
});
});
it("should create with value of 0 if param is false", () => {
const spacing = new ContextualSpacing(false);
const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({
"w:contextualSpacing": [{ _attr: { "w:val": 0 } }],
});
});
});
});

View File

@ -0,0 +1,12 @@
import { expect } from "chai";
import { DefaultStyle } from "./default-style";
describe("DefaultStyle", () => {
it("creates an initially empty property object", () => {
const style = DefaultStyle();
expect(style).to.have.property("w:styles");
expect(style["w:styles"].length).to.be.greaterThan(1);
expect(style["w:styles"][1]).to.have.property("w:docDefaults");
});
});

View File

@ -0,0 +1,211 @@
/* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
"use strict";
return [
{
_attr: {
"w:name": name,
"w:uiPriority": uiPriority,
"w:qFormat": qFormat,
"w:semiHidden": semiHidden,
"w:unhideWhenUsed": unhideWhenUsed,
},
},
];
}
export function DefaultStyle() {
var style = {
"w:styles": [
{
_attr: {
"xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
"mc:Ignorable": "w14 w15",
},
},
{
"w:docDefaults": [
{
"w:rPrDefault": [
{
"w:rPr": [
{
"w:rFonts": [
{
_attr: {
"w:asciiTheme": "minorHAnsi",
"w:eastAsiaTheme": "minorHAnsi",
"w:hAnsiTheme": "minorHAnsi",
"w:cstheme": "minorBidi",
},
},
],
},
{
"w:sz": [
{
_attr: {
"w:val": "22",
},
},
],
},
{
"w:szCs": [
{
_attr: {
"w:val": "22",
},
},
],
},
{
"w:lang": [
{
_attr: {
"w:val": "en-GB",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
],
},
],
},
],
},
{
"w:pPrDefault": [
{
"w:pPr": [
{
"w:spacing": [
{
_attr: {
"w:after": "160",
"w:line": "259",
"w:lineRule": "auto",
},
},
],
},
],
},
],
},
],
},
{
"w:latentStyles": [
{
_attr: {
"w:defLockedState": "0",
"w:defUIPriority": "99",
"w:defSemiHidden": "0",
"w:defUnhideWhenUsed": "0",
"w:defQFormat": "0",
"w:count": "371",
},
},
{
"w:lsdException": createLsdException("Normal", 0, 1),
},
{
"w:lsdException": createLsdException("heading 1", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 2", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 3", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 4", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 5", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 6", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 7", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 8", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 9", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("index 1", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 2", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 3", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 4", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 5", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 6", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 7", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 8", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 9", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 1", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 2", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 3", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 4", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 5", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 6", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 7", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 8", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 9", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("Normal Indent", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("footnote text", undefined, undefined, 1, 1),
},
],
},
],
};
return style;
}

View File

@ -1,211 +1 @@
/* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
"use strict";
return [
{
_attr: {
"w:name": name,
"w:uiPriority": uiPriority,
"w:qFormat": qFormat,
"w:semiHidden": semiHidden,
"w:unhideWhenUsed": unhideWhenUsed,
},
},
];
}
export function DefaultStyle() {
var style = {
"w:styles": [
{
_attr: {
"xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
"mc:Ignorable": "w14 w15",
},
},
{
"w:docDefaults": [
{
"w:rPrDefault": [
{
"w:rPr": [
{
"w:rFonts": [
{
_attr: {
"w:asciiTheme": "minorHAnsi",
"w:eastAsiaTheme": "minorHAnsi",
"w:hAnsiTheme": "minorHAnsi",
"w:cstheme": "minorBidi",
},
},
],
},
{
"w:sz": [
{
_attr: {
"w:val": "22",
},
},
],
},
{
"w:szCs": [
{
_attr: {
"w:val": "22",
},
},
],
},
{
"w:lang": [
{
_attr: {
"w:val": "en-GB",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
],
},
],
},
],
},
{
"w:pPrDefault": [
{
"w:pPr": [
{
"w:spacing": [
{
_attr: {
"w:after": "160",
"w:line": "259",
"w:lineRule": "auto",
},
},
],
},
],
},
],
},
],
},
{
"w:latentStyles": [
{
_attr: {
"w:defLockedState": "0",
"w:defUIPriority": "99",
"w:defSemiHidden": "0",
"w:defUnhideWhenUsed": "0",
"w:defQFormat": "0",
"w:count": "371",
},
},
{
"w:lsdException": createLsdException("Normal", 0, 1),
},
{
"w:lsdException": createLsdException("heading 1", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 2", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 3", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 4", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 5", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 6", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 7", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 8", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 9", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("index 1", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 2", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 3", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 4", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 5", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 6", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 7", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 8", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 9", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 1", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 2", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 3", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 4", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 5", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 6", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 7", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 8", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 9", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("Normal Indent", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("footnote text", undefined, undefined, 1, 1),
},
],
},
],
};
return style;
}
export * from "./default-style";

View File

@ -179,7 +179,7 @@ export class TableCellWidth extends XmlComponent {
}
}
interface ITableCellShadingAttributesProperties {
export interface ITableCellShadingAttributesProperties {
fill?: string;
color?: string;
val?: string;
@ -197,7 +197,7 @@ class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShading
* Table cell shading element.
*/
export class TableCellShading extends XmlComponent {
constructor(attrs: object) {
constructor(attrs: ITableCellShadingAttributesProperties) {
super("w:shd");
this.root.push(new TableCellShadingAttributes(attrs));
}

View File

@ -0,0 +1,64 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { VerticalAlign, VMergeType, WidthType } from "./table-cell-components";
import { TableCellProperties } from "./table-cell-properties";
describe("TableCellProperties", () => {
describe("#constructor", () => {
it("creates an initially empty property object", () => {
const cellMargain = new TableCellProperties();
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [] });
});
});
describe("#addGridSpan", () => {
it("adds grid span", () => {
const cellMargain = new TableCellProperties();
cellMargain.addGridSpan(1);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": [{ _attr: { "w:val": 1 } }] }] });
});
});
describe("#addVerticalMerge", () => {
it("adds vertical merge", () => {
const cellMargain = new TableCellProperties();
cellMargain.addVerticalMerge(VMergeType.CONTINUE);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] });
});
});
describe("#setVerticalAlign", () => {
it("sets vertical align", () => {
const cellMargain = new TableCellProperties();
cellMargain.setVerticalAlign(VerticalAlign.BOTTOM);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": [{ _attr: { "w:val": "bottom" } }] }] });
});
});
describe("#setWidth", () => {
it("sets width", () => {
const cellMargain = new TableCellProperties();
cellMargain.setWidth(1, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "dxa", "w:w": 1 } }] }] });
});
});
describe("#setShading", () => {
it("sets shading", () => {
const cellMargain = new TableCellProperties();
cellMargain.setShading({
fill: "test",
color: "000",
});
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": [{ _attr: { "w:fill": "test", "w:color": "000" } }] }] });
});
});
});

View File

@ -2,6 +2,7 @@ import { XmlComponent } from "file/xml-components";
import {
GridSpan,
ITableCellShadingAttributesProperties,
TableCellBorders,
TableCellShading,
TableCellWidth,
@ -49,7 +50,7 @@ export class TableCellProperties extends XmlComponent {
return this;
}
public setShading(attrs: object): TableCellProperties {
public setShading(attrs: ITableCellShadingAttributesProperties): TableCellProperties {
this.root.push(new TableCellShading(attrs));
return this;

View File

@ -0,0 +1,51 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { WidthType } from "../table-cell";
import { TableCellMargin } from "./table-cell-margin";
describe("TableCellMargin", () => {
describe("#constructor", () => {
it("should throw an error if theres no child elements", () => {
const cellMargain = new TableCellMargin();
expect(() => new Formatter().format(cellMargain)).to.throw();
});
});
describe("#addTopMargin", () => {
it("adds a table cell top margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addTopMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
});
});
describe("#addLeftMargin", () => {
it("adds a table cell left margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addLeftMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
});
});
describe("#addBottomMargin", () => {
it("adds a table cell bottom margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addBottomMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
});
});
describe("#addRightMargin", () => {
it("adds a table cell right margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addRightMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
});
});
});

View File

@ -43,5 +43,14 @@ describe("TableProperties", () => {
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
});
});
it("adds a table cell left margin", () => {
const tp = new TableProperties();
tp.CellMargin.addLeftMargin(1234, WidthType.DXA);
const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
});
});
});
});

View File

@ -0,0 +1,26 @@
import { expect } from "chai";
import { ImportDotx } from "./import-dotx";
describe("ImportDotx", () => {
describe("#constructor", () => {
it("should create", () => {
const file = new ImportDotx();
expect(file).to.deep.equal({ currentRelationshipId: 1 });
});
});
// describe("#extract", () => {
// it("should create", async () => {
// const file = new ImportDotx();
// const filePath = "./demo/dotx/template.dotx";
// const templateDocument = await file.extract(data);
// await file.extract(data);
// expect(templateDocument).to.be.equal({ currentRelationshipId: 1 });
// });
// });
});