From 086bc630c9e8ba844d076ce2c4c81aebf8b7402e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 8 Jul 2026 09:12:08 +0100 Subject: [PATCH] Proper handling for day train vs overnight train. --- templates/trip_page.html | 2 +- tests/test_trip_page_route.py | 129 ++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/templates/trip_page.html b/templates/trip_page.html index 16e92ff..7e873a7 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -361,7 +361,7 @@ CO₂ {{ "{:,.1f}".format(item.co2_kg) }} kg {% endif %} {% if item.coach %} - 🛏️ Coach {{ item.coach }}{% if item.seat %}, Seat {% if item.seat is iterable and item.seat is not string %}{{ item.seat | join(" & ") }}{% else %}{{ item.seat }}{% endif %}{% endif %} + {% if is_overnight %}🛏️{% else %}💺{% endif %} Coach {{ item.coach }}{% if item.seat %}, Seat {% if item.seat is iterable and item.seat is not string %}{{ item.seat | join(" & ") }}{% else %}{{ item.seat }}{% endif %}{% endif %} {% endif %}

diff --git a/tests/test_trip_page_route.py b/tests/test_trip_page_route.py index bf5e470..488870d 100644 --- a/tests/test_trip_page_route.py +++ b/tests/test_trip_page_route.py @@ -178,3 +178,132 @@ def test_trip_page_hides_train_times_for_date_only_train_leg() -> None: assert "Eurostar Plus" in page assert "00:00" not in page assert "🕒" not in page + + +def test_trip_page_uses_seat_icon_for_day_train_coach() -> None: + """Same-day train coach details should not use the sleeper bed icon.""" + trip = Trip( + start=date(2026, 2, 4), + travel=[ + { + "type": "train", + "depart": datetime(2026, 2, 4, 10, 0), + "arrive": datetime(2026, 2, 4, 12, 0), + "from": "London", + "to": "Manchester", + "from_station": { + "name": "London", + "country": "gb", + "latitude": 51.5, + "longitude": -0.1, + }, + "to_station": { + "name": "Manchester", + "country": "gb", + "latitude": 53.48, + "longitude": -2.24, + }, + "legs": [ + { + "from": "London", + "to": "Manchester", + "depart": datetime(2026, 2, 4, 10, 0), + "arrive": datetime(2026, 2, 4, 12, 0), + "from_station": { + "name": "London", + "country": "gb", + "latitude": 51.5, + "longitude": -0.1, + }, + "to_station": { + "name": "Manchester", + "country": "gb", + "latitude": 53.48, + "longitude": -2.24, + }, + "coach": "C", + "seat": 12, + } + ], + } + ], + ) + + with web_view.app.app_context(): + with ( + mock.patch.object(web_view, "get_trip_list", return_value=[trip]), + mock.patch.object(agenda.weather, "get_trip_weather", return_value=[]), + ): + web_view.app.config["TESTING"] = True + + with web_view.app.test_client() as client: + response = client.get("/trip/2026-02-04") + + assert response.status_code == 200 + page = response.data.decode() + assert "💺 Coach C, Seat 12" in page + assert "🛏️ Coach C, Seat 12" not in page + + +def test_trip_page_uses_bed_icon_for_overnight_train_coach() -> None: + """Overnight train coach details keep the sleeper bed icon.""" + trip = Trip( + start=date(2026, 2, 4), + travel=[ + { + "type": "train", + "depart": datetime(2026, 2, 4, 22, 0), + "arrive": datetime(2026, 2, 5, 7, 0), + "from": "London", + "to": "Edinburgh", + "from_station": { + "name": "London", + "country": "gb", + "latitude": 51.5, + "longitude": -0.1, + }, + "to_station": { + "name": "Edinburgh", + "country": "gb", + "latitude": 55.95, + "longitude": -3.19, + }, + "legs": [ + { + "from": "London", + "to": "Edinburgh", + "depart": datetime(2026, 2, 4, 22, 0), + "arrive": datetime(2026, 2, 5, 7, 0), + "from_station": { + "name": "London", + "country": "gb", + "latitude": 51.5, + "longitude": -0.1, + }, + "to_station": { + "name": "Edinburgh", + "country": "gb", + "latitude": 55.95, + "longitude": -3.19, + }, + "coach": "S", + "seat": 4, + } + ], + } + ], + ) + + with web_view.app.app_context(): + with ( + mock.patch.object(web_view, "get_trip_list", return_value=[trip]), + mock.patch.object(agenda.weather, "get_trip_weather", return_value=[]), + ): + web_view.app.config["TESTING"] = True + + with web_view.app.test_client() as client: + response = client.get("/trip/2026-02-04") + + assert response.status_code == 200 + page = response.data.decode() + assert "🛏️ Coach S, Seat 4" in page