Improve progressive results loading

This commit is contained in:
Edward Betts 2026-05-21 09:52:58 +01:00
parent 9691632f65
commit 378d2484d0
6 changed files with 369 additions and 60 deletions

View file

@ -1,4 +1,7 @@
from datetime import datetime
import app as app_module
import trip_planner as trip_planner_module
def _client():
@ -72,7 +75,7 @@ def test_search_redirects_return_with_return_date():
assert resp.status_code == 302
assert resp.headers['Location'].endswith(
'/results/BRI/paris/2026-04-10?journey_type=return&return_date=2026-04-17'
'/results/BRI/paris/2026-04-10/return/2026-04-17'
)
@ -91,6 +94,23 @@ def test_results_shows_same_day_destination_switcher(monkeypatch):
assert 'ES 9014' in html
def test_results_progressive_shell_loads_without_scraping(monkeypatch):
def fail_fetch(*args, **kwargs):
raise AssertionError("progressive shell should not fetch data")
monkeypatch.setattr(app_module.rtt_scraper, 'fetch', fail_fetch)
monkeypatch.setattr(app_module.eurostar_scraper, 'fetch', fail_fetch)
monkeypatch.setattr(app_module.gwr_fares_scraper, 'fetch', fail_fetch)
client = _client()
resp = client.get('/results/BRI/paris/2026-04-10?progressive=1')
html = resp.get_data(as_text=True)
assert resp.status_code == 200
assert 'Loading train times and fares' in html
assert 'render=full' in html
def test_results_title_and_social_meta_include_destination(monkeypatch):
_stub_data(monkeypatch)
client = _client()
@ -380,14 +400,39 @@ def test_results_return_renders_outbound_and_inbound_tables(monkeypatch):
],
},
)
monkeypatch.setattr(
trip_planner_module.circle_line,
'upcoming_services',
lambda earliest_board, count=2, direction='pad_to_kx': (
[
(datetime(2026, 4, 10, 9, 10), datetime(2026, 4, 10, 9, 25)),
(datetime(2026, 4, 10, 9, 15), datetime(2026, 4, 10, 9, 30)),
]
if direction == 'pad_to_kx'
else [
(datetime(2026, 4, 17, 16, 40), datetime(2026, 4, 17, 16, 55)),
(datetime(2026, 4, 17, 16, 45), datetime(2026, 4, 17, 17, 0)),
]
),
)
client = _client()
resp = client.get('/results/BRI/paris/2026-04-10?journey_type=return&return_date=2026-04-17')
resp = client.get('/results/BRI/paris/2026-04-10/return/2026-04-17')
html = resp.get_data(as_text=True)
assert resp.status_code == 200
assert 'Outbound: Bristol Temple Meads → Paris Gare du Nord' in html
assert 'Return: Paris Gare du Nord → Bristol Temple Meads' in html
assert '/results/BRI/paris/2026-04-09/return/2026-04-17' in html
assert '/results/BRI/paris/2026-04-11/return/2026-04-17' in html
assert "/results/BRI/paris/2026-04-10/return/2026-04-17" in html
assert 'journey_type=return' not in html
assert 'return_date=2026-04-17' not in html
assert 'Circle 09:10 → KX 09:25' in html
assert 'next 09:15 → KX 09:30' in html
assert 'Circle 16:40 → PAD 16:55' in html
assert 'next 16:45 → PAD 17:00' in html
assert 'title="Tight connection">⚠️</span>' in html
assert 'ES 9014' in html
assert 'ES 9035' in html