-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
275 additions
and
18 deletions.
There are no files selected for viewing
266 changes: 266 additions & 0 deletions
266
apps/site/assets/ts/stop/__tests__/DeparturesAndMapShuttleTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
import React from "react"; | ||
import { screen, waitFor } from "@testing-library/react"; | ||
import DeparturesAndMap from "../components/DeparturesAndMap"; | ||
import { Stop, Route } from "../../__v3api"; | ||
import { renderWithRouter } from "./helpers"; | ||
import * as useSchedules from "../../hooks/useSchedules"; | ||
import { ScheduleWithTimestamp } from "../../models/schedules"; | ||
import { add } from "date-fns"; | ||
import * as useVehiclesChannel from "../../hooks/useVehiclesChannel"; | ||
import { FetchStatus } from "../../helpers/use-fetch"; | ||
import * as usePredictionsChannel from "../../hooks/usePredictionsChannel"; | ||
import { PredictionWithTimestamp } from "../../models/predictions"; | ||
|
||
const stop = { | ||
id: "test-stop", | ||
name: "Test Stop", | ||
latitude: 42.3519, | ||
longitude: 71.0552 | ||
} as Stop; | ||
const now = Date.now(); | ||
|
||
const crRoute = { | ||
type: 2, | ||
name: "Framingham/Worcester Line", | ||
long_name: "Framingham/Worcester Line", | ||
line: { | ||
type: "line", | ||
id: "line-Worcester" | ||
}, | ||
id: "CR-Worcester", | ||
direction_names: { | ||
"0": "Outbound", | ||
"1": "Inbound" | ||
}, | ||
direction_destinations: { | ||
"0": "Worcester", | ||
"1": "South Station" | ||
}, | ||
description: "commuter_rail" | ||
}; | ||
const railReplacementRoute = { | ||
type: 3, | ||
name: "Worcester Line Shuttle", | ||
long_name: "Ashland - Framingham", | ||
line: { | ||
type: "line", | ||
id: "line-Worcester" | ||
}, | ||
id: "Shuttle-AshlandFramingham", | ||
direction_names: { | ||
"0": "Outbound", | ||
"1": "Inbound" | ||
}, | ||
direction_destinations: { | ||
"0": "Worcester", | ||
"1": "South Station" | ||
}, | ||
description: "rail_replacement_bus" | ||
}; | ||
const rapidTransitRoute = { | ||
type: 1, | ||
name: "Test Rapid Transit", | ||
long_name: "Test Rapid Transit Line", | ||
line: { | ||
type: "line", | ||
id: "line-rapid-transit" | ||
}, | ||
id: "Test-Rapid-Line", | ||
direction_names: { | ||
"0": "Outbound", | ||
"1": "Inbound" | ||
}, | ||
direction_destinations: { | ||
"0": "Test North Station", | ||
"1": "Test South Station" | ||
}, | ||
description: "rapid_transit" | ||
}; | ||
|
||
const rapidTransitShuttleRoute = { | ||
type: 3, | ||
name: "Test Rapid Transit (Shuttle)", | ||
long_name: "Test Rapid Transit (Shuttle) Line", | ||
line: { | ||
type: "line", | ||
id: "line-rapid-transit" | ||
}, | ||
id: "Shuttle-Test-Rapid-Line", | ||
direction_names: { | ||
"0": "Outbound", | ||
"1": "Inbound" | ||
}, | ||
direction_destinations: { | ||
"0": "Test North Station", | ||
"1": "Test South Station" | ||
}, | ||
description: "rail_replacement_bus" | ||
}; | ||
|
||
const groupedRoutePatterns = { | ||
"Shuttle-AshlandFramingham": { | ||
"Ashland (Shuttle)": [ | ||
{ | ||
headsign: "Ashland (Shuttle)", | ||
id: "ashland-shuttle", | ||
route_id: railReplacementRoute.id, | ||
direction_id: 1, | ||
representative_trip_polyline: { | ||
id: "1" | ||
} | ||
} | ||
] | ||
}, | ||
"CR-Worcester": { | ||
"North Station": [ | ||
{ | ||
headsign: "North Station", | ||
id: "north-station", | ||
route_id: crRoute.id, | ||
direction_id: 1, | ||
representative_trip_polyline: { | ||
id: "2" | ||
} | ||
} | ||
], | ||
"South Station": [ | ||
{ | ||
headsign: "South Station", | ||
id: "south-station", | ||
route_id: crRoute.id, | ||
direction_id: 1, | ||
representative_trip_polyline: { | ||
id: "3" | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
const groupedRapidTransitRoutePatterns = { | ||
"Shuttle-Test-Rapid-Line": { | ||
"Rapid (Shuttle)": [ | ||
{ | ||
headsign: "Rapid (Shuttle)", | ||
id: "rapid-shuttle", | ||
route_id: rapidTransitShuttleRoute.id, | ||
direction_id: 1, | ||
representative_trip_polyline: { | ||
id: "1" | ||
} | ||
} | ||
] | ||
}, | ||
"Test-Rapid-Line": { | ||
"Test North Station": [ | ||
{ | ||
headsign: "North Station", | ||
id: "north-station", | ||
route_id: rapidTransitRoute.id, | ||
direction_id: 1, | ||
representative_trip_polyline: { | ||
id: "2" | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
jest.mock("../components/StopMapRedesign", () => ({ | ||
__esModule: true, | ||
default: () => <div>Stop Map</div> | ||
})); | ||
|
||
describe("DeparturesAndMap", () => { | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it("should merge the rail replacement shuttles into the commuter rail cards", async () => { | ||
jest.spyOn(useVehiclesChannel, "default").mockReturnValue([]); | ||
jest | ||
.spyOn(usePredictionsChannel, "default") | ||
.mockReturnValue([] as PredictionWithTimestamp[]); | ||
|
||
const schedules = [ | ||
{ | ||
route: crRoute, | ||
stop: stop, | ||
trip: { id: "1", headsign: "Worcester", direction_id: 1 }, | ||
time: add(now, { minutes: 10 }) | ||
}, | ||
{ | ||
route: railReplacementRoute, | ||
stop: stop, | ||
trip: { id: "2", headsign: "Worcester (Shuttle)", direction_id: 0 }, | ||
time: add(now, { minutes: 15 }) | ||
} | ||
] as ScheduleWithTimestamp[]; | ||
|
||
jest | ||
.spyOn(useSchedules, "useSchedulesByStop") | ||
.mockReturnValue({ status: FetchStatus.Data, data: schedules }); | ||
|
||
const routes = [crRoute, railReplacementRoute] as Route[]; | ||
|
||
renderWithRouter( | ||
<DeparturesAndMap | ||
routes={routes} | ||
stop={stop} | ||
alerts={[]} | ||
setPredictionError={jest.fn()} | ||
/>, | ||
[], | ||
groupedRoutePatterns | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Ashland (Shuttle)")).toBeInTheDocument(); | ||
expect(screen.queryByText("Worcester Line Shuttle")).toBeNull(); | ||
}); | ||
}); | ||
|
||
it("should not show the rapid tranist shuttle routes", async () => { | ||
jest.spyOn(useVehiclesChannel, "default").mockReturnValue([]); | ||
jest | ||
.spyOn(usePredictionsChannel, "default") | ||
.mockReturnValue([] as PredictionWithTimestamp[]); | ||
|
||
const schedules = [ | ||
{ | ||
route: rapidTransitRoute, | ||
stop: stop, | ||
trip: { id: "1", headsign: "Worcester", direction_id: 1 }, | ||
time: add(now, { minutes: 10 }) | ||
}, | ||
{ | ||
route: rapidTransitShuttleRoute, | ||
stop: stop, | ||
trip: { id: "2", headsign: "Worcester (Shuttle)", direction_id: 0 }, | ||
time: add(now, { minutes: 15 }) | ||
} | ||
] as ScheduleWithTimestamp[]; | ||
|
||
jest | ||
.spyOn(useSchedules, "useSchedulesByStop") | ||
.mockReturnValue({ status: FetchStatus.Data, data: schedules }); | ||
|
||
const routes = [rapidTransitRoute, rapidTransitShuttleRoute] as Route[]; | ||
|
||
renderWithRouter( | ||
<DeparturesAndMap | ||
routes={routes} | ||
stop={stop} | ||
alerts={[]} | ||
setPredictionError={jest.fn()} | ||
/>, | ||
[], | ||
groupedRapidTransitRoutePatterns | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Test North Station")).toBeInTheDocument(); | ||
expect(screen.queryByText("Test Rapid Transit (Shuttle)")).toBeNull(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters