-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(AutoComplete): fix autocomplete not working
- Loading branch information
1 parent
4ae9880
commit a58f1ea
Showing
2 changed files
with
71 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from "react"; | ||
|
||
import { render, waitFor } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { Formik, Form, Field, FormikProps } from "formik"; | ||
import _ from "lodash"; | ||
|
||
import { AutoComplete } from "../AutoComplete"; | ||
|
||
test("Works with formik", async () => { | ||
const formikRef = React.createRef<FormikProps<any>>(); | ||
const { getByTestId } = render( | ||
<Formik | ||
innerRef={formikRef} | ||
initialValues={{ | ||
text: "value", | ||
}} | ||
onSubmit={_.noop} | ||
> | ||
<Form> | ||
<Field name="text" component={AutoComplete} data-testid="input" /> | ||
</Form> | ||
</Formik> | ||
); | ||
|
||
expect(getByTestId("input")).toHaveValue("value"); | ||
|
||
userEvent.clear(getByTestId("input")); | ||
userEvent.type(getByTestId("input"), "newvalue"); | ||
|
||
await waitFor(() => { | ||
expect(formikRef.current?.values).toHaveProperty("text", "newvalue"); | ||
}); | ||
}); | ||
|
||
test("Autocomplete shouold work", async () => { | ||
const formikRef = React.createRef<FormikProps<any>>(); | ||
const { getByTestId, getByText } = render( | ||
<Formik | ||
innerRef={formikRef} | ||
initialValues={{ | ||
text: "", | ||
}} | ||
onSubmit={_.noop} | ||
> | ||
<Form> | ||
<Field | ||
name="text" | ||
component={AutoComplete} | ||
data={["suggested result"]} | ||
data-testid="input" | ||
/> | ||
</Form> | ||
</Formik> | ||
); | ||
|
||
userEvent.type(getByTestId("input"), "s"); | ||
|
||
userEvent.click(getByText("suggested result")); | ||
|
||
await waitFor(() => { | ||
expect(formikRef.current?.values).toHaveProperty( | ||
"text", | ||
"suggested result" | ||
); | ||
}); | ||
}); |