2023-06-05 00:33:43 +01:00
|
|
|
import { describe, expect, it } from "vitest";
|
2021-03-12 03:58:05 +00:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { Formatter } from "@export/formatter";
|
2021-03-12 03:58:05 +00:00
|
|
|
import { DocumentWrapper } from "../document-wrapper";
|
|
|
|
import { File } from "../file";
|
|
|
|
|
|
|
|
import { ParagraphProperties } from "./properties";
|
|
|
|
|
|
|
|
describe("ParagraphProperties", () => {
|
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("creates an initially empty property object", () => {
|
|
|
|
const properties = new ParagraphProperties();
|
|
|
|
|
|
|
|
expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly");
|
|
|
|
});
|
|
|
|
|
2021-03-13 04:07:44 +00:00
|
|
|
it("should create with numbering", () => {
|
2021-03-12 03:58:05 +00:00
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
numbering: {
|
|
|
|
reference: "test-reference",
|
|
|
|
level: 0,
|
|
|
|
instance: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties, {
|
|
|
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
|
|
|
file: {
|
|
|
|
Numbering: {
|
2022-09-15 20:00:50 +01:00
|
|
|
createConcreteNumberingInstance: (_: string, __: number) => undefined,
|
2021-03-12 03:58:05 +00:00
|
|
|
},
|
|
|
|
} as File,
|
|
|
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
|
|
|
viewWrapper: new DocumentWrapper({ background: {} }),
|
2022-12-26 15:12:44 +00:00
|
|
|
stack: [],
|
2021-03-12 03:58:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:pStyle": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "ListParagraph",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"w:numPr": [
|
|
|
|
{
|
|
|
|
"w:ilvl": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"w:numId": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "{test-reference-0}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2021-03-13 04:07:44 +00:00
|
|
|
|
|
|
|
it("should create with widowControl", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
widowControl: true,
|
|
|
|
});
|
2021-12-02 17:27:00 +00:00
|
|
|
const tree = new Formatter().format(properties);
|
2021-03-13 04:07:44 +00:00
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
2021-05-24 11:28:10 +03:00
|
|
|
"w:widowControl": {},
|
2021-03-13 04:07:44 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2021-12-02 17:24:19 +00:00
|
|
|
|
2021-12-02 17:27:00 +00:00
|
|
|
it("should create with the bidirectional property", () => {
|
2021-12-02 17:24:19 +00:00
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
bidirectional: true,
|
|
|
|
});
|
2021-12-02 17:27:00 +00:00
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:bidi": {},
|
2021-12-02 17:24:19 +00:00
|
|
|
},
|
2021-12-02 17:27:00 +00:00
|
|
|
],
|
2021-12-02 17:24:19 +00:00
|
|
|
});
|
2021-12-02 17:27:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should create with the contextualSpacing property", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
contextualSpacing: true,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
2021-12-02 17:24:19 +00:00
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
2021-12-02 17:27:00 +00:00
|
|
|
"w:contextualSpacing": {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create with the suppressLineNumbers property", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
suppressLineNumbers: true,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:suppressLineNumbers": {},
|
2021-12-02 17:24:19 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2022-10-25 18:53:00 +01:00
|
|
|
|
2023-03-17 02:20:51 +00:00
|
|
|
it("should create with the autoSpaceEastAsianText property", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
autoSpaceEastAsianText: true,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:autoSpaceDN": {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-25 18:53:00 +01:00
|
|
|
it("should create with the wordWrap property", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
wordWrap: true,
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:wordWrap": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2023-12-22 09:21:12 +08:00
|
|
|
|
|
|
|
it("should create with the run property", () => {
|
|
|
|
const properties = new ParagraphProperties({
|
|
|
|
run: {
|
|
|
|
size: "10pt",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:pPr": [
|
|
|
|
{
|
|
|
|
"w:rPr": [
|
|
|
|
{
|
|
|
|
"w:sz": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "10pt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"w:szCs": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "10pt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2021-03-12 03:58:05 +00:00
|
|
|
});
|
|
|
|
});
|