@@ -2415,6 +2415,75 @@ defmodule Dotcom.UpcomingDeparturesTest do
24152415 assert trip_details . stops_before |> Enum . map ( & & 1 . stop_id ) == [ stop_1 . id , stop_2 . id ]
24162416 end
24172417
2418+ test "drops all stops before the current vehicle" do
2419+ # Setup
2420+ % {
2421+ predicted_arrival_times: [ _ , _ , _ , arrival_time , _ ] ,
2422+ predictions: predictions ,
2423+ stop_sequences: [ _ , _ , _ , stop_seq , _ ] ,
2424+ stops: [ _stop_0 , _stop_1 , _stop_2 , stop , _ ] ,
2425+ trip_id: trip_id ,
2426+ vehicle: vehicle
2427+ } =
2428+ PredictedScheduleHelper . predicted_schedule_trip_data (
2429+ stop_count: 5 ,
2430+ vehicle_stop_index: 3
2431+ )
2432+
2433+ expect ( Predictions.Repo.Mock , :all , fn _ -> predictions end )
2434+ expect ( Schedules.Repo.Mock , :schedule_for_trip , fn ^ trip_id -> [ ] end )
2435+ expect ( Vehicles.Repo.Mock , :get , fn _ -> vehicle end )
2436+
2437+ # Exercise
2438+ trip_details =
2439+ UpcomingDepartures . trip_details ( % {
2440+ now: Generators.ServiceDateTime . earlier_on_day ( arrival_time ) ,
2441+ stop_id: stop . id ,
2442+ stop_sequence: stop_seq ,
2443+ trip_id: trip_id
2444+ } )
2445+
2446+ # Verify
2447+ assert trip_details . stops_before == [ ]
2448+ end
2449+
2450+ test "does not drop any stops if the vehicle is serving a different trip" do
2451+ # Setup
2452+ % {
2453+ predicted_arrival_times: [ _ , _ , _ , arrival_time , _ ] ,
2454+ predictions: predictions ,
2455+ stop_sequences: [ _ , _ , _ , stop_seq , _ ] ,
2456+ stops: [ stop_0 , stop_1 , stop_2 , stop , _ ] ,
2457+ trip_id: trip_id ,
2458+ vehicle: vehicle
2459+ } =
2460+ PredictedScheduleHelper . predicted_schedule_trip_data (
2461+ stop_count: 5 ,
2462+ vehicle_stop_index: 3 ,
2463+ vehicle_on_different_trip?: true
2464+ )
2465+
2466+ expect ( Predictions.Repo.Mock , :all , fn _ -> predictions end )
2467+ expect ( Schedules.Repo.Mock , :schedule_for_trip , fn ^ trip_id -> [ ] end )
2468+ expect ( Vehicles.Repo.Mock , :get , fn _ -> vehicle end )
2469+
2470+ # Exercise
2471+ trip_details =
2472+ UpcomingDepartures . trip_details ( % {
2473+ now: Generators.ServiceDateTime . earlier_on_day ( arrival_time ) ,
2474+ stop_id: stop . id ,
2475+ stop_sequence: stop_seq ,
2476+ trip_id: trip_id
2477+ } )
2478+
2479+ # Verify
2480+ assert trip_details . stops_before |> Enum . map ( & & 1 . stop_id ) == [
2481+ stop_0 . id ,
2482+ stop_1 . id ,
2483+ stop_2 . id
2484+ ]
2485+ end
2486+
24182487 test "shows a vehicle status of :scheduled_to_depart if the trip has no predictions and all schedules are in the future" do
24192488 # Setup
24202489 % {
0 commit comments