-
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: Part 3 of converting to Restart modals: Preset modals (#2578)
- Loading branch information
1 parent
1daa424
commit ed3ea5b
Showing
2 changed files
with
21 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { jest, describe, test, expect } from "@jest/globals" | ||
import React from "react" | ||
import { render, fireEvent } from "@testing-library/react" | ||
import { render, waitFor } from "@testing-library/react" | ||
import InputModal from "../../src/components/inputModal" | ||
import { StateDispatchProvider } from "../../src/contexts/stateDispatchContext" | ||
import { initialState, closeInputModal } from "../../src/state" | ||
import userEvent from "@testing-library/user-event" | ||
|
||
describe("InputModal", () => { | ||
test("can be dismissed with escape key", () => { | ||
test("can be dismissed with escape key", async () => { | ||
const mockDispatch = jest.fn() | ||
|
||
const result = render( | ||
render( | ||
<StateDispatchProvider state={initialState} dispatch={mockDispatch}> | ||
<InputModal> | ||
<>Hello, world!</> | ||
</InputModal> | ||
</StateDispatchProvider> | ||
) | ||
|
||
fireEvent.keyDown(result.getByText("Hello, world!"), { key: "Escape" }) | ||
|
||
expect(mockDispatch).toHaveBeenCalledWith(closeInputModal()) | ||
await userEvent.keyboard("{Escape}") | ||
await waitFor(() => | ||
expect(mockDispatch).toHaveBeenCalledWith(closeInputModal()) | ||
) | ||
}) | ||
}) |