Skip to content

Commit

Permalink
chore: Pressing escape closes the inputModal (#2585)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahpurcell authored May 8, 2024
1 parent 6bef3d8 commit 8f8bbce
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion assets/tests/components/modal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jest, describe, test, expect } from "@jest/globals"
import "@testing-library/jest-dom/jest-globals"
import React from "react"
import { render } from "@testing-library/react"
import { render, screen, waitFor } from "@testing-library/react"
import Modal from "../../src/components/modal"
import { StateDispatchProvider } from "../../src/contexts/stateDispatchContext"
import { useMinischeduleRuns } from "../../src/hooks/useMinischedule"
Expand All @@ -12,6 +13,8 @@ import {
import { initialState, State } from "../../src/state"
import stateFactory from "../factories/applicationState"
import { viewFactory } from "../factories/pagePanelStateFactory"
import userEvent from "@testing-library/user-event"
import { RealDispatchWrapper } from "../testHelpers/wrappers"

jest.mock("../../src/hooks/useMinischedule", () => ({
__esModule: true,
Expand Down Expand Up @@ -105,6 +108,29 @@ describe("Modal", () => {
expect(result.getByText("Save open routes as preset")).not.toBeNull()
})

test("create preset modal closes on escape", async () => {
const createCallback = jest.fn()
const confirmOverwriteCallback = jest.fn()

render(
<RealDispatchWrapper
initialState={stateFactory.build({
openInputModal: {
type: "CREATE_PRESET",
createCallback,
confirmOverwriteCallback,
},
})}
>
<Modal />
</RealDispatchWrapper>
)
const modal = screen.getByText("Save open routes as preset")
expect(modal).toBeVisible()
userEvent.keyboard("{Escape}")
await waitFor(() => expect(modal).not.toBeInTheDocument())
})

test("renders save preset modal", () => {
const saveCallback = jest.fn()

Expand Down

0 comments on commit 8f8bbce

Please sign in to comment.