Skip to content

Commit

Permalink
test(mesh-io): browser readPointSet writePointSet
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Oct 4, 2024
1 parent b786dfd commit 06b188e
Show file tree
Hide file tree
Showing 12 changed files with 2,317 additions and 1,077 deletions.
7 changes: 7 additions & 0 deletions packages/mesh-io/typescript/cypress/e2e/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export function verifyMesh (mesh) {
cy.expect(mesh.numberOfPoints).to.equal(2903)
cy.expect(mesh.numberOfCells).to.equal(3263)
}

export function verifyPointSet (pointSet) {
cy.expect(pointSet.pointSetType.dimension).to.equal(3)
cy.expect(pointSet.pointSetType.pointComponentType).to.equal(FloatTypes.Float32)
cy.expect(pointSet.pointSetType.pointPixelType).to.equal(PixelTypes.Vector)
cy.expect(pointSet.numberOfPoints).to.equal(8)
}
90 changes: 90 additions & 0 deletions packages/mesh-io/typescript/cypress/e2e/read-point-set.cy.ts
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",
);
}
});
},
);
});
74 changes: 43 additions & 31 deletions packages/mesh-io/typescript/cypress/e2e/write-mesh.cy.ts
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 packages/mesh-io/typescript/cypress/e2e/write-point-set.cy.ts
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);
});
});
});
Loading

0 comments on commit 06b188e

Please sign in to comment.