Skip to content

Commit

Permalink
feat: add detour button to list page (#2739)
Browse files Browse the repository at this point in the history
* feat: add detour button to list page

* feat: add detour machine input to original route type

* feat: show modal when add button is clicked
  • Loading branch information
firestack authored Aug 20, 2024
1 parent 8257c6a commit f9d88c5
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
21 changes: 20 additions & 1 deletion assets/src/components/detourListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from "react"
import React, { useState } from "react"
import { DetoursTable } from "./detoursTable"
import userInTestGroup, { TestGroups } from "../userInTestGroup"
import { Button } from "react-bootstrap"
import { PlusSquare } from "../helpers/bsIcons"
import { DetourModal } from "./detours/detourModal"

export interface Detour {
route: string
Expand Down Expand Up @@ -76,9 +80,24 @@ export const DetourListPage = () => {
},
]

const [showDetourModal, setShowDetourModal] = useState(false)

return (
<div className="h-100 overflow-y-auto">
{userInTestGroup(TestGroups.DetoursPilot) && (
<Button className="icon-link" onClick={() => setShowDetourModal(true)}>
<PlusSquare />
Add detour
</Button>
)}
<DetoursTable data={fakeData} />
{showDetourModal && (
<DetourModal
onClose={() => setShowDetourModal(false)}
show
originalRoute={{}}
/>
)}
</div>
)
}
6 changes: 3 additions & 3 deletions assets/src/models/createDetourMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export const createDetourMachine = setup({
| {
// Caller has target route
route: Route
routePattern: undefined
routePattern?: undefined
}
| {
// Caller has no prior selection
route: undefined
routePattern: undefined
route?: undefined
routePattern?: undefined
},

events: {} as
Expand Down
9 changes: 5 additions & 4 deletions assets/src/models/detour.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LatLngLiteral } from "leaflet"
import { Route, RoutePattern, ShapePoint, Stop } from "../schedule"
import { ShapePoint, Stop } from "../schedule"
import { CreateDetourMachineInput } from "./createDetourMachine"

export interface DetourShape {
coordinates: ShapePoint[]
Expand All @@ -10,13 +11,13 @@ export type DetourDirection = {
instruction: string
}

export interface OriginalRoute {
route: Route
routePattern?: RoutePattern
export interface MapLocation {
center?: LatLngLiteral
zoom?: number
}

export type OriginalRoute = CreateDetourMachineInput & MapLocation

export interface UnfinishedRouteSegments {
beforeStartPoint: ShapePoint[]
afterStartPoint: ShapePoint[]
Expand Down
68 changes: 68 additions & 0 deletions assets/tests/components/detours/detoursPage.addDetour.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, expect, jest, test } from "@jest/globals"

import React from "react"

import { screen } from "@testing-library/dom"
import "@testing-library/jest-dom/jest-globals"
import { render } from "@testing-library/react"
import userEvent from "@testing-library/user-event"

import { DetourListPage } from "../../../src/components/detourListPage"
import { TestGroups } from "../../../src/userInTestGroup"
import getTestGroups from "../../../src/userTestGroups"

jest.mock("../../../src/userTestGroups")

const renderDetourListPage = () => {
return render(<DetourListPage></DetourListPage>)
}

describe("Detours Page: Create Detour", () => {
test("Shows the add detour button when in test group", () => {
jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursPilot])

renderDetourListPage()

expect(screen.getByRole("button", { name: "Add detour" })).toBeVisible()
})

test("Does not show add detour button when not in test group", () => {
jest.mocked(getTestGroups).mockReturnValue([])

renderDetourListPage()

expect(
screen.queryByRole("button", { name: "Add detour" })
).not.toBeInTheDocument()
})

test("Opens Detour Modal when clicked", async () => {
jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursPilot])

renderDetourListPage()

await userEvent.click(screen.getByRole("button", { name: "Add detour" }))

expect(
await screen.findByRole("heading", { name: "Create Detour" })
).toBeVisible()
})

test("Returns to page when modal is closed", async () => {
jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursPilot])

renderDetourListPage()

await userEvent.click(screen.getByRole("button", { name: "Add detour" }))

const createDetourHeading = await screen.findByRole("heading", {
name: "Create Detour",
})
expect(createDetourHeading).toBeVisible()

await userEvent.click(screen.getByRole("button", { name: "Close" }))
await userEvent.click(screen.getByRole("button", { name: "Yes, I'm sure" }))

expect(createDetourHeading).not.toBeInTheDocument()
})
})

0 comments on commit f9d88c5

Please sign in to comment.