Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

HARP-13852 Adding unit tests for MapControls toggleTilt #2069

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

nzjony
Copy link
Member

@nzjony nzjony commented Jan 22, 2021

No description provided.

now: () => {}
now: () => {
// Time in ms, i.e. 20ms gives us a FPS of 50.
return (time += 20);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried incrementing by 1, but it is just a waste of resources, so this is a good value which approaches normal usage

@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #2069 (af400c5) into master (c4790fb) will decrease coverage by 0.09%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2069      +/-   ##
==========================================
- Coverage   66.81%   66.71%   -0.10%     
==========================================
  Files         297      297              
  Lines       26378    26353      -25     
  Branches     5969     5958      -11     
==========================================
- Hits        17624    17582      -42     
- Misses       8754     8771      +17     
Impacted Files Coverage Δ
@here/harp-mapview/lib/CameraMovementDetector.ts 93.05% <80.00%> (+0.09%) ⬆️
@here/harp-test-utils/lib/WebGLStub.ts 100.00% <100.00%> (ø)
...here/harp-datasource-protocol/lib/TechniqueAttr.ts 60.00% <0.00%> (-30.00%) ⬇️
@here/harp-datasource-protocol/lib/DecodedTile.ts 50.96% <0.00%> (-4.09%) ⬇️
...vectortile-datasource/lib/VectorTileDataEmitter.ts 60.22% <0.00%> (-4.05%) ⬇️
@here/harp-datasource-protocol/lib/Techniques.ts 71.69% <0.00%> (-0.95%) ⬇️
@here/harp-mapview/lib/TileObjectsRenderer.ts 44.20% <0.00%> (-0.80%) ⬇️
@here/harp-mapview/lib/Statistics.ts 68.88% <0.00%> (-0.27%) ⬇️
.../harp-datasource-protocol/lib/StyleSetEvaluator.ts 89.05% <0.00%> (-0.26%) ⬇️
@here/harp-mapview/lib/MapObjectAdapter.ts 87.50% <0.00%> (-0.22%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99b41a3...8dac926. Read the comment docs.

@here/harp-mapview/lib/CameraMovementDetector.ts Outdated Show resolved Hide resolved
Comment on lines 613 to 624
const checkGoesToZero = () => {
const mapViewTiltRad = THREE.MathUtils.degToRad(mapView.tilt);

// Resolve when we reach 0
if (mapViewTiltRad <= Number.EPSILON) {
mapView.removeEventListener(MapViewEventNames.AfterRender, checkGoesToZero);
resolvePromise();
} else if (previousTilt === mapViewTiltRad) {
rejectPromise();
}
previousTilt = mapViewTiltRad;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and checkReachesTiltAngle can be done with a single function. Just pass the target angle as parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, great idea!

}
previousTilt = mapViewTiltRad;
};
mapView.addEventListener(MapViewEventNames.AfterRender, checkReachesTiltAngle);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would listen to MapViewEventNames.MovementFinished instead, that way we only need to check the tilt once at the end of the animation. Then return the reached tilt angle as Promise result and check the value in the assertion as I mention next.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner, thanks for the tip!

previousTilt = mapViewTiltRad;
};
mapView.addEventListener(MapViewEventNames.AfterRender, checkReachesTiltAngle);
await tiltCamera;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await tiltCamera;
expect(tiltCamera).to.eventually.be.closeTo(targetTilt, Number.EPSILON).then( // add here the second part of the test);

Using chai as promised the test expectation is clearer and the error messages will be more explicit. You need to import chai as promised (see TileLoaderTest).

previousTilt = mapViewTiltRad;
};
mapView.addEventListener(MapViewEventNames.AfterRender, checkGoesToZero);
await tiltBackToZero;
Copy link
Collaborator

@atomicsulfate atomicsulfate Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await tiltBackToZero;
return expect(tiltBackToZero).to.eventually.be.closeTo(0, Number.EPSILON);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed to use expect.

I don't like the return syntax, because otherwise the test gets more nested and it makes readability / maintenance harder IMO, also, await is used a lot in existing tests, so I think this is not some exception.

atomicsulfate
atomicsulfate previously approved these changes Jan 25, 2021
@nzjony
Copy link
Member Author

nzjony commented Jan 28, 2021

retest this please

@nzjony nzjony enabled auto-merge (squash) January 28, 2021 12:48
@nzjony
Copy link
Member Author

nzjony commented Jan 28, 2021

retest this please

1 similar comment
@nzjony
Copy link
Member Author

nzjony commented Jan 29, 2021

retest this please

@nzjony
Copy link
Member Author

nzjony commented Jan 29, 2021

rebase please

Signed-off-by: Jonathan Stichbury <2533428+nzjony@users.noreply.github.com>
@github-actions
Copy link

Rebase succeeded.

@nzjony
Copy link
Member Author

nzjony commented Jan 29, 2021

retest this please

2 similar comments
@nzjony
Copy link
Member Author

nzjony commented Feb 1, 2021

retest this please

@nzjony
Copy link
Member Author

nzjony commented Feb 1, 2021

retest this please

@nzjony
Copy link
Member Author

nzjony commented Feb 1, 2021

@harpgl-bot retest this please

@nzjony
Copy link
Member Author

nzjony commented Feb 1, 2021

rebase please

@github-actions
Copy link

github-actions bot commented Feb 1, 2021

Rebase succeeded.

@nzjony nzjony disabled auto-merge February 1, 2021 15:42
@nzjony nzjony merged commit f638162 into master Feb 1, 2021
@nzjony nzjony deleted the HARP-13852_unittest branch February 1, 2021 15:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants