Skip to content

Commit

Permalink
Add xml test to static resources
Browse files Browse the repository at this point in the history
  • Loading branch information
phanlezz committed Jun 10, 2024
1 parent 0359929 commit 0e25e9b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
})
})
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
29 changes: 29 additions & 0 deletions visualization/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions visualization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0e25e9b

Please sign in to comment.