-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix submit-on-enter for ApiAutoComplete having singleLine=true (#392)
* Fix submit-on-enter for ApiAutoComplete having singleLine=true --------- Signed-off-by: Carl Gieringer <78054+carlgieringer@users.noreply.github.com>
- Loading branch information
1 parent
f52d461
commit d80d2b8
Showing
7 changed files
with
114 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import { screen } from "@testing-library/react"; | ||
|
||
import ApiAutoComplete from "./ApiAutoComplete"; | ||
import { | ||
renderWithProviders, | ||
setupUserEvent, | ||
withFakeTimers, | ||
} from "./testUtils"; | ||
import { schema } from "normalizr"; | ||
|
||
withFakeTimers(); | ||
|
||
describe("ApiAutoComplete", () => { | ||
test("enter submits", async () => { | ||
const onSubmit = jest.fn((e) => e.preventDefault()); | ||
interface Thingy { | ||
name: string; | ||
} | ||
const suggestionSchema = new schema.Entity<Thingy>("thingies"); | ||
|
||
renderWithProviders( | ||
<form onSubmit={onSubmit}> | ||
<ApiAutoComplete | ||
id="test-api-autocomplete" | ||
name="test-api-autocomplete" | ||
fetchSuggestions={(_value, _suggestionsKey) => ({ | ||
type: "TEST_TYPE", | ||
payload: {}, | ||
})} | ||
cancelSuggestions={(_suggestionsKey) => ({ | ||
type: "TEST_TYPE", | ||
payload: {}, | ||
})} | ||
suggestionsKey="test-api-autocomplete" | ||
suggestionSchema={suggestionSchema} | ||
labelKey="name" | ||
/> | ||
</form> | ||
); | ||
|
||
const user = setupUserEvent(); | ||
const input = screen.getByRole("textbox"); | ||
await user.type(input, "Hi diddily do"); | ||
|
||
// Act | ||
await user.type(input, "{Enter}"); | ||
|
||
// Assert | ||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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