Improve stop search and add documentation
This commit is contained in:
parent
42484907ac
commit
71e1b57164
9 changed files with 358 additions and 37 deletions
|
|
@ -39,7 +39,11 @@ def test_search_and_stop_details_in_browser(chromium_browser: Any, flask_url: st
|
|||
"""A location search renders stops, an ATCO code, tags, and route metadata."""
|
||||
page = chromium_browser.new_page(viewport={"width": 1280, "height": 800})
|
||||
page_errors: list[str] = []
|
||||
search_requests: list[str] = []
|
||||
page.on("pageerror", lambda error: page_errors.append(str(error)))
|
||||
page.on("request", lambda request: (
|
||||
search_requests.append(request.url) if "/api/search?" in request.url else None
|
||||
))
|
||||
stop = {
|
||||
"type": "node", "id": 123, "lat": 51.451, "lon": -2.591,
|
||||
"name": "Central Stop", "atco_code": "0100BRP90314", "indicator": "N",
|
||||
|
|
@ -48,14 +52,12 @@ def test_search_and_stop_details_in_browser(chromium_browser: Any, flask_url: st
|
|||
"tags": {"highway": "bus_stop", "shelter": "yes"},
|
||||
}
|
||||
page.route("**/api/search?*", lambda route: route.fulfill(json={
|
||||
"kind": "location",
|
||||
"location": {"lat": 51.45, "lon": -2.59, "label": "Bristol"},
|
||||
"stops": [{
|
||||
"type": "node", "id": 125, "lat": 51.47, "lon": -2.61,
|
||||
"name": "Far Stop", "atco_code": "0100BRP90316", "indicator": None,
|
||||
"bearing": "E", "transport_type": "Bus stop",
|
||||
"tags": {"highway": "bus_stop"},
|
||||
}, stop],
|
||||
"kind": "geocode",
|
||||
"query": "Bristol",
|
||||
"locations": [
|
||||
{"lat": 51.45, "lon": -2.59, "label": "Bristol Centre", "type": "city"},
|
||||
{"lat": 51.2, "lon": -2.7, "label": "Bristol Road, Somerset", "type": "road"},
|
||||
],
|
||||
}))
|
||||
page.route("**/api/stops?*", lambda route: route.fulfill(json={
|
||||
"kind": "location",
|
||||
|
|
@ -85,8 +87,12 @@ def test_search_and_stop_details_in_browser(chromium_browser: Any, flask_url: st
|
|||
page.get_by_label("Location or ATCO code").fill("Bristol")
|
||||
page.get_by_role("button", name="Search").click()
|
||||
playwright_api.expect(page).to_have_url(re.compile(r"\?q=Bristol$"))
|
||||
assert all(key in search_requests[-1] for key in ("west=", "south=", "east=", "north="))
|
||||
playwright_api.expect(page.get_by_text("2 UK matches for “Bristol”", exact=True)).to_be_visible()
|
||||
page.get_by_text("Bristol Centre", exact=True).click()
|
||||
playwright_api.expect(page).to_have_url(re.compile(r"\?lat=51.45&lon=-2.59$"))
|
||||
playwright_api.expect(page.get_by_text("Central Stop", exact=True)).to_be_visible()
|
||||
assert page.locator("#stop-list .stop-title").all_inner_texts() == ["Central Stop", "Far Stop"]
|
||||
assert page.locator("#stop-list .stop-title").all_inner_texts() == ["Central Stop", "Nearby Stop"]
|
||||
playwright_api.expect(page.locator("#stop-list .stop-meta").first).to_contain_text("m · Bus stop")
|
||||
playwright_api.expect(page.locator("#stop-list .stop-meta").first).to_contain_text("NW-bound")
|
||||
assert page.evaluate("map.getZoom()") > 6
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue