Skip to content

Commit

Permalink
refactor(test): handling fail messages in test with promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Apr 19, 2023
1 parent 9ca1d5f commit 48b9750
Show file tree
Hide file tree
Showing 22 changed files with 604 additions and 470 deletions.
9 changes: 5 additions & 4 deletions test/unit/3dtileslayerprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ describe('3Dtiles layer', function () {
};

it('Add 3dtiles layer', function (done) {
View.prototype.addLayer.call(viewer, threedTilesLayer).then((layer) => {
assert.equal(layer.root.children.length, 1);
done();
});
View.prototype.addLayer.call(viewer, threedTilesLayer)
.then((layer) => {
assert.equal(layer.root.children.length, 1);
done();
}, done);
});
it('preUpdate 3dtiles layer', function () {
const elements = threedTilesLayer.preUpdate(context, new Set([threedTilesLayer]));
Expand Down
13 changes: 7 additions & 6 deletions test/unit/3dtileslayerprocessbatchtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ describe('3Dtiles batch table', function () {
}, viewer);

it('Add 3dtiles layer with batch table', function (done) {
View.prototype.addLayer.call(viewer, threedTilesLayerBTHierarchy).then((layer) => {
assert.equal(layer.root.children.length, 1);
const batchLength = viewer.getLayerById('3d-tiles-bt-hierarchy').root.batchTable.batchLength;
assert.equal(batchLength, 30);
done();
});
View.prototype.addLayer.call(viewer, threedTilesLayerBTHierarchy)
.then((layer) => {
assert.equal(layer.root.children.length, 1);
const batchLength = viewer.getLayerById('3d-tiles-bt-hierarchy').root.batchTable.batchLength;
assert.equal(batchLength, 30);
done();
}, done);
});
});
94 changes: 54 additions & 40 deletions test/unit/CameraUtils.js → test/unit/cameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,62 +56,76 @@ describe('Camera utils unit test', function () {
const range = 25000000;
const coord = new Coordinates('EPSG:4326', 2.35, 48.85, 0);

it('init like expected', function () {
it('init like expected', function (done) {
const params = { range, coord };
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
done();
}, done);
});
it('should set range like expected', function () {
it('should set range like expected', function (done) {
const params = { range: 10000 };
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
const range = result.range;
assert.ok(equalToFixed(range, params.range, 1));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
const range = result.range;
assert.ok(equalToFixed(range, params.range, 1));
done();
}, done);
});
it('should look at coordinate like expected', function () {
it('should look at coordinate like expected', function (done) {
const params = { coord: coord.clone() };
params.coord.setFromValues(params.coord.longitude + 1, params.coord.latitude + 1, 0);
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
done();
}, done);
});
it('should tilt like expected', function () {
it('should tilt like expected', function (done) {
const params = { tilt: 38 };
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
done();
}, done);
});
it('should heading like expected', function () {
it('should heading like expected', function (done) {
const params = { heading: 147 };
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
done();
}, done);
});
it('should heading, tilt, range and coordinate like expected', function () {
it('should heading, tilt, range and coordinate like expected', function (done) {
const params = { heading: 17, tilt: 80, range: 20000, coord: coord.clone() };
params.coord.setFromValues(params.coord.longitude + 5, params.coord.latitude + 5, 0);
CameraUtils.transformCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
});
CameraUtils.transformCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
done();
}, done);
});
it('should heading, tilt, range and coordinate like expected with animation (200ms)', function () {
it('should heading, tilt, range and coordinate like expected with animation (200ms)', function (done) {
const params = { heading: 17, tilt: 80, range: 20000, coord: coord.clone(), time: 200 };
params.coord.setFromValues(params.coord.longitude + 3, params.coord.latitude + 4, 0);
CameraUtils.animateCameraToLookAtTarget(view, camera, params).then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
});
CameraUtils.animateCameraToLookAtTarget(view, camera, params)
.then((result) => {
assert.ok(equalToFixed(result.heading, params.heading, 4));
assert.ok(equalToFixed(result.tilt, params.tilt, 4));
assert.ok(equalToFixed(result.range, params.range, 1));
assert.ok(equalToFixed(result.coord.longitude, params.coord.longitude, 4));
assert.ok(equalToFixed(result.coord.latitude, params.coord.latitude, 4));
done();
}, done);
});

it('should transform camera from given extent', function () {
Expand Down
117 changes: 63 additions & 54 deletions test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Provide in Sources', function () {
context.scheduler.commands = [];
});

it('should get wmts texture with DataSourceProvider', () => {
it('should get wmts texture with DataSourceProvider', (done) => {
colorlayer.source = new WMTSSource({
url: 'http://',
name: 'name',
Expand All @@ -131,11 +131,13 @@ describe('Provide in Sources', function () {

updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => {
assert.equal(textures[0].extent.zoom, zoom);
assert.equal(textures[0].extent.row, 511);
assert.equal(textures[0].extent.col, 512);
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures[0].extent.zoom, zoom);
assert.equal(textures[0].extent.row, 511);
assert.equal(textures[0].extent.col, 512);
done();
}, done);
});

it('should get wmts texture elevation with DataSourceProvider', (done) => {
Expand All @@ -159,12 +161,13 @@ describe('Provide in Sources', function () {

updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent);
updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => {
assert.equal(textures[0].extent.zoom, zoom);
assert.equal(textures[0].extent.row, 511);
assert.equal(textures[0].extent.col, 512);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures[0].extent.zoom, zoom);
assert.equal(textures[0].extent.row, 511);
assert.equal(textures[0].extent.col, 512);
done();
}, done);
});
it('should get wms texture with DataSourceProvider', (done) => {
colorlayer.source = new WMSSource({
Expand All @@ -188,15 +191,16 @@ describe('Provide in Sources', function () {

updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => {
const e = textures[0].extent.as(tile.extent.crs);
assert.equal(e.zoom, zoom);
assert.equal(e.west, tile.extent.west);
assert.equal(e.east, tile.extent.east);
assert.equal(e.north, tile.extent.north);
assert.equal(e.south, tile.extent.south);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
const e = textures[0].extent.as(tile.extent.crs);
assert.equal(e.zoom, zoom);
assert.equal(e.west, tile.extent.west);
assert.equal(e.east, tile.extent.east);
assert.equal(e.north, tile.extent.north);
assert.equal(e.south, tile.extent.south);
done();
}, done);
});
it('should get 4 TileMesh from TileProvider', (done) => {
const tile = new TileMesh(geom, material, planarlayer, extent, zoom);
Expand All @@ -205,14 +209,15 @@ describe('Provide in Sources', function () {
tile.parent = { };

planarlayer.subdivideNode(context, tile);
TileProvider.executeCommand(context.scheduler.commands[0]).then((tiles) => {
assert.equal(tiles.length, 4);
assert.equal(tiles[0].extent.west, tile.extent.east * 0.5);
assert.equal(tiles[0].extent.east, tile.extent.east);
assert.equal(tiles[0].extent.north, tile.extent.north);
assert.equal(tiles[0].extent.south, tile.extent.north * 0.5);
done();
});
TileProvider.executeCommand(context.scheduler.commands[0])
.then((tiles) => {
assert.equal(tiles.length, 4);
assert.equal(tiles[0].extent.west, tile.extent.east * 0.5);
assert.equal(tiles[0].extent.east, tile.extent.east);
assert.equal(tiles[0].extent.north, tile.extent.north);
assert.equal(tiles[0].extent.south, tile.extent.north * 0.5);
done();
}, done);
});
it('should get 3 meshs with WFS source and DataSourceProvider', (done) => {
const tile = new TileMesh(geom, material, planarlayer, extent, featureLayer.zoom.min);
Expand All @@ -225,10 +230,11 @@ describe('Provide in Sources', function () {
featureLayer.source.onLayerAdded({ out: featureLayer });

featureLayer.update(context, featureLayer, tile);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((features) => {
assert.equal(features[0].meshes.children.length, 4);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((features) => {
assert.equal(features[0].meshes.children.length, 4);
done();
}, done);
});

it('should get 1 mesh with WFS source and DataSourceProvider and mergeFeatures == true', (done) => {
Expand All @@ -246,14 +252,15 @@ describe('Provide in Sources', function () {
featureLayer.source._featuresCaches = {};
featureLayer.source.onLayerAdded({ out: featureLayer });
featureLayer.update(context, featureLayer, tile);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((features) => {
assert.ok(features[0].meshes.children[0].isMesh);
assert.ok(features[0].meshes.children[1].isPoints);
assert.equal(features[0].meshes.children[0].children.length, 0);
assert.equal(features[0].meshes.children[1].children.length, 0);
assert.equal(featureCountByCb, 2);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((features) => {
assert.ok(features[0].meshes.children[0].isMesh);
assert.ok(features[0].meshes.children[1].isPoints);
assert.equal(features[0].meshes.children[0].children.length, 0);
assert.equal(features[0].meshes.children[1].children.length, 0);
assert.equal(featureCountByCb, 2);
done();
}, done);
});
it('should get 1 texture with WFS source and DataSourceProvider', (done) => {
const tile = new TileMesh(
Expand Down Expand Up @@ -287,11 +294,12 @@ describe('Provide in Sources', function () {
colorlayerWfs.source.onLayerAdded({ out: colorlayerWfs });
updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => {
assert.equal(textures.length, 1);
assert.ok(textures[0].isTexture);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures.length, 1);
assert.ok(textures[0].isTexture);
done();
}, done);
});

it('should get updated RasterLayer', (done) => {
Expand All @@ -315,13 +323,14 @@ describe('Provide in Sources', function () {

updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((result) => {
tile.material.setSequence([colorlayer.id]);
tile.material.getLayer(colorlayer.id).setTextures(result, [new THREE.Vector4()]);
assert.equal(tile.material.uniforms.colorTextures.value[0].extent, undefined);
tile.material.updateLayersUniforms();
assert.equal(tile.material.uniforms.colorTextures.value[0].extent.zoom, 10);
done();
});
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((result) => {
tile.material.setSequence([colorlayer.id]);
tile.material.getLayer(colorlayer.id).setTextures(result, [new THREE.Vector4()]);
assert.equal(tile.material.uniforms.colorTextures.value[0].extent, undefined);
tile.material.updateLayersUniforms();
assert.equal(tile.material.uniforms.colorTextures.value[0].extent.zoom, 10);
done();
}, done);
});
});
18 changes: 10 additions & 8 deletions test/unit/demutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ describe('DemUtils', function () {
};

it('add elevation layer', (done) => {
viewer.addLayer(elevationlayer).then((l) => {
assert.equal('worldelevation', l.id);
done();
});
viewer.addLayer(elevationlayer)
.then((l) => {
assert.equal('worldelevation', l.id);
done();
}, done);
});
const tiles = [];
const extent = new Extent('EPSG:4326', 5.625, 11.25, 45, 50.625);
Expand All @@ -64,10 +65,11 @@ describe('DemUtils', function () {
const tile = new TileMesh(geom, material, viewer.tileLayer, extent, 5);
tile.layerUpdateState[elevationlayer.id] = new LayerUpdateState();
tiles.push(tile);
updateLayeredMaterialNodeElevation(context, elevationlayer, tile, {}).then(() => {
assert.equal(nodeLayer.textures[0].image.data[0], 357.3833923339844);
done();
});
updateLayeredMaterialNodeElevation(context, elevationlayer, tile, {})
.then(() => {
assert.equal(nodeLayer.textures[0].image.data[0], 357.3833923339844);
done();
}, done);
});

it('get elevation value at with PRECISE_READ_Z', () => {
Expand Down
Loading

0 comments on commit 48b9750

Please sign in to comment.