Test: Implement Component: Fleet Manager Vehicle Tracking (Live Map) Updates - #523
Open
AdaBliss wants to merge 1 commit into
Open
Test: Implement Component: Fleet Manager Vehicle Tracking (Live Map) Updates#523AdaBliss wants to merge 1 commit into
AdaBliss wants to merge 1 commit into
Conversation
…Updates Add component tests for the fleet manager live map covering marker clustering, live driver updates and empty states. Clustering is now zoom-aware: the grid cell size doubles for every zoom level the manager zooms out, so nearby drivers merge into one cluster marker instead of rendering as overlapping pins, and split apart again on zoom in. Previously the cell size was a fixed 0.05 degrees regardless of zoom, so 'clusters when zoomed out' was not observable behaviour. - clustering: add cellSizeForZoom() with clamping and non-finite guards - FleetMapClient: track zoom via useMapEvents and re-bucket on zoomend - tests: 19 FleetMapClient cases (mocked react-leaflet/leaflet) and 7 cellSizeForZoom cases
|
@AdaBliss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #497
Summary
Adds component tests for the fleet manager live map, covering marker clustering as the manager zooms, live driver telemetry updates, and empty/degenerate data.
While writing these it became clear the behaviour the issue asks to verify did not exist yet:
clusterDriverswas always called with a fixed0.05degree cell size, so the map produced identical buckets at every zoom level. "Clusters markers when zoomed out" was therefore not observable. This PR makes clustering zoom-aware so the tests assert real behaviour rather than a constant.Changes
components/fleet/clustering.tscellSizeForZoom(zoom). One Leaflet zoom step halves the ground distance a pixel covers, so the grid cell doubles for every level the user zooms out. That keeps the on-screen distance between merged pins roughly constant.[0.001, 45]degrees so extreme zooms cannot degenerate into one bucket per driver or a single bucket for the whole world, and a non-finite zoom falls back to the default.DEFAULT_CLUSTER_CELL_SIZEandREFERENCE_ZOOM;clusterDriversnow uses the named constant as its default, so the previous behaviour is unchanged at zoom 6.components/fleet/FleetMapClient.tsxDriverClusterLayerchild souseMapEventscan read the Leaflet map from context, and re-bucket onzoomend.zoomend, so a map created at a restored zoom or viafitBoundsclusters correctly on first paint.Test coverage
components/fleet/__tests__/FleetMapClient.test.tsx(19 tests).react-leafletandleafletare mocked with lightweight DOM stubs, since jsdom has no layout engine and the realMapContainercannot mount. The stubs surface the props the component passes down (center, radius, colour) as data attributes, so assertions describe what a fleet manager would see rather than internals. No network, no timers, no real map instance.2 driversmarker zoomed out; split apart again on zoom in; drivers in different cities never merge at regional zoom; cluster markers get the larger radius and the cluster colour; cluster sits at the centroid of its members; the layer adopts the map instance zoom on mount.NaNzoom, and drivers straddling the equator and prime meridian.components/fleet/__tests__/clustering.test.tsgains 7cellSizeForZoomcases (reference zoom, doubling out, halving in, monotonicity, clamping, non-finite fallback, and an end-to-end merge/split check).Verification
npx jest components/fleet- 4 suites, 40 tests, all passing.mainbefore this change.npx eslint components/fleet- clean.npx tsc --noEmit- no errors from this change.Note for the maintainer
maincurrently fails the CIType CheckandBuild Verificationsteps for an unrelated reason:components/mobile/MobileFooter.tsxlanded with its string quotes stripped (line 1 is a backtick-quoteduse client, and imports readimport React from react), which tripsTS1160: Unterminated template literal. It came in with #318 and is present onmainindependently of this PR, so it will show red here and on every other open PR until it is fixed. I left it alone to keep this PR scoped to the issue; happy to open a separate fix PR if that would help.