From af0ae9eb29a97da21a070e64c8a6e2ef93b6c840 Mon Sep 17 00:00:00 2001 From: Ryan Kotval Date: Fri, 29 Sep 2023 12:05:57 -0500 Subject: [PATCH] fix(ScheduleFinder): Upcoming Departure rows doesn't show skipped trips (#1753) --- .../daily-schedule/TripDetails.tsx | 6 ++- .../upcoming-departures/TripDetails.tsx | 7 +++- .../__tests__/TripDetailsTest.tsx | 37 ++++++++++++++++++- .../__snapshots__/TripDetailsTest.tsx.snap | 12 ++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/apps/site/assets/ts/schedule/components/schedule-finder/daily-schedule/TripDetails.tsx b/apps/site/assets/ts/schedule/components/schedule-finder/daily-schedule/TripDetails.tsx index adf00a90f7..f4e0bccb55 100644 --- a/apps/site/assets/ts/schedule/components/schedule-finder/daily-schedule/TripDetails.tsx +++ b/apps/site/assets/ts/schedule/components/schedule-finder/daily-schedule/TripDetails.tsx @@ -105,7 +105,11 @@ const TripDetailsTable = ({ /> )) ) : ( - + + + + + )} diff --git a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/TripDetails.tsx b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/TripDetails.tsx index fdc3a5bde5..a84647bbc4 100644 --- a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/TripDetails.tsx +++ b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/TripDetails.tsx @@ -14,7 +14,9 @@ interface Props { const hasAPrediction = ( departure: TripDeparture -): departure is TripDepartureWithPrediction => departure.prediction !== null; +): departure is TripDepartureWithPrediction => + departure.prediction !== null && + departure.prediction.schedule_relationship !== "skipped"; const departuresWithPredictions = ( departures: TripDeparture[] @@ -31,7 +33,8 @@ const TripSummary = ({ Trip length - {tripInfo.times.length} stops, {tripInfo.duration} minutes total + {departuresWithPredictions(tripInfo.times).length} stops,{" "} + {tripInfo.duration} minutes total
diff --git a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/TripDetailsTest.tsx b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/TripDetailsTest.tsx index ac8f0b9af1..2de6ab5811 100644 --- a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/TripDetailsTest.tsx +++ b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/TripDetailsTest.tsx @@ -1,5 +1,6 @@ import React from "react"; import renderer from "react-test-renderer"; +import { render, screen } from "@testing-library/react"; import { createReactRoot } from "../../../../../app/helpers/testUtils"; import { TripInfo } from "../../../__trips"; import CrowdingPill from "../../../line-diagram/CrowdingPill"; @@ -8,7 +9,6 @@ import crTripDataWithDelays from "../../__tests__/test-data/crTripInfoWithDelays import tripData from "../../__tests__/test-data/tripInfo.json"; import tripDataWithPredictions from "../../__tests__/test-data/tripInfoWithPredictions.json"; import TripDetails from "../TripDetails"; -import { render, screen } from "@testing-library/react"; const tripInfo: TripInfo = (tripData as unknown) as TripInfo; const crTripInfo: TripInfo = (crTripData as unknown) as TripInfo; @@ -78,4 +78,39 @@ describe("TripDetails", () => { "some_crowding" ); }); + + it("does not render a prediction that is skipped", () => { + const testInfo = { + times: [ + { + schedule: { stop: { id: "TestStop1", name: "Test Stop 1" } }, + prediction: { + stop: { id: "TestStop1", name: "Test Stop 1" }, + time: "11:25 AM", + schedule_relationship: "skipped" + } + }, + { + schedule: { stop: { id: "TestStop2", name: "Test Stop 2" } }, + prediction: { + stop: { id: "TestStop1", name: "Test Stop 2" }, + time: "11:35 AM", + schedule_relationship: null + } + } + ], + route_type: 1, + fare: { + price: "$2.40", + fare_link: "/fares/subway-fares" + }, + duration: 37 + }; + + render(); + + expect(screen.queryByText("11:25 AM")).toBeNull(); + expect(screen.queryByText("11:35 AM")).toBeInTheDocument(); + expect(screen.queryByText("1 stops")); + }); }); diff --git a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/__snapshots__/TripDetailsTest.tsx.snap b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/__snapshots__/TripDetailsTest.tsx.snap index 376d24e3ae..87035e4258 100644 --- a/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/__snapshots__/TripDetailsTest.tsx.snap +++ b/apps/site/assets/ts/schedule/components/schedule-finder/upcoming-departures/__tests__/__snapshots__/TripDetailsTest.tsx.snap @@ -19,7 +19,8 @@ exports[`TripDetails displays both scheduled and predicted times for CR if there Trip length 7 - stops, + stops, + 56 minutes total
@@ -236,7 +237,8 @@ exports[`TripDetails it renders trip details for a CR trip 1`] = ` Trip length 10 - stops, + stops, + 69 minutes total @@ -531,7 +533,8 @@ exports[`TripDetails it renders trip details for a bus trip 1`] = ` Trip length 11 - stops, + stops, + 14 minutes total @@ -788,7 +791,8 @@ exports[`TripDetails uses a predicted departure time in preference to a schedule Trip length 39 - stops, + stops, + 32 minutes total