Skip to content

Commit

Permalink
Show "No real-time data" when no predictions (#2084)
Browse files Browse the repository at this point in the history
* show message when no predictions

* fix issue with orange line schedule

* change var names

* add css to align visuals
  • Loading branch information
anthonyshull authored May 31, 2024
1 parent 7789656 commit abda48d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 11 deletions.
23 changes: 21 additions & 2 deletions assets/css/_stop-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ $radius: 4px;
// on mobile, adopt a full-screen "app" view,
// this is the scrollable section
@include media-breakpoint-down(sm) {
-webkit-overflow-scrolling: touch;
overflow-y: scroll;
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
}
}

Expand All @@ -102,9 +102,9 @@ $radius: 4px;
@include media-breakpoint-down(sm) {
bottom: 0;
display: grid;
left: 0;
gap: 0;
grid-template-rows: auto 1fr;
left: 0;
padding-bottom: 0;
padding-top: 0;
position: fixed;
Expand Down Expand Up @@ -425,3 +425,22 @@ $radius: 4px;
margin: 0;
}
}

.departure-card__times {
.no-real-time-data {
@extend .font-helvetica-neue;
@extend .fs-14;
}
}

.stop-departures--realtime {
.no-real-time-data {
@extend .align-items-center;
@extend .c-alert-item--low;
@extend .d-flex;
@extend .justify-content-center;
@extend .m-8;
@extend .pb-40;
@extend .pt-40;
}
}
13 changes: 10 additions & 3 deletions assets/ts/helpers/__tests__/departureInfoTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("departureInfo", () => {

describe("departuresListFromInfos", () => {
it("can handle no departures", () => {
render(<ul>{departuresListFromInfos([], false)}</ul>);
render(<ul>{departuresListFromInfos([], false, false)}</ul>);

// no <li> created
expect(screen.queryByRole("listitem")).toBeNull();
Expand All @@ -121,6 +121,7 @@ describe("departureInfo", () => {
{departuresListFromInfos(
departures,
false,
false,
undefined,
undefined,
false,
Expand All @@ -147,7 +148,13 @@ describe("departureInfo", () => {
const customLength = 4;
render(
<ul>
{departuresListFromInfos(departures, false, undefined, customLength)}
{departuresListFromInfos(
departures,
false,
false,
undefined,
customLength
)}
</ul>
);

Expand Down Expand Up @@ -186,7 +193,7 @@ describe("departureInfo", () => {
} as DepartureInfo;
});

render(<ul>{departuresListFromInfos(departures, false)}</ul>);
render(<ul>{departuresListFromInfos(departures, false, false)}</ul>);

// the schedule-only departures at index positions 2, 4, 7 should have been removed
expect(screen.queryAllByRole("listitem")).toHaveLength(
Expand Down
12 changes: 12 additions & 0 deletions assets/ts/helpers/departureInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const DefaultWrapper: React.FunctionComponent<unknown> = ({ children }) => (
const departuresListFromInfos = (
departureInfos: DepartureInfo[],
isCR: boolean,
isSubway: boolean,
targetDate?: Date,
listLength?: number,
omitCancelledAndSkipped = false,
Expand All @@ -164,6 +165,17 @@ const departuresListFromInfos = (
.maxBy("prediction.time")
.value()?.prediction!.time;

const routeId = departureInfos[0]?.route?.id;
const tripId = departureInfos[0]?.trip?.id;

if (isSubway && !predictionTimeCutoff) {
return [
<div className="no-real-time-data" key={`${routeId}-${tripId}`}>
No real-time data
</div>
];
}

return chain(departureInfos)
.reject(
departure =>
Expand Down
11 changes: 11 additions & 0 deletions assets/ts/stop/__tests__/components/DepartureTimesTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={[]}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand Down Expand Up @@ -80,6 +81,7 @@ describe("DepartureTimes", () => {
overrideDate={dateToCompare}
alertsForDirection={[]}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand Down Expand Up @@ -117,6 +119,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={alerts}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand Down Expand Up @@ -156,6 +159,7 @@ describe("DepartureTimes", () => {
departures={mergeIntoDepartureInfo(schedules, [])}
alertsForDirection={alerts}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand Down Expand Up @@ -208,6 +212,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[detourAlert] as Alert[]}
overrideDate={dateToCompare}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand Down Expand Up @@ -361,6 +366,7 @@ describe("DepartureTimes", () => {
alertsForDirection={[]}
overrideDate={compareTime}
isCR={false}
isSubway={false}
onClick={setRowSpy}
hasService={true}
/>
Expand Down Expand Up @@ -447,6 +453,7 @@ describe("DepartureTimes", () => {
overrideDate={dateToCompare}
alertsForDirection={[]}
isCR={true}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand All @@ -466,6 +473,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={[]}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand All @@ -489,6 +497,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={[closureAlert]}
isCR={true}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand All @@ -512,6 +521,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={[closureAlert]}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={true}
/>
Expand All @@ -531,6 +541,7 @@ describe("DepartureTimes", () => {
departures={[]}
alertsForDirection={[]}
isCR={false}
isSubway={false}
onClick={jest.fn()}
hasService={false}
/>
Expand Down
1 change: 1 addition & 0 deletions assets/ts/stop/components/DepartureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const DepartureCard = ({
)}
onClick={onClick}
isCR={isACommuterRailRoute(route)}
isSubway={isSubwayRoute(route)}
hasService={routePatterns.length !== 0}
/>
);
Expand Down
10 changes: 8 additions & 2 deletions assets/ts/stop/components/DepartureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { routeName, routeToModeIcon } from "../../helpers/route-headers";
import renderSvg from "../../helpers/render-svg";
import { isSuppressiveAlert } from "../../models/alert";
import Alerts from "../../components/Alerts";
import { isACommuterRailRoute } from "../../models/route";
import { isACommuterRailRoute, isSubwayRoute } from "../../models/route";

interface DepartureListProps {
route: Route;
Expand Down Expand Up @@ -42,6 +42,7 @@ const DepartureList = ({
targetDate
}: DepartureListProps): ReactElement<HTMLElement> => {
const isCR = isACommuterRailRoute(route);
const isSubway = isSubwayRoute(route);

// don's show cancelled departures for subway
const modeSpecificDepartures: DepartureInfo[] = filter(
Expand Down Expand Up @@ -87,7 +88,12 @@ const DepartureList = ({
{noServiceOrNoTrips ||
(!alertsShouldSuppressDepartures && (
<ul className="stop-routes__departures list-unstyled">
{departuresListFromInfos(modeSpecificDepartures, isCR, targetDate)}
{departuresListFromInfos(
modeSpecificDepartures,
isCR,
isSubway,
targetDate
)}
</ul>
))}
</>
Expand Down
3 changes: 3 additions & 0 deletions 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;
isSubway: boolean;
hasService: boolean;
// override date primarily used for testing
overrideDate?: Date;
Expand Down Expand Up @@ -51,12 +52,14 @@ const DepartureTimes = ({
headsign,
onClick,
isCR,
isSubway,
hasService,
overrideDate
}: DepartureTimesProps): ReactElement<HTMLElement> | null => {
const timeList = departuresListFromInfos(
departures,
isCR,
isSubway,
overrideDate,
isCR ? 1 : 2,
true,
Expand Down
8 changes: 4 additions & 4 deletions integration/scenarios/view-subway-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ exports.scenario = async ({ page, baseURL }) => {

// Get the first and last stop names
const first = await page
.locator("h4.m-schedule-diagram__stop-link a span")
.locator("h4.m-schedule-diagram__stop-link a span:last-child")
.first()
.textContent();
const last = await page
.locator("h4.m-schedule-diagram__stop-link a span")
.locator("h4.m-schedule-diagram__stop-link a span:last-child")
.last()
.textContent();

await page.locator("button.m-schedule-direction__button").click();

// Expect them to be reversed after clicking the direction filter
await expect(
page.locator("h4.m-schedule-diagram__stop-link a span").first(),
page.locator("h4.m-schedule-diagram__stop-link a span:last-child").first(),
).toHaveText(last);
await expect(
page.locator("h4.m-schedule-diagram__stop-link a span").last(),
page.locator("h4.m-schedule-diagram__stop-link a span:last-child").last(),
).toHaveText(first);
};

0 comments on commit abda48d

Please sign in to comment.