Skip to content

Commit

Permalink
feat: no service state inferred via route patterns
Browse files Browse the repository at this point in the history
- show "No service today" in departure card
- show "No service today, (date)" in departure list
  • Loading branch information
thecristen committed Oct 30, 2023
1 parent a070329 commit 9834fff
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 25 deletions.
27 changes: 27 additions & 0 deletions apps/site/assets/ts/stop/__tests__/DepartureListTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"Cucamonga"}
alerts={[]}
hasService={true}
/>
);
expect(screen.queryAllByRole("listitem")).toHaveLength(predictions.length);
Expand All @@ -83,6 +84,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"Atlantis"}
alerts={[]}
hasService={true}
/>
);

Expand All @@ -101,6 +103,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"Disney"}
alerts={[]}
hasService={true}
/>
);

Expand All @@ -119,6 +122,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"Bermuda"}
alerts={[]}
hasService={true}
/>
);
expect(
Expand Down Expand Up @@ -161,6 +165,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"San Fransokyo"}
alerts={alerts}
hasService={true}
/>
);

Expand All @@ -179,6 +184,7 @@ describe("DepartureList", () => {
directionId={0}
headsign={"Gotham"}
alerts={[]}
hasService={true}
/>
);
expect(
Expand All @@ -195,6 +201,7 @@ describe("DepartureList", () => {
departures={[]}
directionId={0}
headsign="Riverdale"
hasService={true}
/>
);
expect(screen.getByText("No upcoming trips today")).toBeDefined();
Expand Down Expand Up @@ -225,6 +232,7 @@ describe("DepartureList", () => {
departures={mergeIntoDepartureInfo(schedules, predictions)}
directionId={0}
headsign="Smallville"
hasService={true}
/>
);
expect(screen.getByText("Cancelled")).toBeInTheDocument();
Expand Down Expand Up @@ -265,6 +273,7 @@ describe("DepartureList", () => {
directionId={0}
headsign="Emerald City"
targetDate={new Date("2022-04-27T11:00:00-04:00")}
hasService={true}
/>
);
expect(screen.queryByText("Cancelled")).not.toBeInTheDocument();
Expand Down Expand Up @@ -292,8 +301,26 @@ describe("DepartureList", () => {
directionId={0}
headsign="Emerald City"
targetDate={new Date("2022-04-27T11:00:00-04:00")}
hasService={true}
/>
);
expect(screen.queryAllByRole("listitem")).toHaveLength(departures.length);
});

it("can show no service message", () => {
const expectedMessage = "No service today";
render(
<DepartureList
route={route}
stop={stop}
departures={mergeIntoDepartureInfo(schedules, [])}
directionId={0}
headsign={"Atlantis"}
alerts={[]}
hasService={false}
/>
);

expect(screen.findByText(expectedMessage)).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[]}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -80,6 +81,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[]}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -116,6 +118,7 @@ describe("DepartureTimes", () => {
alertsForDirection={alerts}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -154,6 +157,7 @@ describe("DepartureTimes", () => {
alertsForDirection={alerts}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -205,6 +209,7 @@ describe("DepartureTimes", () => {
overrideDate={dateToCompare}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -357,6 +362,7 @@ describe("DepartureTimes", () => {
overrideDate={compareTime}
isCR={false}
onClick={setRowSpy}
hasService={true}
/>
);

Expand Down Expand Up @@ -442,6 +448,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[]}
isCR={true}
onClick={jest.fn()}
hasService={true}
/>
);

Expand All @@ -460,6 +467,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[]}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand All @@ -482,6 +490,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[closureAlert]}
isCR={true}
onClick={jest.fn()}
hasService={true}
/>
);
await waitFor(() => {
Expand All @@ -504,6 +513,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[closureAlert]}
isCR={false}
onClick={jest.fn()}
hasService={true}
/>
);

Expand All @@ -512,4 +522,21 @@ describe("DepartureTimes", () => {
expect(screen.getByText("See alternatives")).toBeInTheDocument();
});
});

it("can show no service message", async () => {
const expectedMessage = "No service today";
renderWithRouter(
<DepartureTimes
headsign="Some place"
departures={[]}
alertsForDirection={[]}
isCR={false}
onClick={jest.fn()}
hasService={false}
/>
);
await waitFor(() => {
expect(screen.findByText(expectedMessage)).toBeDefined();
});
});
});
1 change: 1 addition & 0 deletions apps/site/assets/ts/stop/components/DepartureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DepartureCard = ({
)}
onClick={onClick}
isCR={isACommuterRailRoute(route)}
hasService={routePatterns.length !== 0}
/>
);
}
Expand Down
33 changes: 20 additions & 13 deletions apps/site/assets/ts/stop/components/DepartureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import renderSvg from "../../helpers/render-svg";
import { isSuppressiveAlert } from "../../models/alert";
import Alerts from "../../components/Alerts";
import { isACommuterRailRoute } from "../../models/route";
import { todayDateString } from "../../helpers/date";

