Skip to content

Commit

Permalink
failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 3, 2020
1 parent 826d840 commit 0091444
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,51 @@ describe('<Autocomplete />', () => {
});
});

describe('prop: autoHighlight', () => {
it('should set the focus on the first item', () => {
const options = ['one', 'two'];
const { getByRole } = render(
<Autocomplete
freeSolo
autoHighlight
options={options}
renderInput={params => <TextField autoFocus {...params} />}
/>,
);

function checkHighlightIs(expected) {
expect(getByRole('listbox').querySelector('li[data-focus]')).to.have.text(expected);
}

checkHighlightIs('one');
fireEvent.change(document.activeElement, { target: { value: 'oo' } });
fireEvent.change(document.activeElement, { target: { value: 'o' } });
checkHighlightIs('one');
});
});

describe('prop: autoSelect', () => {
it('should not clear on blur when value does not match any option', () => {
const handleChange = spy();
const options = ['one', 'two'];
const value = 'oo';

render(
<Autocomplete
freeSolo
autoHighlight
autoSelect
options={options}
onChange={handleChange}
renderInput={params => <TextField autoFocus {...params} />}
/>,
);
fireEvent.change(document.activeElement, { target: { value } });
fireEvent.change(document.activeElement, { target: { value: 'o' } });
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.change(document.activeElement, { target: { value: 'oo' } });
document.activeElement.blur();
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.deep.equal(value);
expect(handleChange.args[0][1]).to.deep.equal('oo');
});

it('should add new value when autoSelect & multiple on blur', () => {
const handleChange = spy();
const options = ['one', 'two'];
Expand Down

0 comments on commit 0091444

Please sign in to comment.