Skip to content

Commit

Permalink
[Autocomplete] Better isolate test case (#23704)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Nov 27, 2020
1 parent 1e305ec commit 5115f08
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions packages/material-ui/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,22 @@ describe('<Autocomplete />', () => {

it('should trigger a form expectedly', () => {
const handleSubmit = spy();
const { setProps } = render(
<Autocomplete
options={['one', 'two']}
const Test = (props) => (
<div
onKeyDown={(event) => {
if (!event.defaultPrevented && event.key === 'Enter') {
handleSubmit();
}
}}
renderInput={(props2) => <TextField {...props2} autoFocus />}
/>,
>
<Autocomplete
options={['one', 'two']}
renderInput={(props2) => <TextField {...props2} autoFocus />}
{...props}
/>
</div>
);
const { setProps } = render(<Test />);
let textbox = screen.getByRole('textbox');

fireEvent.keyDown(textbox, { key: 'Enter' });
Expand Down Expand Up @@ -576,23 +581,26 @@ describe('<Autocomplete />', () => {
});

describe('prop: getOptionDisabled', () => {
it('should disable the option but allow focus with disabledItemsFocusable', () => {
it('should prevent the disabled option to trigger actions but allow focus with disabledItemsFocusable', () => {
const handleSubmit = spy();
const handleChange = spy();
const { getAllByRole } = render(
<Autocomplete
disabledItemsFocusable
getOptionDisabled={(option) => option === 'two'}
<div
onKeyDown={(event) => {
if (!event.defaultPrevented && event.key === 'Enter') {
handleSubmit();
}
}}
onChange={handleChange}
openOnFocus
options={['one', 'two', 'three']}
renderInput={(props2) => <TextField {...props2} autoFocus />}
/>,
>
<Autocomplete
disabledItemsFocusable
getOptionDisabled={(option) => option === 'two'}
onChange={handleChange}
openOnFocus
options={['one', 'two', 'three']}
renderInput={(props2) => <TextField {...props2} autoFocus />}
/>
</div>,
);

let options;
Expand Down

0 comments on commit 5115f08

Please sign in to comment.