Skip to content

Commit 9781adb

Browse files
committedJul 21, 2022
Add unit test
1 parent 47bb908 commit 9781adb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

‎packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,39 @@ describe('<AutocompleteInput />', () => {
124124
});
125125
});
126126

127+
it('should allow to clear the first character', async () => {
128+
render(
129+
<AdminContext dataProvider={testDataProvider()}>
130+
<SimpleForm onSubmit={jest.fn()} defaultValues={{ role: 2 }}>
131+
<AutocompleteInput
132+
{...defaultProps}
133+
optionText="foobar"
134+
choices={[
135+
{ id: 2, foobar: 'foo' },
136+
{ id: 3, foobar: 'bar' },
137+
]}
138+
/>
139+
</SimpleForm>
140+
</AdminContext>
141+
);
142+
143+
const input = screen.getByLabelText(
144+
'resources.users.fields.role'
145+
) as HTMLInputElement;
146+
147+
fireEvent.focus(input);
148+
149+
userEvent.type(input, 'f');
150+
await waitFor(() => {
151+
expect(input.value).toEqual('f');
152+
});
153+
154+
userEvent.type(input, '{backspace}');
155+
await waitFor(() => {
156+
expect(input.value).toEqual('');
157+
});
158+
});
159+
127160
it('should use optionText with a string value including "." as text identifier', async () => {
128161
render(
129162
<AdminContext dataProvider={testDataProvider()}>

0 commit comments

Comments
 (0)
Please sign in to comment.