Add tests

This commit is contained in:
Dolan
2021-03-08 04:18:26 +00:00
parent 2d4a452d2e
commit a0d8911e18
2 changed files with 152 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { Paragraph, TextRun } from "file/paragraph";
import { Footnote, FootnoteType } from "./footnote";
@ -28,5 +29,134 @@ describe("Footnote", () => {
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
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",
],
},
],
},
],
},
],
});
});
});
});