Files
docx-js/src/patcher/util.spec.ts

51 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-03-14 03:13:23 +00:00
import { expect } from "chai";
import { createTextElementContents, getFirstLevelElements, patchSpaceAttribute, toJson } from "./util";
describe("util", () => {
describe("toJson", () => {
it("should return an Element", () => {
const output = toJson("<xml></xml>");
expect(output).to.be.an("object");
});
});
describe("createTextElementContents", () => {
it("should return an array of elements", () => {
const output = createTextElementContents("hello");
expect(output).to.deep.equal([{ type: "text", text: "hello" }]);
});
});
describe("patchSpaceAttribute", () => {
it("should return an element with the xml:space attribute", () => {
const output = patchSpaceAttribute({ type: "element", name: "xml" });
expect(output).to.deep.equal({
type: "element",
name: "xml",
attributes: {
"xml:space": "preserve",
},
});
});
});
describe("getFirstLevelElements", () => {
it("should return an empty array if no elements are found", () => {
2023-03-15 02:46:39 +00:00
const elements = getFirstLevelElements(
{ elements: [{ type: "element", name: "Relationships", elements: [] }] },
"Relationships",
);
2023-03-14 03:13:23 +00:00
expect(elements).to.deep.equal([]);
});
it("should return an array if elements are found", () => {
2023-03-15 02:46:39 +00:00
const elements = getFirstLevelElements(
{ elements: [{ type: "element", name: "Relationships", elements: [{ type: "element", name: "Relationship" }] }] },
"Relationships",
);
2023-03-14 03:13:23 +00:00
expect(elements).to.deep.equal([{ type: "element", name: "Relationship" }]);
});
});
});