2019-06-26 22:12:18 +01:00
|
|
|
import { expect } from "chai";
|
2017-09-17 00:00:41 +01:00
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
|
2017-09-17 00:00:41 +01:00
|
|
|
import { Run } from "./";
|
2016-03-30 03:58:53 +01:00
|
|
|
|
2016-07-13 00:59:53 +01:00
|
|
|
describe("Run", () => {
|
2016-05-26 15:08:34 +01:00
|
|
|
let run: Run;
|
2016-03-30 03:58:53 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
run = new Run();
|
|
|
|
});
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
describe("#bold()", () => {
|
2016-03-30 04:43:56 +01:00
|
|
|
it("it should add bold to the properties", () => {
|
|
|
|
run.bold();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [
|
|
|
|
{
|
|
|
|
"w:rPr": [
|
|
|
|
{ "w:b": { _attr: { "w:val": true } } },
|
|
|
|
{
|
|
|
|
"w:bCs": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-30 04:43:56 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 03:58:53 +01:00
|
|
|
|
2018-11-18 15:22:23 +00:00
|
|
|
describe("#italics()", () => {
|
2016-03-30 04:43:56 +01:00
|
|
|
it("it should add italics to the properties", () => {
|
2018-11-18 15:22:23 +00:00
|
|
|
run.italics();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [
|
|
|
|
{
|
|
|
|
"w:rPr": [
|
|
|
|
{ "w:i": { _attr: { "w:val": true } } },
|
|
|
|
{
|
|
|
|
"w:iCs": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-03-30 04:43:56 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
describe("#underline()", () => {
|
2017-03-12 17:28:52 +01:00
|
|
|
it("should default to 'single' and no color", () => {
|
|
|
|
run.underline();
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }] }],
|
2017-03-12 17:28:52 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set the style type and color if given", () => {
|
|
|
|
run.underline("double", "990011");
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "990011" } } }] }],
|
2017-03-12 17:28:52 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 03:58:53 +01:00
|
|
|
});
|
|
|
|
|
2016-07-12 08:46:26 +01:00
|
|
|
describe("#smallCaps()", () => {
|
|
|
|
it("it should add smallCaps to the properties", () => {
|
|
|
|
run.smallCaps();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
|
|
|
|
});
|
2016-07-12 08:46:26 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#caps()", () => {
|
|
|
|
it("it should add caps to the properties", () => {
|
|
|
|
run.allCaps();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
|
|
|
|
});
|
2016-07-12 08:46:26 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#strike()", () => {
|
|
|
|
it("it should add strike to the properties", () => {
|
|
|
|
run.strike();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
|
|
|
|
});
|
2016-07-12 08:46:26 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 03:58:53 +01:00
|
|
|
|
2016-07-12 08:46:26 +01:00
|
|
|
describe("#doubleStrike()", () => {
|
|
|
|
it("it should add caps to the properties", () => {
|
|
|
|
run.doubleStrike();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
|
|
|
|
});
|
2016-07-12 08:46:26 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#break()", () => {
|
|
|
|
it("it should add break to the run", () => {
|
|
|
|
run.break();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:br": {} }],
|
|
|
|
});
|
2016-07-12 08:46:26 +01:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 03:58:53 +01:00
|
|
|
|
2016-07-12 08:46:26 +01:00
|
|
|
describe("#tab()", () => {
|
|
|
|
it("it should add break to the run", () => {
|
|
|
|
run.tab();
|
2019-06-26 22:12:18 +01:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [{ "w:tab": {} }],
|
|
|
|
});
|
2016-03-30 03:58:53 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-08 20:29:12 +01:00
|
|
|
|
|
|
|
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 tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2018-07-24 12:37:15 +08:00
|
|
|
"w:r": [
|
|
|
|
{
|
|
|
|
"w:rPr": [
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
2018-07-24 12:37:15 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2017-03-08 20:29:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-12 17:31:36 +01:00
|
|
|
|
|
|
|
describe("#color", () => {
|
|
|
|
it("should set the run to the color given", () => {
|
|
|
|
run.color("001122");
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:rPr": [{ "w:color": { _attr: { "w:val": "001122" } } }] }],
|
2017-03-12 17:31:36 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#size", () => {
|
|
|
|
it("should set the run to the given size", () => {
|
|
|
|
run.size(24);
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2018-07-25 15:02:58 +03:00
|
|
|
"w:r": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
|
2018-07-25 15:02:58 +03:00
|
|
|
},
|
|
|
|
],
|
2017-03-12 17:31:36 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-12 17:35:15 +01:00
|
|
|
|
2018-07-24 18:52:45 +03:00
|
|
|
describe("#rtl", () => {
|
|
|
|
it("should set the run to the RTL mode", () => {
|
2018-08-07 02:47:24 +01:00
|
|
|
run.rightToLeft();
|
2018-07-24 18:52:45 +03:00
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:rPr": [{ "w:rtl": { _attr: { "w:val": true } } }] }],
|
2018-07-24 18:52:45 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-15 21:40:19 +00:00
|
|
|
describe("#numberOfTotalPages", () => {
|
|
|
|
it("should set the run to the RTL mode", () => {
|
|
|
|
run.numberOfTotalPages();
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
2019-01-15 21:40:19 +00:00
|
|
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] },
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
2019-01-15 21:40:19 +00:00
|
|
|
],
|
2019-08-09 11:56:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#numberOfTotalPagesSection", () => {
|
|
|
|
it("should set the run to the RTL mode", () => {
|
|
|
|
run.numberOfTotalPagesSection();
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [
|
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
|
|
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTIONPAGES"] },
|
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
|
|
|
],
|
2019-01-15 21:40:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#pageNumber", () => {
|
|
|
|
it("should set the run to the RTL mode", () => {
|
|
|
|
run.pageNumber();
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:r": [
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
2019-01-15 21:40:19 +00:00
|
|
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] },
|
2019-04-09 05:27:18 -04:00
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
|
|
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
2019-01-15 21:40:19 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-12 17:35:15 +01:00
|
|
|
describe("#style", () => {
|
|
|
|
it("should set the style to the given styleId", () => {
|
|
|
|
run.style("myRunStyle");
|
|
|
|
const tree = new Formatter().format(run);
|
|
|
|
expect(tree).to.deep.equal({
|
2019-04-09 05:27:18 -04:00
|
|
|
"w:r": [{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "myRunStyle" } } }] }],
|
2017-03-12 17:35:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-08 20:28:59 +01:00
|
|
|
});
|