diff --git a/visualization/app/codeCharta/services/3DExports/generateXML/build3mfModelConfig.spec.ts b/visualization/app/codeCharta/services/3DExports/generateXML/build3mfModelConfig.spec.ts new file mode 100644 index 0000000000..2ed615294d --- /dev/null +++ b/visualization/app/codeCharta/services/3DExports/generateXML/build3mfModelConfig.spec.ts @@ -0,0 +1,34 @@ +import { XMLParser } from "fast-xml-parser" +import { Volume } from "../serialize3mf.service" +import { getXMLmodelConfig } from "./build3mfModelConfig" + +describe("build3mfModelConfig", () => { + it("should return a valid xml with properly defined volumes", () => { + const exampleVolumeList: Volume[] = [] + for (let index = 0; index < 5; index++) { + const aVolume: Volume = { + id: index, + name: "", + color: "", + extruder: index, + firstTriangleId: index * 10, + lastTriangleId: index * 10 + 9 + } + exampleVolumeList[index] = aVolume + } + + const xmlContent = getXMLmodelConfig(exampleVolumeList) + const xmlParser = new XMLParser({ removeNSPrefix: false, ignoreAttributes: false, parseAttributeValue: true }) + const xmlObject = xmlParser.parse(xmlContent) + + let expectedID = 0 + + for (const volume of xmlObject["config"]["object"]["volume"]) { + expect(volume["@_firstid"]).toBe(expectedID) + expectedID = volume["@_lastid"] + 1 + // name, extruder, source_object_id, source_volume_id + expect(volume["metadata"][1]["@_value"]).toBeLessThanOrEqual(5) + expect(volume["metadata"][2]["@_value"]).toBe(1) + } + }) +}) diff --git a/visualization/app/codeCharta/services/3DExports/generateXML/build3mfStatics.spec.ts b/visualization/app/codeCharta/services/3DExports/generateXML/build3mfStatics.spec.ts new file mode 100644 index 0000000000..70f05db218 --- /dev/null +++ b/visualization/app/codeCharta/services/3DExports/generateXML/build3mfStatics.spec.ts @@ -0,0 +1,18 @@ +import { getXMLcontentType, getXMLrelationships } from "./build3mfStatics" +import { XMLValidator } from "fast-xml-parser" + +describe("build3mfStatics", () => { + describe("contentType", () => { + it("should return valid xml", () => { + const xmlContent = getXMLcontentType() + expect(XMLValidator.validate(xmlContent)).toBe(true) + }) + }) + + describe("relationships", () => { + it("should return valid xml", () => { + const xmlContent = getXMLrelationships() + expect(XMLValidator.validate(xmlContent)).toBe(true) + }) + }) +}) diff --git a/visualization/package-lock.json b/visualization/package-lock.json index 7838af2394..770ea6c2e7 100644 --- a/visualization/package-lock.json +++ b/visualization/package-lock.json @@ -74,6 +74,7 @@ "eslint-config-prettier": "^8.10.0", "eslint-plugin-unicorn": "^47.0.0", "eslint-plugin-unused-imports": "^2.0.0", + "fast-xml-parser": "^4.4.0", "html-loader": "^4.0.0", "jest": "^29.7.0", "jest-canvas-mock": "^2.4.0", @@ -11379,6 +11380,28 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "node_modules/fast-xml-parser": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.4.0.tgz", + "integrity": "sha512-kLY3jFlwIYwBNDojclKsNAC12sfD6NwW74QB2CoNGPvtVxjliYehVunB3HYyNi+n4Tt1dAcgwYvmKF/Z18flqg==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + }, + { + "type": "paypal", + "url": "https://paypal.me/naturalintelligence" + } + ], + "dependencies": { + "strnum": "^1.0.5" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, "node_modules/fastq": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", @@ -21020,6 +21043,12 @@ "node": ">=0.10.0" } }, + "node_modules/strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==", + "dev": true + }, "node_modules/sumchecker": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", diff --git a/visualization/package.json b/visualization/package.json index 61273b1065..69c42f5e74 100644 --- a/visualization/package.json +++ b/visualization/package.json @@ -126,6 +126,7 @@ "eslint-config-prettier": "^8.10.0", "eslint-plugin-unicorn": "^47.0.0", "eslint-plugin-unused-imports": "^2.0.0", + "fast-xml-parser": "^4.4.0", "html-loader": "^4.0.0", "jest": "^29.7.0", "jest-canvas-mock": "^2.4.0",