From 8f8bbceacd7afa5fc36c447d2a645aca1ae1fd9f Mon Sep 17 00:00:00 2001 From: Hannah Purcell <69368883+hannahpurcell@users.noreply.github.com> Date: Wed, 8 May 2024 10:02:58 -0400 Subject: [PATCH] chore: Pressing escape closes the inputModal (#2585) --- assets/tests/components/modal.test.tsx | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/assets/tests/components/modal.test.tsx b/assets/tests/components/modal.test.tsx index 840346faf..4729335c0 100644 --- a/assets/tests/components/modal.test.tsx +++ b/assets/tests/components/modal.test.tsx @@ -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" @@ -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, @@ -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( + + + + ) + 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()