Proper handling for day train vs overnight train.

This commit is contained in:
Edward Betts 2026-07-08 09:12:08 +01:00
parent c6cb06b71e
commit 086bc630c9
2 changed files with 130 additions and 1 deletions

View file

@ -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