Test: Implement Integration: WebSocket Live Driver Location Updates - #544
Merged
Merged
Conversation
Closes SwiftChainn#474 Adds the integration coverage the issue asks for: mock WebSocket events emitting driver coordinates, asserted against the map's rendered state. The repo had no path from a socket event to the fleet map. useFleet fetches a driver snapshot over REST and FleetMapClient renders it, but nothing folded live telemetry back in, so there was no seam to test. This adds that seam as a thin hook and then tests it end to end. - hooks/useDriverLocations.ts: subscribes to DRIVER_LOCATION while the socket is connected and overlays incoming coordinates onto the driver list. Unknown driverIds and malformed frames are ignored, and an older frame does not overwrite a newer one, which matters on reconnect. - __tests__/integration/DriverLocationUpdates.test.tsx: 9 tests covering subscribe/unsubscribe lifecycle, a single frame moving a marker, a sequence of frames tracking one driver, isolation between drivers, and the three bad-frame paths. The socket is mocked at the service boundary and Leaflet is stubbed the same way components/fleet/__tests__/FleetMapClient.test.tsx already does it, so no real connection is opened and jsdom never has to lay out a map. Marker positions are read back off the stub as data attributes, so the assertions describe what a fleet manager would actually see move. Verified the tests fail (4 of 9) when the hook's merge step is removed, so they are not passing vacuously.
|
@AdaBebe0 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 #474
Re-opening this work — the original branch was deleted by mistake, so this is a fresh branch with the same scope.
What the issue asks for
What I found first
There was no path from a socket event to the fleet map.
useFleetfetches a driver snapshot over REST andFleetMapClientrenders it, but nothing folded live telemetry back into that list —DRIVER_LOCATION(or any equivalent) appears nowhere in the repo. So there was no seam to write an integration test against.This PR adds that seam as a thin hook, then tests it end to end. Flagging it explicitly since the issue is labelled
testingand I'd rather not slip production code in unannounced — happy to split the hook into its own PR if the team prefers.Changes
hooks/useDriverLocations.ts— subscribes toDRIVER_LOCATIONwhile the socket is connected and overlays incoming coordinates onto the driver list. Follows the existing layering (Component → Hook →socketService), same shape asuseLiveUpdates. Three deliberate behaviours:driverIdare ignored rather than inventing a markerNaNcoordinates) are dropped, so a marker can never jump toNaN,NaN__tests__/integration/DriverLocationUpdates.test.tsx— 9 tests:Test approach
The socket is mocked at the service boundary, so no real connection is opened. Leaflet is stubbed wholesale — jsdom has no layout engine, so the real
MapContainercannot mount — following the pattern already established incomponents/fleet/__tests__/FleetMapClient.test.tsx. The stubs expose marker centres as data attributes, so assertions read against what a fleet manager would actually see move on the map, not against hook internals.Verification
pnpm run lint— no new errorstsc --noEmit— no errors in either new fileNote on CI
CI on this repo is currently red on
mainfor every PR —pnpm run lintexits 1 on 4 pre-existing errors, so Type Check and Test never run. #542 fixes that, and #543 clears 110 of the pre-existing type errors. Neither is related to this PR, but this PR's checks won't go green until #542 lands.