Professional Documents
Culture Documents
Toll Calculator Component Documentation
Toll Calculator Component Documentation
Vercel : https://toll-calculator-q6pcoweak-sammywysors-projects.vercel.app/
Github : https://github.com/sammywysor/Toll-Calculator-Mapup
Overview
The Toll Calculator component stands as a pivotal feature within our application, empowering users to
effortlessly compute toll information for their designated routes. This component seamlessly integrates
with the TollGuru API, harnessing its capabilities to retrieve comprehensive toll details. The calculated
toll data is then presented interactively on an embedded map, offering users an intuitive and visually
engaging experience.
Features
User-Friendly Interface:
Communicates with the TollGuru API to fetch accurate toll details based on the provided route.
Visualizes toll booths along the route with relevant information.
Dynamic Marker Popups:
Provides additional information about markers, such as origin, destination, and toll details,
through popups.
Component Structure
State Variables
origin: Object with latitude and longitude for the origin location.
destination: Object with latitude and longitude for the destination location.
tollInfo: Stores toll information retrieved from the API.
isLoading: Boolean flag indicating whether the toll calculation is in progress.
routePolyline: Decoded polyline for visualizing the calculated route on the map.
Map Initialization
The component initializes a Leaflet map centered at [0, 0] with a default zoom level of 2. The
OpenStreetMap tile layer is added as the base layer.
Map Initialization
The component initializes a Leaflet map centered at [0, 0] with a default zoom level of 2.
The OpenStreetMap tile layer is added as the base layer.
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
}).addTo(map);
The handleCalculateToll function triggers the toll calculation process. It calls the calculateToll
API function, decodes the received polyline, and updates the state variables accordingly.
setIsLoading(true);
try {
const result = await calculateToll(origin, destination);
setTollInfo(result);
setRoutePolyline(decodedPolyline);
} catch (error) {
} finally {
setIsLoading(false);
};
Map Markers
Markers are added to the map for origin, destination, and toll details. Each marker has a
popup displaying relevant information.
jsx
<Marker position={origin}>
<Popup>
<div>
<h3>Origin</h3>
</div>
</Popup>
</Marker>
Verifies that the Toll Calculator component loads successfully on the page.
cy.visit('/');
cy.get('.tollCalculatorContainer').should('exist');
});
cy.get('button').contains('Calculate Toll').click();
// Wait for the API request to complete
cy.wait('@calculateToll');
});
cy.get('button').contains('Calculate Toll').click();
cy.wait('@calculateToll');
});
cy.get('button').contains('Calculate Toll').click();
cy.wait('@calculateToll');
Verifies the content of marker popups for origin, destination, and toll details.
cy.get('button').contains('Calculate Toll').click();
cy.wait('@calculateToll');
});
cy.get('input[placeholder="Enter origin"]').type('Ind');
cy.get('.suggestion-item').should('exist');
});
Test: Distance Calculation
cy.get('button').contains('Calculate Toll').click();
cy.wait('@calculateToll');
});
cy.get('button').contains('Calculate Toll').click();
cy.get('#map .leaflet-marker-icon.custom-marker').should('exist');
});
Future Enhancements
The Toll Calculator component is designed to facilitate future enhancements and modifications.
Developers can extend its functionality seamlessly, and the test suite ensures that new changes
do not compromise existing functionalities.
For any assistance or inquiries, refer to the comprehensive documentation, reach out to our
support team, or explore the source code for further insights.
Thank you for choosing our Toll Calculator component. Happy coding!