Skip to content

Commit

Permalink
fix: Moved "Return to Regular Route" into root directions list (#2521)
Browse files Browse the repository at this point in the history
* Test out moving the "return to route" to the root directions list

* Only add Regular Route after detour is finished

* Updated wording to match figma

* Added check: "regular route" only appears when detour is finished

Co-authored-by: Kayla Firestack <[email protected]>
  • Loading branch information
hannahpurcell and firestack authored Mar 29, 2024
1 parent 80e31cf commit fc5df73
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
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

0 comments on commit fc5df73

Please sign in to comment.