-
Notifications
You must be signed in to change notification settings - Fork 197
HARP-13852 Adding unit tests for MapControls toggleTilt #2069
Conversation
06ce97e
to
dd5947f
Compare
now: () => {} | ||
now: () => { | ||
// Time in ms, i.e. 20ms gives us a FPS of 50. | ||
return (time += 20); |
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
dd5947f
to
af400c5
Compare
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; | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await tiltBackToZero; | |
return expect(tiltBackToZero).to.eventually.be.closeTo(0, Number.EPSILON); |
There was a problem hiding this comment.
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.
af400c5
to
0a4927f
Compare
retest this please |
retest this please |
1 similar comment
retest this please |
rebase please |
Signed-off-by: Jonathan Stichbury <2533428+nzjony@users.noreply.github.com>
Rebase succeeded. |
0a4927f
to
8dac926
Compare
retest this please |
2 similar comments
retest this please |
retest this please |
@harpgl-bot retest this please |
rebase please |
Rebase succeeded. |
No description provided.