Add tests
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
import { Paragraph, TextRun } from "file/paragraph";
|
||||||
|
|
||||||
import { Footnote, FootnoteType } from "./footnote";
|
import { Footnote, FootnoteType } from "./footnote";
|
||||||
|
|
||||||
@ -28,5 +29,134 @@ describe("Footnote", () => {
|
|||||||
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
||||||
expect(tree["w:footnote"]).to.deep.equal({ _attr: { "w:id": 1 } });
|
expect(tree["w:footnote"]).to.deep.equal({ _attr: { "w:id": 1 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should append footnote ref run on the first footnote paragraph", () => {
|
||||||
|
const footnote = new Footnote({
|
||||||
|
id: 1,
|
||||||
|
children: [new Paragraph({ children: [new TextRun("test-footnote")] })],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(footnote);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:footnote": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:id": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:p": [
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:rStyle": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "FootnoteReference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:footnoteRef": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:t": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xml:space": "preserve",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test-footnote",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add multiple paragraphs", () => {
|
||||||
|
const footnote = new Footnote({
|
||||||
|
id: 1,
|
||||||
|
children: [
|
||||||
|
new Paragraph({ children: [new TextRun("test-footnote")] }),
|
||||||
|
new Paragraph({ children: [new TextRun("test-footnote-2")] }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(footnote);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:footnote": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:id": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:p": [
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:rStyle": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "FootnoteReference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:footnoteRef": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:t": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xml:space": "preserve",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test-footnote",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:p": [
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:t": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xml:space": "preserve",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test-footnote-2",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -618,6 +618,28 @@ describe("Paragraph", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not add ListParagraph style when custom is true", () => {
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
numbering: {
|
||||||
|
reference: "test id",
|
||||||
|
level: 0,
|
||||||
|
custom: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(paragraph);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:p": [
|
||||||
|
{
|
||||||
|
"w:pPr": [
|
||||||
|
{
|
||||||
|
"w:numPr": [{ "w:ilvl": { _attr: { "w:val": 0 } } }, { "w:numId": { _attr: { "w:val": "{test id}" } } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("it should add bookmark", () => {
|
it("it should add bookmark", () => {
|
||||||
|
Reference in New Issue
Block a user