2023-06-05 00:33:43 +01:00
|
|
|
import { describe, expect, it } from "vitest";
|
2017-09-17 00:00:41 +01:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { Formatter } from "@export/formatter";
|
2021-05-26 10:14:19 +03:00
|
|
|
import { Attributes, BaseXmlComponent, XmlComponent } from "./";
|
2016-07-17 16:03:31 +01:00
|
|
|
|
2021-05-26 10:14:19 +03:00
|
|
|
class TestComponent extends XmlComponent {
|
|
|
|
public push(el: BaseXmlComponent): void {
|
|
|
|
this.root.push(el);
|
|
|
|
}
|
|
|
|
}
|
2016-07-17 16:03:31 +01:00
|
|
|
|
2016-07-17 16:18:20 +01:00
|
|
|
describe("XmlComponent", () => {
|
2016-07-17 16:03:31 +01:00
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("should create an Xml Component which has the correct rootKey", () => {
|
2021-05-26 10:14:19 +03:00
|
|
|
const xmlComponent = new TestComponent("w:test");
|
2019-06-26 02:11:43 +01:00
|
|
|
const tree = new Formatter().format(xmlComponent);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:test": {},
|
|
|
|
});
|
2016-07-17 16:03:31 +01:00
|
|
|
});
|
2021-05-26 10:14:19 +03:00
|
|
|
it("should handle children elements", () => {
|
|
|
|
const xmlComponent = new TestComponent("w:test");
|
2023-11-01 22:52:41 +00:00
|
|
|
// eslint-disable-next-line functional/immutable-data
|
2021-05-26 10:14:19 +03:00
|
|
|
xmlComponent.push(
|
|
|
|
new Attributes({
|
|
|
|
val: "test",
|
|
|
|
}),
|
|
|
|
);
|
2023-11-01 22:52:41 +00:00
|
|
|
// eslint-disable-next-line functional/immutable-data
|
2021-05-26 10:14:19 +03:00
|
|
|
xmlComponent.push(new TestComponent("innerTest"));
|
|
|
|
|
|
|
|
const tree = new Formatter().format(xmlComponent);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:test": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"w:val": "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
innerTest: {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("should hoist attrs if only attrs are present", () => {
|
|
|
|
const xmlComponent = new TestComponent("w:test");
|
2023-11-01 22:52:41 +00:00
|
|
|
// eslint-disable-next-line functional/immutable-data
|
2021-05-26 10:14:19 +03:00
|
|
|
xmlComponent.push(
|
|
|
|
new Attributes({
|
|
|
|
val: "test",
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
const tree = new Formatter().format(xmlComponent);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:test": {
|
|
|
|
_attr: {
|
|
|
|
"w:val": "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2016-07-17 16:03:31 +01:00
|
|
|
});
|
2017-03-09 20:49:14 +01:00
|
|
|
});
|