Skip to content

Commit

Permalink
fix(ScheduleFinder): Upcoming Departure rows doesn't show skipped tri…
Browse files Browse the repository at this point in the history
…ps (#1753)
  • Loading branch information
kotva006 authored Sep 29, 2023
1 parent f0593d4 commit af0ae9e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ const TripDetailsTable = ({
/>
))
) : (
<ErrorLoadingTrip />
<tr>
<td>
<ErrorLoadingTrip />
</td>
</tr>
)}
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -31,7 +33,8 @@ const TripSummary = ({
<span className="trip-details-table__title u-small-caps u-bold">
Trip length
</span>
{tripInfo.times.length} stops, {tripInfo.duration} minutes total
{departuresWithPredictions(tripInfo.times).length} stops,{" "}
{tripInfo.duration} minutes total
</div>
<div>
<span className="trip-details-table__title u-small-caps u-bold">
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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(<TripDetails tripInfo={testInfo as any} showFare={false} />);

expect(screen.queryByText("11:25 AM")).toBeNull();
expect(screen.queryByText("11:35 AM")).toBeInTheDocument();
expect(screen.queryByText("1 stops"));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exports[`TripDetails displays both scheduled and predicted times for CR if there
Trip length
</span>
7
stops,
stops,
56
minutes total
</div>
Expand Down Expand Up @@ -236,7 +237,8 @@ exports[`TripDetails it renders trip details for a CR trip 1`] = `
Trip length
</span>
10
stops,
stops,
69
minutes total
</div>
Expand Down Expand Up @@ -531,7 +533,8 @@ exports[`TripDetails it renders trip details for a bus trip 1`] = `
Trip length
</span>
11
stops,
stops,
14
minutes total
</div>
Expand Down Expand Up @@ -788,7 +791,8 @@ exports[`TripDetails uses a predicted departure time in preference to a schedule
Trip length
</span>
39
stops,
stops,
32
minutes total
</div>
Expand Down

0 comments on commit af0ae9e

Please sign in to comment.