Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Moved "Return to Regular Route" into root directions list #2521

Merged
merged 11 commits into from
Mar 29, 2024
1 change: 0 additions & 1 deletion assets/src/components/detours/diversionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const DiversionPage = ({
,
"Turn-by-Turn Directions:",
...(directions?.map((v) => v.instruction) ?? []),
"Return to Regular Route",
,
"Connection Points:",
connectionPoints?.start?.name ?? "N/A",
Expand Down
11 changes: 5 additions & 6 deletions assets/src/components/detours/diversionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ export const DiversionPanel = ({
<ListGroup as="ol">
{directions.map((d) => (
<ListGroup.Item key={d.instruction} as="li">
{d.instruction}
{d.instruction == "Regular Route" ? (
<strong className="fw-medium">{d.instruction}</strong>
) : (
d.instruction
)}
</ListGroup.Item>
))}
{detourFinished && (
<ListGroup.Item as="li">
<strong className="fw-medium">Return to Regular Route</strong>
</ListGroup.Item>
)}
</ListGroup>
) : (
<DirectionsHelpText />
Expand Down
9 changes: 8 additions & 1 deletion assets/src/hooks/useDetour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ export const useDetour = ({ routePatternId, shape }: OriginalRoute) => {
)

const coordinates = isOk(detourShape) ? detourShape.ok.coordinates : []
const directions = isOk(detourShape) ? detourShape.ok.directions : undefined
// Only append direction "Regular Route" after detour is finished
const directions = isOk(detourShape)
? finishedDetour
? detourShape.ok.directions?.concat({
instruction: "Regular Route",
})
: detourShape.ok.directions
: undefined

const canAddWaypoint = () => startPoint !== null && endPoint === null
const addWaypoint = canAddWaypoint()
Expand Down
68 changes: 67 additions & 1 deletion assets/tests/components/detours/diversionPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,72 @@ describe("DiversionPage", () => {
expect(screen.queryByTitle("Detour End")).toBeNull()
})

test("shows 'Regular Route' text when the detour is finished", async () => {
jest.mocked(fetchDetourDirections).mockResolvedValue(
ok(
detourShapeFactory.build({
directions: [
{ instruction: "Turn left on Main Street" },
{ instruction: "Turn right on High Street" },
{ instruction: "Turn sharp right on Broadway" },
],
})
)
)

jest
.mocked(fetchFinishedDetour)
.mockResolvedValue(finishedDetourFactory.build())

const { container } = render(<DiversionPage />)

act(() => {
fireEvent.click(originalRouteShape.get(container))
})

act(() => {
fireEvent.click(originalRouteShape.get(container))
})

expect(await screen.findByText("Regular Route")).toBeVisible()
})

test("does not show 'Regular Route' when detour is not finished", async () => {
jest.mocked(fetchDetourDirections).mockResolvedValue(
ok(
detourShapeFactory.build({
directions: [
{ instruction: "Turn left on Main Street" },
{ instruction: "Turn right on High Street" },
{ instruction: "Turn sharp right on Broadway" },
],
})
)
)

jest
.mocked(fetchFinishedDetour)
.mockResolvedValue(finishedDetourFactory.build())

const { container } = render(<DiversionPage />)

expect(screen.queryByText("Regular Route")).not.toBeInTheDocument()

act(() => {
fireEvent.click(originalRouteShape.get(container))
})

act(() => {
fireEvent.click(originalRouteShape.get(container))
})

expect(await screen.findByText("Regular Route")).toBeVisible()

fireEvent.click(screen.getByRole("button", { name: "Undo" }))

expect(screen.queryByText("Regular Route")).not.toBeInTheDocument()
})

test("missed stops are filled in when detour is complete", async () => {
const stop1 = stopFactory.build()
const stop2 = stopFactory.build()
Expand Down Expand Up @@ -410,7 +476,7 @@ describe("DiversionPage", () => {
"Turn left on Main Street",
"Turn right on High Street",
"Turn sharp right on Broadway",
"Return to Regular Route",
"Regular Route",
,
"Connection Points:",
start.name,
Expand Down
Loading