-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mesh-io): browser readPointSet writePointSet
- Loading branch information
Showing
12 changed files
with
2,317 additions
and
1,077 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/mesh-io/typescript/cypress/e2e/read-point-set.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { demoServer, verifyPointSet } from "./common.ts"; | ||
|
||
describe("read-point-set", () => { | ||
beforeEach(function () { | ||
cy.visit(demoServer); | ||
|
||
const testPathPrefix = "../test/data/input/"; | ||
|
||
const testImageFiles = ["box-points.obj"]; | ||
testImageFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName); | ||
}); | ||
}); | ||
|
||
it("Reads an point set File in the demo", function () { | ||
cy.get('sl-tab[panel="readPointSet-panel"]').click(); | ||
|
||
const testFile = { | ||
contents: new Uint8Array(this["box-points.obj"]), | ||
fileName: "box-points.obj", | ||
}; | ||
cy.get( | ||
'#readPointSetInputs input[name="serialized-point-set-file"]', | ||
).selectFile([testFile], { force: true }); | ||
cy.get("#readPointSet-serialized-point-set-details").should( | ||
"contain", | ||
"35,9", | ||
); | ||
|
||
cy.get('#readPointSetInputs sl-button[name="run"]').click(); | ||
|
||
cy.get("#readPointSet-point-set-details").should("contain", "pointSetType"); | ||
}); | ||
|
||
it("Reads an pointSet BinaryFile", function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this["box-points.obj"]).buffer; | ||
const { pointSet, webWorker } = await win.meshIo.readPointSet({ | ||
data: new Uint8Array(arrayBuffer), | ||
path: "box-points.obj", | ||
}); | ||
webWorker.terminate(); | ||
verifyPointSet(pointSet); | ||
}); | ||
}); | ||
|
||
it("Reads an pointSet File", function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this["box-points.obj"]).buffer; | ||
const cowFile = new win.File([arrayBuffer], "box-points.obj"); | ||
const { pointSet, webWorker } = await win.meshIo.readPointSet(cowFile); | ||
webWorker.terminate(); | ||
verifyPointSet(pointSet); | ||
}); | ||
}); | ||
|
||
it("Reads re-uses a WebWorker", function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this["box-points.obj"]).buffer; | ||
const cowFile = new win.File([arrayBuffer], "box-points.obj"); | ||
const { webWorker } = await win.meshIo.readPointSet(cowFile); | ||
const { pointSet } = await win.meshIo.readPointSet(cowFile, { | ||
webWorker, | ||
}); | ||
webWorker.terminate(); | ||
verifyPointSet(pointSet); | ||
}); | ||
}); | ||
|
||
it( | ||
"Throws a catchable error for an invalid file", | ||
{ defaultCommandTimeout: 120000 }, | ||
function () { | ||
cy.window().then(async (win) => { | ||
const invalidArray = new Uint8Array([21, 4, 4, 4, 4, 9, 5, 0, 82, 42]); | ||
const invalidBlob = new win.Blob([invalidArray]); | ||
const invalidFile = new win.File([invalidBlob], "invalid.file"); | ||
try { | ||
const { webWorker, pointSet } = | ||
await win.meshIo.readPointSet(invalidFile); | ||
webWorker.terminate(); | ||
} catch (error) { | ||
cy.expect(error.message).to.equal( | ||
"Could not find IO for: invalid.file", | ||
); | ||
} | ||
}); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
import { demoServer, verifyMesh } from './common.ts' | ||
import { demoServer, verifyMesh } from "./common.ts"; | ||
|
||
describe('write-mesh', () => { | ||
beforeEach(function() { | ||
cy.visit(demoServer) | ||
describe("write-mesh", () => { | ||
beforeEach(function () { | ||
cy.visit(demoServer); | ||
|
||
const testPathPrefix = '../test/data/input/' | ||
const testPathPrefix = "../test/data/input/"; | ||
|
||
const testImageFiles = [ | ||
'cow.iwm.cbor' | ||
] | ||
testImageFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName) | ||
}) | ||
}) | ||
const testMeshFiles = ["cow.iwm.cbor"]; | ||
testMeshFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName); | ||
}); | ||
}); | ||
|
||
it('Writes an mesh in the demo', function () { | ||
cy.get('sl-tab[panel="writeMesh-panel"]').click() | ||
it("Writes an mesh in the demo", function () { | ||
cy.get('sl-tab[panel="writeMesh-panel"]').click(); | ||
|
||
const testFile = { contents: new Uint8Array(this['cow.iwm.cbor']), fileName: 'cow.iwm.cbor' } | ||
cy.get('#writeMeshInputs input[name="mesh-file"]').selectFile([testFile,], { force: true }) | ||
cy.get('#writeMesh-mesh-details').should('contain', 'meshType') | ||
cy.get('#writeMeshInputs sl-input[name="serialized-mesh"]').find('input', { includeShadowDom: true }).type('cow.vtk', { force: true }) | ||
const testFile = { | ||
contents: new Uint8Array(this["cow.iwm.cbor"]), | ||
fileName: "cow.iwm.cbor", | ||
}; | ||
cy.get('#writeMeshInputs input[name="mesh-file"]').selectFile([testFile], { | ||
force: true, | ||
}); | ||
cy.get("#writeMesh-mesh-details").should("contain", "meshType"); | ||
cy.get('#writeMeshInputs sl-input[name="serialized-mesh"]') | ||
.find("input", { includeShadowDom: true }) | ||
.type("cow.vtk", { force: true }); | ||
|
||
cy.get('#writeMeshInputs sl-button[name="run"]').click() | ||
cy.get('#writeMeshInputs sl-button[name="run"]').click(); | ||
|
||
cy.get('#writeMesh-serialized-mesh-details').should('contain', '35,32') | ||
}) | ||
cy.get("#writeMesh-serialized-mesh-details").should("contain", "35,32"); | ||
}); | ||
|
||
it('Writes an mesh to an ArrayBuffer', function () { | ||
it("Writes an mesh to an ArrayBuffer", function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this['cow.iwm.cbor']).buffer | ||
const { mesh, webWorker } = await win.meshIo.readMesh({ data: new Uint8Array(arrayBuffer), path: 'cow.iwm.cbor' }) | ||
const { serializedMesh } = await win.meshIo.writeMesh(mesh, 'cow.vtk', { webWorker }) | ||
const { mesh: meshBack } = await win.meshIo.readMesh(serializedMesh, { webWorker }) | ||
webWorker.terminate() | ||
verifyMesh(meshBack) | ||
}) | ||
}) | ||
}) | ||
const arrayBuffer = new Uint8Array(this["cow.iwm.cbor"]).buffer; | ||
const { mesh, webWorker } = await win.meshIo.readMesh({ | ||
data: new Uint8Array(arrayBuffer), | ||
path: "cow.iwm.cbor", | ||
}); | ||
const { serializedMesh } = await win.meshIo.writeMesh(mesh, "cow.vtk", { | ||
webWorker, | ||
}); | ||
const { mesh: meshBack } = await win.meshIo.readMesh(serializedMesh, { | ||
webWorker, | ||
}); | ||
webWorker.terminate(); | ||
verifyMesh(meshBack); | ||
}); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
packages/mesh-io/typescript/cypress/e2e/write-point-set.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { demoServer, verifyPointSet } from "./common.ts"; | ||
|
||
describe("write-point-set", () => { | ||
beforeEach(function () { | ||
cy.visit(demoServer); | ||
|
||
const testPathPrefix = "../test/data/baseline/"; | ||
|
||
const testPointSetFiles = ["obj-read-point-set-test.iwm.cbor"]; | ||
testPointSetFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName); | ||
}); | ||
}); | ||
|
||
it("Writes an point set in the demo", function () { | ||
cy.get('sl-tab[panel="writePointSet-panel"]').click(); | ||
|
||
const testFile = { | ||
contents: new Uint8Array(this["obj-read-point-set-test.iwm.cbor"]), | ||
fileName: "obj-read-point-set-test.iwm.cbor", | ||
}; | ||
cy.get('#writePointSetInputs input[name="point-set-file"]').selectFile( | ||
[testFile], | ||
{ | ||
force: true, | ||
}, | ||
); | ||
cy.get("#writePointSet-point-set-details").should( | ||
"contain", | ||
"pointSetType", | ||
); | ||
cy.get('#writePointSetInputs sl-input[name="serialized-point-set"]') | ||
.find("input", { includeShadowDom: true }) | ||
.type("point-set.vtk", { force: true }); | ||
|
||
cy.get('#writePointSetInputs sl-button[name="run"]').click(); | ||
|
||
cy.get("#writePointSet-serialized-point-set-details").should( | ||
"contain", | ||
"35,32", | ||
); | ||
}); | ||
|
||
it("Writes an point set to an ArrayBuffer", function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array( | ||
this["obj-read-point-set-test.iwm.cbor"], | ||
).buffer; | ||
const { pointSet, webWorker } = await win.meshIo.readPointSet({ | ||
data: new Uint8Array(arrayBuffer), | ||
path: "obj-read-point-set-test.iwm.cbor", | ||
}); | ||
const { serializedPointSet } = await win.meshIo.writePointSet( | ||
pointSet, | ||
"point-set.iwm.cbor", | ||
{ | ||
webWorker, | ||
}, | ||
); | ||
const { pointSet: pointSetBack } = await win.meshIo.readPointSet( | ||
serializedPointSet, | ||
{ | ||
webWorker, | ||
}, | ||
); | ||
webWorker.terminate(); | ||
verifyPointSet(pointSetBack); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.