2017-03-09 12:25:59 +01:00
|
|
|
import { assert, expect } from "chai";
|
2017-09-17 00:00:41 +01:00
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
import * as file from "file";
|
|
|
|
|
2017-12-20 00:01:23 +00:00
|
|
|
import { Numbering } from "../numbering";
|
2019-01-11 00:16:25 +00:00
|
|
|
import { LeaderType } from "./formatting";
|
2016-03-30 03:58:53 +01:00
|
|
|
|
2016-04-03 05:24:56 +01:00
|
|
|
describe("Paragraph", () => {
|
2017-12-20 01:03:20 +00:00
|
|
|
let paragraph: file.Paragraph;
|
2016-03-29 04:10:33 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-12-20 01:03:20 +00:00
|
|
|
paragraph = new file.Paragraph();
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
describe("#constructor()", () => {
|
2016-03-29 04:10:33 +01:00
|
|
|
it("should create valid JSON", () => {
|
2017-03-09 12:25:59 +01:00
|
|
|
const stringifiedJson = JSON.stringify(paragraph);
|
2016-03-29 04:10:33 +01:00
|
|
|
|
|
|
|
try {
|
2018-01-31 23:24:55 +00:00
|
|
|
JSON.parse(stringifiedJson);
|
2016-03-29 04:10:33 +01:00
|
|
|
} catch (e) {
|
|
|
|
assert.isTrue(false);
|
|
|
|
}
|
|
|
|
assert.isTrue(true);
|
|
|
|
});
|
2016-05-09 13:12:28 +01:00
|
|
|
|
|
|
|
it("should create have valid properties", () => {
|
2017-03-09 12:25:59 +01:00
|
|
|
const stringifiedJson = JSON.stringify(paragraph);
|
|
|
|
const newJson = JSON.parse(stringifiedJson);
|
2016-05-09 21:50:46 +01:00
|
|
|
assert.equal(newJson.root[0].rootKey, "w:pPr");
|
2016-05-09 13:12:28 +01:00
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
2017-03-10 14:35:37 +01:00
|
|
|
|
2017-03-10 14:44:25 +01:00
|
|
|
describe("#createTextRun", () => {
|
2017-03-10 14:35:37 +01:00
|
|
|
it("should add a new run to the paragraph and return it", () => {
|
2017-03-10 14:44:25 +01:00
|
|
|
const run = paragraph.createTextRun("this is a test run");
|
2017-12-20 01:03:20 +00:00
|
|
|
expect(run).to.be.instanceof(file.TextRun);
|
2017-03-10 14:35:37 +01:00
|
|
|
const tree = new Formatter().format(paragraph)["w:p"];
|
2018-01-23 01:33:12 +00:00
|
|
|
expect(tree)
|
|
|
|
.to.be.an("array")
|
|
|
|
.which.includes({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
|
2018-01-23 01:33:12 +00:00
|
|
|
});
|
2017-03-10 14:35:37 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
|
|
|
|
describe("#heading1()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading1();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading1" } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#heading2()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading2();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading2" } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#heading3()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading3();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading3" } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-11 00:16:25 +00:00
|
|
|
describe("#heading4()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading4();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading4" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#heading5()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading5();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading5" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#heading6()", () => {
|
|
|
|
it("should add heading style to JSON", () => {
|
|
|
|
paragraph.heading6();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading6" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-29 04:10:33 +01:00
|
|
|
describe("#title()", () => {
|
|
|
|
it("should add title style to JSON", () => {
|
|
|
|
paragraph.title();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Title" } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-29 04:10:33 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-29 04:50:23 +01:00
|
|
|
|
|
|
|
describe("#center()", () => {
|
|
|
|
it("should add center alignment to JSON", () => {
|
|
|
|
paragraph.center();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "center" } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-29 04:50:23 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-29 05:01:33 +01:00
|
|
|
|
2019-01-11 00:16:25 +00:00
|
|
|
describe("#left()", () => {
|
|
|
|
it("should add left alignment to JSON", () => {
|
|
|
|
paragraph.left();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "left" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#right()", () => {
|
|
|
|
it("should add right alignment to JSON", () => {
|
|
|
|
paragraph.right();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "right" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#start()", () => {
|
|
|
|
it("should add start alignment to JSON", () => {
|
|
|
|
paragraph.start();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "start" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#end()", () => {
|
|
|
|
it("should add end alignment to JSON", () => {
|
|
|
|
paragraph.end();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "end" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#distribute()", () => {
|
|
|
|
it("should add distribute alignment to JSON", () => {
|
|
|
|
paragraph.distribute();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "distribute" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#justified()", () => {
|
|
|
|
it("should add justified alignment to JSON", () => {
|
|
|
|
paragraph.justified();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "both" } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tab": {
|
|
|
|
_attr: {
|
|
|
|
"w:pos": 9026,
|
|
|
|
"w:val": "right",
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tab": {
|
|
|
|
_attr: {
|
|
|
|
"w:pos": 100,
|
|
|
|
"w:val": "left",
|
|
|
|
"w:leader": "hyphen",
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tab": {
|
|
|
|
_attr: {
|
|
|
|
"w:pos": 100,
|
|
|
|
"w:val": "right",
|
|
|
|
"w:leader": "dot",
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:tab": {
|
|
|
|
_attr: {
|
|
|
|
"w:pos": 100,
|
|
|
|
"w:val": "center",
|
|
|
|
"w:leader": "middleDot",
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 1 } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 0 } } }],
|
2019-01-11 00:16:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:36:57 +01:00
|
|
|
describe("#thematicBreak()", () => {
|
2016-03-29 05:01:33 +01:00
|
|
|
it("should add thematic break to JSON", () => {
|
2016-03-29 23:36:57 +01:00
|
|
|
paragraph.thematicBreak();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
2018-01-23 01:33:12 +00:00
|
|
|
"w:p": [
|
|
|
|
{
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:pBdr": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:bottom": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "single",
|
|
|
|
"w:color": "auto",
|
|
|
|
"w:space": "1",
|
|
|
|
"w:sz": "6",
|
2018-01-23 01:33:12 +00:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-01-23 01:33:12 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2017-03-10 10:32:40 +01:00
|
|
|
});
|
2016-03-29 05:01:33 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 00:28:05 +01:00
|
|
|
|
2018-08-19 19:37:36 -04:00
|
|
|
describe("#paragraphBorders()", () => {
|
|
|
|
it("should add a left and right border to a paragraph", () => {
|
|
|
|
paragraph.createBorder();
|
|
|
|
paragraph.Borders.addLeftBorder();
|
|
|
|
paragraph.Borders.addRightBorder();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:pBdr": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:left": {
|
|
|
|
_attr: {
|
|
|
|
"w:color": "auto",
|
|
|
|
"w:space": "1",
|
|
|
|
"w:sz": "6",
|
|
|
|
"w:val": "single",
|
2018-08-19 19:37:36 -04:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-19 19:37:36 -04:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:right": {
|
|
|
|
_attr: {
|
|
|
|
"w:color": "auto",
|
|
|
|
"w:space": "1",
|
|
|
|
"w:sz": "6",
|
|
|
|
"w:val": "single",
|
2018-08-19 19:37:36 -04:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-19 19:37:36 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-30 00:28:05 +01:00
|
|
|
describe("#pageBreak()", () => {
|
|
|
|
it("should add page break to JSON", () => {
|
|
|
|
paragraph.pageBreak();
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
2018-01-23 01:33:12 +00:00
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:br": { _attr: { "w:type": "page" } } }],
|
2018-01-23 01:33:12 +00:00
|
|
|
},
|
|
|
|
],
|
2017-03-10 10:32:40 +01:00
|
|
|
});
|
2016-03-30 00:28:05 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 02:55:11 +01:00
|
|
|
|
2018-05-10 19:43:58 +02:00
|
|
|
describe("#pageBreakBefore()", () => {
|
|
|
|
it("should add page break before to JSON", () => {
|
|
|
|
paragraph.pageBreakBefore();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2018-05-17 15:34:47 +02:00
|
|
|
"w:pPr": [
|
|
|
|
{
|
2019-04-10 01:28:37 -04:00
|
|
|
"w:pageBreakBefore": {},
|
2018-05-17 15:34:47 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-05-10 19:43:58 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-30 02:55:11 +01:00
|
|
|
describe("#bullet()", () => {
|
2018-04-10 21:54:52 +01:00
|
|
|
it("should default to 0 indent level if no bullet was specified", () => {
|
|
|
|
paragraph.bullet();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree)
|
|
|
|
.to.have.property("w:p")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
|
|
|
expect(tree["w:p"][0])
|
|
|
|
.to.have.property("w:pPr")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
|
|
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
2018-04-10 21:54:52 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-30 02:55:11 +01:00
|
|
|
it("should add list paragraph style to JSON", () => {
|
2018-04-10 10:25:12 +03:00
|
|
|
paragraph.bullet(0);
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
2018-01-23 01:33:12 +00:00
|
|
|
expect(tree)
|
|
|
|
.to.have.property("w:p")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
|
|
|
expect(tree["w:p"][0])
|
|
|
|
.to.have.property("w:pPr")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
2017-03-10 10:32:40 +01:00
|
|
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
2017-03-10 10:32:40 +01:00
|
|
|
});
|
2016-03-30 02:55:11 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("it should add numbered properties", () => {
|
2018-04-10 10:25:12 +03:00
|
|
|
paragraph.bullet(1);
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
2018-01-23 01:33:12 +00:00
|
|
|
expect(tree)
|
|
|
|
.to.have.property("w:p")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
|
|
|
expect(tree["w:p"][0])
|
|
|
|
.to.have.property("w:pPr")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(2);
|
2017-03-10 10:32:40 +01:00
|
|
|
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:numPr": [{ "w:ilvl": { _attr: { "w:val": 1 } } }, { "w:numId": { _attr: { "w:val": 1 } } }],
|
2017-03-10 10:32:40 +01:00
|
|
|
});
|
2016-03-30 02:55:11 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-08 18:23:00 +01:00
|
|
|
|
|
|
|
describe("#setNumbering", () => {
|
|
|
|
it("should add list paragraph style to JSON", () => {
|
|
|
|
const numbering = new Numbering();
|
|
|
|
const numberedAbstract = numbering.createAbstractNumbering();
|
|
|
|
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
|
|
|
|
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
|
|
|
|
|
|
|
|
paragraph.setNumbering(letterNumbering, 0);
|
2017-03-10 10:32:40 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
2018-01-23 01:33:12 +00:00
|
|
|
expect(tree)
|
|
|
|
.to.have.property("w:p")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
|
|
|
expect(tree["w:p"][0])
|
|
|
|
.to.have.property("w:pPr")
|
|
|
|
.which.is.an("array")
|
|
|
|
.which.has.length.at.least(1);
|
2017-03-10 10:32:40 +01:00
|
|
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
2017-03-10 10:32:40 +01:00
|
|
|
});
|
2017-03-08 18:23:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("it should add numbered properties", () => {
|
|
|
|
const numbering = new Numbering();
|
|
|
|
const numberedAbstract = numbering.createAbstractNumbering();
|
|
|
|
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
|
|
|
|
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
|
|
|
|
|
|
|
|
paragraph.setNumbering(letterNumbering, 0);
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
|
|
|
"w:pPr": [
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:pStyle": { _attr: { "w:val": "ListParagraph" } } },
|
2017-03-08 18:23:00 +01:00
|
|
|
{
|
|
|
|
"w:numPr": [
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:ilvl": { _attr: { "w:val": 0 } } },
|
|
|
|
{ "w:numId": { _attr: { "w:val": letterNumbering.id } } },
|
2017-03-09 12:25:59 +01:00
|
|
|
],
|
2017-03-08 18:23:00 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2017-03-09 12:25:59 +01:00
|
|
|
],
|
|
|
|
});
|
2017-03-08 18:23:00 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-09 09:18:17 +01:00
|
|
|
|
2017-03-09 09:46:12 +01:00
|
|
|
describe("#style", () => {
|
|
|
|
it("should set the paragraph style to the given styleId", () => {
|
2017-03-09 12:25:59 +01:00
|
|
|
paragraph.style("myFancyStyle");
|
2017-03-09 09:46:12 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "myFancyStyle" } } }],
|
2017-03-09 09:46:12 +01:00
|
|
|
},
|
2017-03-09 12:25:59 +01:00
|
|
|
],
|
|
|
|
});
|
2017-03-09 09:46:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-09 09:18:17 +01:00
|
|
|
describe("#indent", () => {
|
|
|
|
it("should set the paragraph indent to the given values", () => {
|
2017-09-16 12:31:31 -06:00
|
|
|
paragraph.indent({ left: 720 });
|
2017-03-09 09:18:17 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:ind": { _attr: { "w:left": 720 } } }],
|
2017-03-09 09:18:17 +01:00
|
|
|
},
|
2017-03-09 12:25:59 +01:00
|
|
|
],
|
|
|
|
});
|
2017-03-09 09:18:17 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-09 12:12:33 +01:00
|
|
|
|
|
|
|
describe("#spacing", () => {
|
|
|
|
it("should set the paragraph spacing to the given values", () => {
|
2018-01-23 01:33:12 +00:00
|
|
|
paragraph.spacing({ before: 90, line: 50 });
|
2017-03-09 12:12:33 +01:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:spacing": { _attr: { "w:before": 90, "w:line": 50 } } }],
|
2017-03-09 12:12:33 +01:00
|
|
|
},
|
2017-03-09 12:25:59 +01:00
|
|
|
],
|
|
|
|
});
|
2017-03-09 12:12:33 +01:00
|
|
|
});
|
|
|
|
});
|
2017-04-14 21:13:11 +02:00
|
|
|
|
|
|
|
describe("#keepLines", () => {
|
|
|
|
it("should set the paragraph keepLines sub-component", () => {
|
|
|
|
paragraph.keepLines();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-10 01:28:37 -04:00
|
|
|
"w:p": [{ "w:pPr": [{ "w:keepLines": {} }] }],
|
2017-04-14 21:13:11 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#keepNext", () => {
|
|
|
|
it("should set the paragraph keepNext sub-component", () => {
|
|
|
|
paragraph.keepNext();
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-10 01:28:37 -04:00
|
|
|
"w:p": [{ "w:pPr": [{ "w:keepNext": {} }] }],
|
2017-04-14 21:13:11 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-07-22 17:08:11 +03:00
|
|
|
|
2018-08-07 02:47:24 +01:00
|
|
|
describe("#bidirectional", () => {
|
2018-07-22 17:08:11 +03:00
|
|
|
it("set paragraph right to left layout", () => {
|
2018-08-07 02:47:24 +01:00
|
|
|
paragraph.bidirectional();
|
2018-07-22 17:08:11 +03:00
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-10 01:28:37 -04:00
|
|
|
"w:p": [{ "w:pPr": [{ "w:bidi": {} }] }],
|
2018-07-22 17:08:11 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-01-15 15:39:48 +01:00
|
|
|
|
|
|
|
describe("#outlineLevel", () => {
|
|
|
|
it("should set paragraph outline level to the given value", () => {
|
|
|
|
paragraph.outlineLevel("0");
|
|
|
|
const tree = new Formatter().format(paragraph);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": "0" } } }],
|
2019-01-15 15:39:48 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-08 18:23:00 +01:00
|
|
|
});
|