Skip to content

Commit

Permalink
feat: Expose Change route or direction button behind a test group
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed May 28, 2024
1 parent d79813f commit bb69f79
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions assets/src/components/detours/diversionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { OriginalRoute } from "../../models/detour"
import { joinClasses } from "../../helpers/dom"
import { AsProp } from "react-bootstrap/esm/helpers"
import { DetourFinishedPanel } from "./detourFinishedPanel"
import inTestGroup, { TestGroups } from "../../userInTestGroup"

interface DiversionPageProps {
originalRoute: OriginalRoute
Expand Down Expand Up @@ -91,6 +92,10 @@ export const DiversionPage = ({
connectionPoints?.end?.name,
])

const changeRoute = inTestGroup(TestGroups.RouteLadderHeaderUpdate)
? () => {}
: undefined

return (
<>
<article className="l-diversion-page h-100 border-box inherit-box">
Expand All @@ -109,6 +114,7 @@ export const DiversionPage = ({
routeDirection={originalRoute.routeDirection}
detourFinished={finishDetour !== undefined}
onFinishDetour={finishDetour}
onChangeRoute={changeRoute}
/>
)}
{state === DetourState.Finished && editDetour && (
Expand Down
1 change: 1 addition & 0 deletions assets/src/userInTestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum TestGroups {
KeycloakSso = "keycloak-sso",
MinimalLadderPage = "minimal-ladder-page",
LateView = "late-view",
RouteLadderHeaderUpdate = "route-ladder-header-update",
}

const inTestGroup = (key: TestGroups): boolean => {
Expand Down
25 changes: 19 additions & 6 deletions assets/tests/components/detours/diversionPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
} from "../../testHelpers/selectors/components/map/markers/stopIcon"
import { Err, Ok } from "../../../src/util/result"
import { neverPromise } from "../../testHelpers/mockHelpers"
import getTestGroups from "../../../src/userTestGroups"
import { TestGroups } from "../../../src/userInTestGroup"

const DiversionPage = (
props: Omit<
Expand Down Expand Up @@ -71,11 +73,15 @@ beforeEach(() => {
})

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

beforeEach(() => {
jest.mocked(fetchDetourDirections).mockReturnValue(neverPromise())
jest.mocked(fetchFinishedDetour).mockReturnValue(neverPromise())
jest.mocked(fetchNearestIntersection).mockReturnValue(neverPromise())
jest
.mocked(getTestGroups)
.mockReturnValue([TestGroups.RouteLadderHeaderUpdate])
})

describe("DiversionPage", () => {
Expand Down Expand Up @@ -1216,12 +1222,19 @@ describe("DiversionPage", () => {
})

describe("'Change route or direction' button", () => {
/*
* This test is here because this button is now part of one of the
* components, and we want to make sure that we don't accidentally
* render it when we didn't intend to.
*/
test("the button doesn't render yet in context", async () => {
test("there is a button saying 'Change route or direction'", async () => {
render(<DiversionPage />)

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Change route or direction" })
).toBeVisible()
})
})

test("the button is not there if the user isn't in the right test group", async () => {
jest.mocked(getTestGroups).mockReturnValue([])

render(<DiversionPage />)

expect(
Expand Down

0 comments on commit bb69f79

Please sign in to comment.