Merge branch 'master' of github.com:dolanmiu/docx into Numbering
# Conflicts: # src/file/paragraph/run/run.ts
This commit is contained in:
@ -1,19 +1,17 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { ShadingType } from "file/table";
|
||||
|
||||
import { Run } from "./";
|
||||
import { UnderlineType } from "./underline";
|
||||
|
||||
describe("Run", () => {
|
||||
let run: Run;
|
||||
|
||||
beforeEach(() => {
|
||||
run = new Run();
|
||||
});
|
||||
|
||||
describe("#bold()", () => {
|
||||
it("it should add bold to the properties", () => {
|
||||
run.bold();
|
||||
const run = new Run({
|
||||
bold: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
@ -36,7 +34,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#italics()", () => {
|
||||
it("it should add italics to the properties", () => {
|
||||
run.italics();
|
||||
const run = new Run({
|
||||
italics: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
@ -59,7 +59,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#underline()", () => {
|
||||
it("should default to 'single' and no color", () => {
|
||||
run.underline();
|
||||
const run = new Run({
|
||||
underline: {},
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }] }],
|
||||
@ -67,7 +69,12 @@ describe("Run", () => {
|
||||
});
|
||||
|
||||
it("should set the style type and color if given", () => {
|
||||
run.underline("double", "990011");
|
||||
const run = new Run({
|
||||
underline: {
|
||||
type: UnderlineType.DOUBLE,
|
||||
color: "990011",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "990011" } } }] }],
|
||||
@ -77,7 +84,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#smallCaps()", () => {
|
||||
it("it should add smallCaps to the properties", () => {
|
||||
run.smallCaps();
|
||||
const run = new Run({
|
||||
smallCaps: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
|
||||
@ -87,7 +96,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#caps()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.allCaps();
|
||||
const run = new Run({
|
||||
allCaps: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
|
||||
@ -97,7 +108,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#strike()", () => {
|
||||
it("it should add strike to the properties", () => {
|
||||
run.strike();
|
||||
const run = new Run({
|
||||
strike: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
|
||||
@ -107,7 +120,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#doubleStrike()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.doubleStrike();
|
||||
const run = new Run({
|
||||
doubleStrike: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
|
||||
@ -115,8 +130,65 @@ describe("Run", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#highlight()", () => {
|
||||
it("it should add highlight to the properties", () => {
|
||||
const run = new Run({
|
||||
highlight: "005599",
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:highlight": { _attr: { "w:val": "005599" } } },
|
||||
{
|
||||
"w:highlightCs": {
|
||||
_attr: {
|
||||
"w:val": "005599",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#shadow()", () => {
|
||||
it("it should add shadow to the properties", () => {
|
||||
const run = new Run({
|
||||
shading: {
|
||||
type: ShadingType.PERCENT_10,
|
||||
fill: "00FFFF",
|
||||
color: "FF0000",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
|
||||
{
|
||||
"w:shdCs": {
|
||||
_attr: {
|
||||
"w:val": "pct10",
|
||||
"w:fill": "00FFFF",
|
||||
"w:color": "FF0000",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#break()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
const run = new Run({});
|
||||
run.break();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -127,6 +199,7 @@ describe("Run", () => {
|
||||
|
||||
describe("#tab()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
const run = new Run({});
|
||||
run.tab();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -136,12 +209,12 @@ describe("Run", () => {
|
||||
});
|
||||
|
||||
describe("#font()", () => {
|
||||
it("should allow chaining calls", () => {
|
||||
expect(run.font("Times")).to.equal(run);
|
||||
});
|
||||
|
||||
it("should set the font as named", () => {
|
||||
run.font("Times");
|
||||
const run = new Run({
|
||||
font: {
|
||||
name: "Times",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
@ -157,7 +230,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#color", () => {
|
||||
it("should set the run to the color given", () => {
|
||||
run.color("001122");
|
||||
const run = new Run({
|
||||
color: "001122",
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:color": { _attr: { "w:val": "001122" } } }] }],
|
||||
@ -167,7 +242,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#size", () => {
|
||||
it("should set the run to the given size", () => {
|
||||
run.size(24);
|
||||
const run = new Run({
|
||||
size: 24,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
@ -181,7 +258,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#rtl", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
run.rightToLeft();
|
||||
const run = new Run({
|
||||
rightToLeft: true,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:rtl": { _attr: { "w:val": true } } }] }],
|
||||
@ -191,6 +270,7 @@ describe("Run", () => {
|
||||
|
||||
describe("#numberOfTotalPages", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
const run = new Run({});
|
||||
run.numberOfTotalPages();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -221,6 +301,7 @@ describe("Run", () => {
|
||||
|
||||
describe("#pageNumber", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
const run = new Run({});
|
||||
run.pageNumber();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -236,7 +317,9 @@ describe("Run", () => {
|
||||
|
||||
describe("#style", () => {
|
||||
it("should set the style to the given styleId", () => {
|
||||
run.style("myRunStyle");
|
||||
const run = new Run({
|
||||
style: "myRunStyle",
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "myRunStyle" } } }] }],
|
||||
|
Reference in New Issue
Block a user