All files / api/trimet-client/src vehicleTripLegs.ts

100% Statements 4/4
100% Branches 20/20
100% Functions 3/3
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17          54x 67x                    
import type { VehicleTrip } from "./vehicleTrip";
 
export type VehicleTripProgressMode = "live" | "last-known" | "scheduled";
 
export function vehicleTripLegs(trip: VehicleTrip, mode: VehicleTripProgressMode) {
  const next = trip.stops.findIndex(stop => !stop.passed && stop.status !== "canceled");
  return trip.stops.slice(1).map((to, index) => ({
    from: trip.stops[index], to,
    passed: to.passed && to.status !== "canceled",
    current: index + 1 === next && mode === "live",
    status: to.status === "canceled" ? "Canceled stop" :
      to.passed ? mode === "live" ? "Passed" : mode === "last-known" ? "Passed (last report)" : "Scheduled past" :
        index + 1 === next ? mode === "live" ? "Current leg" : mode === "last-known" ? "Current at last report" : "Next scheduled leg" :
          "Upcoming",
  }));
}