Add tests
This commit is contained in:
101
src/patcher/paragraph-split-inject.spec.ts
Normal file
101
src/patcher/paragraph-split-inject.spec.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { findRunElementIndexWithToken, splitRunElement } from "./paragraph-split-inject";
|
||||
|
||||
describe("paragraph-split-inject", () => {
|
||||
describe("findRunElementIndexWithToken", () => {
|
||||
it("should find the index of a run element with a token", () => {
|
||||
const output = findRunElementIndexWithToken(
|
||||
{
|
||||
name: "w:p",
|
||||
type: "element",
|
||||
elements: [
|
||||
{
|
||||
name: "w:r",
|
||||
type: "element",
|
||||
elements: [
|
||||
{
|
||||
name: "w:t",
|
||||
type: "element",
|
||||
elements: [
|
||||
{
|
||||
type: "text",
|
||||
text: "hello world",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
"hello",
|
||||
);
|
||||
expect(output).to.deep.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitRunElement", () => {
|
||||
it("should split a run element", () => {
|
||||
const output = splitRunElement(
|
||||
{
|
||||
name: "w:r",
|
||||
type: "element",
|
||||
elements: [
|
||||
{
|
||||
name: "w:t",
|
||||
type: "element",
|
||||
elements: [
|
||||
{
|
||||
type: "text",
|
||||
text: "hello*world",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
"*",
|
||||
);
|
||||
|
||||
expect(output).to.deep.equal({
|
||||
left: {
|
||||
elements: [
|
||||
{
|
||||
attributes: {
|
||||
"xml:space": "preserve",
|
||||
},
|
||||
elements: [
|
||||
{
|
||||
text: "hello",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
name: "w:t",
|
||||
type: "element",
|
||||
},
|
||||
],
|
||||
name: "w:r",
|
||||
type: "element",
|
||||
},
|
||||
right: {
|
||||
elements: [
|
||||
{
|
||||
attributes: {
|
||||
"xml:space": "preserve",
|
||||
},
|
||||
elements: [
|
||||
{
|
||||
text: "world",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
name: "w:t",
|
||||
type: "element",
|
||||
},
|
||||
],
|
||||
name: "w:r",
|
||||
type: "element",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user