Merge pull request #242 from dolanmiu/feat/more-tests2
Add more tests to paragraph
This commit is contained in:
@ -18,9 +18,9 @@ class SpacingAttributes extends XmlAttributeComponent<ISpacingProperties> {
|
||||
}
|
||||
|
||||
export class Spacing extends XmlComponent {
|
||||
constructor(opts: ISpacingProperties) {
|
||||
constructor(options: ISpacingProperties) {
|
||||
super("w:spacing");
|
||||
this.root.push(new SpacingAttributes(opts));
|
||||
this.root.push(new SpacingAttributes(options));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import { Formatter } from "export/formatter";
|
||||
import * as file from "file";
|
||||
|
||||
import { Numbering } from "../numbering";
|
||||
import { LeaderType } from "./formatting";
|
||||
|
||||
describe("Paragraph", () => {
|
||||
let paragraph: file.Paragraph;
|
||||
@ -86,6 +87,48 @@ describe("Paragraph", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading4()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading4();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading4" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading5()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading5();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading5" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#heading6()", () => {
|
||||
it("should add heading style to JSON", () => {
|
||||
paragraph.heading6();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading6" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#title()", () => {
|
||||
it("should add title style to JSON", () => {
|
||||
paragraph.title();
|
||||
@ -114,6 +157,235 @@ describe("Paragraph", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#left()", () => {
|
||||
it("should add left alignment to JSON", () => {
|
||||
paragraph.left();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#right()", () => {
|
||||
it("should add right alignment to JSON", () => {
|
||||
paragraph.right();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#start()", () => {
|
||||
it("should add start alignment to JSON", () => {
|
||||
paragraph.start();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "start" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#end()", () => {
|
||||
it("should add end alignment to JSON", () => {
|
||||
paragraph.end();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "end" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#distribute()", () => {
|
||||
it("should add distribute alignment to JSON", () => {
|
||||
paragraph.distribute();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "distribute" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#justified()", () => {
|
||||
it("should add justified alignment to JSON", () => {
|
||||
paragraph.justified();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#maxRightTabStop()", () => {
|
||||
it("should add maxRightTabStop to JSON", () => {
|
||||
paragraph.maxRightTabStop();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 9026,
|
||||
"w:val": "right",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#leftTabStop()", () => {
|
||||
it("should add leftTabStop to JSON", () => {
|
||||
paragraph.leftTabStop(100, LeaderType.HYPHEN);
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "left",
|
||||
"w:leader": "hyphen",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#rightTabStop()", () => {
|
||||
it("should add rightTabStop to JSON", () => {
|
||||
paragraph.rightTabStop(100, LeaderType.DOT);
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "right",
|
||||
"w:leader": "dot",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#centerTabStop()", () => {
|
||||
it("should add centerTabStop to JSON", () => {
|
||||
paragraph.centerTabStop(100, LeaderType.MIDDLE_DOT);
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "center",
|
||||
"w:leader": "middleDot",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#contextualSpacing()", () => {
|
||||
it("should add contextualSpacing to JSON, and set 1 if true", () => {
|
||||
paragraph.contextualSpacing(true);
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 1 } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should add contextualSpacing to JSON, and set 0 if false", () => {
|
||||
paragraph.contextualSpacing(false);
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 0 } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#thematicBreak()", () => {
|
||||
it("should add thematic break to JSON", () => {
|
||||
paragraph.thematicBreak();
|
||||
|
@ -241,11 +241,6 @@ export class Paragraph extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public addTabStop(run: Run): Paragraph {
|
||||
this.root.splice(1, 0, run);
|
||||
return this;
|
||||
}
|
||||
|
||||
public addSequentialIdentifier(identifier: string): Paragraph {
|
||||
this.root.push(new SequentialIdentifier(identifier));
|
||||
return this;
|
||||
|
Reference in New Issue
Block a user