interface DepartureListProps {
route: Route;
Expand All @@ -17,13 +18,16 @@ interface DepartureListProps {
directionId: DirectionId;
headsign: string;
alerts: Alert[];
hasService: boolean;
targetDate?: Date | undefined;
}

const displayNoUpcomingTrips = (): JSX.Element => {
const displayNoUpcomingTrips = (
message = "No upcoming trips today"
): JSX.Element => {
return (
<div className="c-alert-item--low m-8 d-flex justify-content-center align-items-center pb-40 pt-40">
No upcoming trips today
{message}
</div>
);
};
Expand All @@ -35,6 +39,7 @@ const DepartureList = ({
directionId,
headsign,
alerts,
hasService,
targetDate
}: DepartureListProps): ReactElement<HTMLElement> => {
const isCR = isACommuterRailRoute(route);
Expand All @@ -52,6 +57,13 @@ const DepartureList = ({
const tripForSelectedRoutePattern: Trip | undefined =
modeSpecificDepartures[0]?.trip;

const noTrips =
modeSpecificDepartures.length === 0 && displayNoUpcomingTrips();
const noService =
!hasService &&
displayNoUpcomingTrips(`No service today, ${todayDateString()}`);
const noServiceOrNoTrips = noService || noTrips;

return (
<>
<div className="stop-departures departure-list-header">
Expand All @@ -74,17 +86,12 @@ const DepartureList = ({
<div className="departure-list__headsign">{headsign}</div>
</h2>
{alerts.length ? <Alerts alerts={alerts} /> : null}
{modeSpecificDepartures.length === 0
? displayNoUpcomingTrips()
: !alertsShouldSuppressDepartures && (
<ul className="stop-routes__departures list-unstyled">
{departuresListFromInfos(
modeSpecificDepartures,
isCR,
targetDate
)}
</ul>
)}
{noServiceOrNoTrips ||
(!alertsShouldSuppressDepartures && (
<ul className="stop-routes__departures list-unstyled">
{departuresListFromInfos(modeSpecificDepartures, isCR, targetDate)}
</ul>
))}
</>
);
};
Expand Down
32 changes: 20 additions & 12 deletions apps/site/assets/ts/stop/components/DepartureTimes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface DepartureTimesProps {
headsign: string;
onClick: () => void;
isCR: boolean;
hasService: boolean;
// override date primarily used for testing
overrideDate?: Date;
}
Expand Down Expand Up @@ -50,6 +51,7 @@ const DepartureTimes = ({
headsign,
onClick,
isCR,
hasService,
overrideDate
}: DepartureTimesProps): ReactElement<HTMLElement> | null => {
const timeList = departuresListFromInfos(
Expand All @@ -66,18 +68,24 @@ const DepartureTimes = ({
return (
<ClickableDepartureRow onClick={onClick} headsignName={headsign}>
<div className="departure-card__content">
<DeparturesWithBadge
alerts={alertsForDirection}
departuresLength={departures.length}
>
{timeList.length > 0 ? (
<div className="departure-card__times">{timeList}</div>
) : (
<div className="font-helvetica-neue fs-14 u-nowrap">
No upcoming trips
</div>
)}
</DeparturesWithBadge>
{hasService ? (
<DeparturesWithBadge
alerts={alertsForDirection}
departuresLength={departures.length}
>
{timeList.length > 0 ? (
<div className="departure-card__times">{timeList}</div>
) : (
<div className="font-helvetica-neue fs-14 u-nowrap">
No upcoming trips
</div>
)}
</DeparturesWithBadge>
) : (
<div className="font-helvetica-neue fs-14 u-nowrap">
No service today
</div>
)}
</div>
</ClickableDepartureRow>
);
Expand Down
1 change: 1 addition & 0 deletions apps/site/assets/ts/stop/components/DeparturesAndMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const DeparturesAndMap = ({
directionId={activeRow.directionId}
headsign={activeRow.headsign}
alerts={realtimeAlerts}
hasService={routePatternsForSelection.length !== 0}
/>
</div>
) : (
Expand Down

0 comments on commit 9834fff

Please sign in to comment.