-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add detour button to list page (#2739)
* 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
Showing
4 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
assets/tests/components/detours/detoursPage.addDetour.test.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,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() | ||
}) | ||
}) |