Add tests

This commit is contained in:
Dolan
2021-03-13 20:23:15 +00:00
parent cc9a966f53
commit 4bc0421055
6 changed files with 77 additions and 11 deletions

8
.nycrc
View File

@ -1,9 +1,9 @@
{ {
"check-coverage": true, "check-coverage": true,
"lines": 98.19, "lines": 98.31,
"functions": 94.79, "functions": 95.83,
"branches": 95.35, "branches": 95.38,
"statements": 98.17, "statements": 98.29,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],

View File

@ -43,7 +43,20 @@ doc.addSection({
], ],
}), }),
}, },
children: [], children: [
new Paragraph({
children: [
new TextRun({
emboss: true,
text: "Embossed text - hello world",
}),
new TextRun({
imprint: true,
text: "Imprinted text - hello world",
}),
],
}),
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -0,0 +1,22 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { Bold } from "./formatting";
describe("Bold", () => {
describe("#constructor()", () => {
it("should create", () => {
const currentBold = new Bold();
const tree = new Formatter().format(currentBold);
expect(tree).to.deep.equal({
"w:b": {
_attr: {
"w:val": true,
},
},
});
});
});
});

View File

@ -1,10 +1,5 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export { Underline } from "./underline";
export { EmphasisMark } from "./emphasis-mark";
export { SubScript, SuperScript } from "./script";
export { RunFonts, IFontAttributesProperties } from "./run-fonts";
export class Bold extends XmlComponent { export class Bold extends XmlComponent {
constructor() { constructor() {
super("w:b"); super("w:b");

View File

@ -8,8 +8,10 @@ import {
CharacterSpacing, CharacterSpacing,
Color, Color,
DoubleStrike, DoubleStrike,
Emboss,
Highlight, Highlight,
HighlightComplexScript, HighlightComplexScript,
Imprint,
Italics, Italics,
ItalicsComplexScript, ItalicsComplexScript,
RightToLeft, RightToLeft,
@ -63,6 +65,8 @@ export interface IRunStylePropertiesOptions {
}; };
readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"]; readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"];
readonly shadow?: IRunStylePropertiesOptions["shading"]; readonly shadow?: IRunStylePropertiesOptions["shading"];
readonly emboss?: boolean;
readonly imprint?: boolean;
} }
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions { export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
@ -169,6 +173,14 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
this.push(new CharacterSpacing(options.characterSpacing)); this.push(new CharacterSpacing(options.characterSpacing));
} }
if (options.emboss) {
this.push(new Emboss());
}
if (options.imprint) {
this.push(new Imprint());
}
const shading = options.shading || options.shadow; const shading = options.shading || options.shadow;
if (shading) { if (shading) {
this.push(new Shading(shading.type, shading.fill, shading.color)); this.push(new Shading(shading.type, shading.fill, shading.color));

View File

@ -146,7 +146,7 @@ describe("Run", () => {
}); });
describe("#doubleStrike()", () => { describe("#doubleStrike()", () => {
it("it should add caps to the properties", () => { it("it should add double strike to the properties", () => {
const run = new Run({ const run = new Run({
doubleStrike: true, doubleStrike: true,
}); });
@ -157,6 +157,30 @@ describe("Run", () => {
}); });
}); });
describe("#emboss()", () => {
it("it should add emboss to the properties", () => {
const run = new Run({
emboss: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:emboss": { _attr: { "w:val": true } } }] }],
});
});
});
describe("#imprint()", () => {
it("it should add imprint to the properties", () => {
const run = new Run({
imprint: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:imprint": { _attr: { "w:val": true } } }] }],
});
});
});
describe("#subScript()", () => { describe("#subScript()", () => {
it("it should add subScript to the properties", () => { it("it should add subScript to the properties", () => {
const run = new Run({ const run = new Run({