Improve desktop geolocation handling

This commit is contained in:
Edward Betts 2026-08-15 12:53:41 +01:00
parent 07080c79d3
commit c3999d796d
2 changed files with 28 additions and 2 deletions

View file

@ -605,8 +605,17 @@ byId('locate-button').addEventListener('click', () => {
const apiParams = new URLSearchParams({...coordinates, label: 'Your location'}); const apiParams = new URLSearchParams({...coordinates, label: 'Your location'});
loadUrl(`${API_URLS.stops}?${apiParams}`); loadUrl(`${API_URLS.stops}?${apiParams}`);
}, },
() => { setLoading(false); showError('Location access was denied or unavailable.'); }, error => {
{enableHighAccuracy: true, timeout: 10000} setLoading(false);
const messages = {
1: 'Location permission was denied. Check this sites location permission in your browser.',
2: 'Your browser could not determine your location. Check that device or operating-system location services are enabled.',
3: 'Determining your location timed out. Try again, or enter latitude and longitude manually.',
};
showError(messages[error.code] || `Could not determine your location${error.message ? `: ${error.message}` : '.'}`);
},
// Desktop browsers usually rely on network location rather than GPS.
{enableHighAccuracy: false, timeout: 20000, maximumAge: 300000}
); );
}); });

View file

@ -219,6 +219,23 @@ def test_single_postcode_match_opens_directly(chromium_browser: Any, flask_url:
page.close() page.close()
def test_browser_location_loads_nearby_stops(chromium_browser: Any, flask_url: str) -> None:
"""A permitted desktop geolocation result is used for a nearby-stop search."""
context = chromium_browser.new_context(geolocation={"latitude": 51.5, "longitude": -0.12})
context.grant_permissions(["geolocation"], origin=flask_url)
page = context.new_page()
page.route("**/api/stops?*", lambda route: route.fulfill(json={
"kind": "location",
"location": {"lat": 51.5, "lon": -0.12, "label": "Your location"},
"stops": [],
}))
page.goto(flask_url, wait_until="networkidle")
page.get_by_role("button", name="Use my current location").click()
playwright_api.expect(page).to_have_url(re.compile(r"\?lat=51.5&lon=-0.12$"))
playwright_api.expect(page.locator("#stop-count")).to_have_text("0 found")
context.close()
def test_mobile_layout_opens_results_sheet(chromium_browser: Any, flask_url: str) -> None: def test_mobile_layout_opens_results_sheet(chromium_browser: Any, flask_url: str) -> None:
"""The finder exposes its search panel as an open mobile bottom sheet.""" """The finder exposes its search panel as an open mobile bottom sheet."""
page = chromium_browser.new_page(viewport={"width": 390, "height": 844}) page = chromium_browser.new_page(viewport={"width": 390, "height": 844})