import: add support to import any xml tab element to XmlComponent (#8)
- make method to import/convert to XmlComponent - expose method to add childElement to Header/Footer - add tests
This commit is contained in:
@ -1,5 +1,52 @@
|
||||
import { expect } from "chai";
|
||||
import { ImportedXmlComponent } from "./";
|
||||
import { ImportedXmlComponent, convertToXmlComponent } from "./";
|
||||
|
||||
const xmlString = `
|
||||
<w:p w:one="value 1" w:two="value 2">
|
||||
<w:rPr>
|
||||
<w:noProof>some value</w:noProof>
|
||||
</w:rPr>
|
||||
<w:r active="true">
|
||||
<w:t>Text 1</w:t>
|
||||
</w:r>
|
||||
<w:r active="true">
|
||||
<w:t>Text 2</w:t>
|
||||
</w:r>
|
||||
</w:p>
|
||||
`;
|
||||
|
||||
const importedXmlElement = {
|
||||
"w:p": {
|
||||
_attr: { "w:one": "value 1", "w:two": "value 2" },
|
||||
"w:rPr": { "w:noProof": "some value" },
|
||||
"w:r": [{ _attr: { active: "true" }, "w:t": "Text 1" }, { _attr: { active: "true" }, "w:t": "Text 2" }],
|
||||
},
|
||||
};
|
||||
|
||||
const convertedXmlElement = {
|
||||
deleted: false,
|
||||
rootKey: "w:p",
|
||||
root: [
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:rPr",
|
||||
root: [{ deleted: false, rootKey: "w:noProof", root: ["some value"] }],
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:r",
|
||||
root: [{ deleted: false, rootKey: "w:t", root: ["Text 1"] }],
|
||||
_attr: { active: "true" },
|
||||
},
|
||||
{
|
||||
deleted: false,
|
||||
rootKey: "w:r",
|
||||
root: [{ deleted: false, rootKey: "w:t", root: ["Text 2"] }],
|
||||
_attr: { active: "true" },
|
||||
},
|
||||
],
|
||||
_attr: { "w:one": "value 1", "w:two": "value 2" },
|
||||
};
|
||||
|
||||
describe("ImportedXmlComponent", () => {
|
||||
let importedXmlComponent: ImportedXmlComponent;
|
||||
@ -31,4 +78,16 @@ describe("ImportedXmlComponent", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should create XmlComponent from xml string", () => {
|
||||
const converted = ImportedXmlComponent.fromXmlString(xmlString);
|
||||
expect(converted).to.eql(convertedXmlElement);
|
||||
});
|
||||
|
||||
describe("convertToXmlComponent", () => {
|
||||
it("should convert to xml component", () => {
|
||||
const converted = convertToXmlComponent("w:p", importedXmlElement["w:p"]);
|
||||
expect(converted).to.eql(convertedXmlElement);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user