Skip to content

Commit 3da9b7b

Browse files
committed
✅ add more tests to autocomplete
improves coverage
1 parent 440f889 commit 3da9b7b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/autocomplete/tests/accessibility.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ describe('AutoComplete Accessibility tests', () => {
6969
expect(simulatedValue()).to.equal(expectedValueAfterKeyDown);
7070
});
7171

72+
it('Successfully navigates to prev item in list when up arrow key is pressed.', () => {
73+
const expectedValueBeforeKeyDown = 'inactive';
74+
const expectedValueAfterKeyDown = 'active';
75+
const childIndex = 2; // Child item index to navigate to.
76+
const simulatedValue = () => wrappedComponent.find('#autocomplete-list').childAt((childIndex - data.length) + 1).prop('aria-label');
77+
78+
focusOnInput();
79+
expect(simulatedValue()).to.equal(expectedValueBeforeKeyDown);
80+
for (let i = childIndex; i >= 0; i -= 1) {
81+
wrappedComponent.find('input').simulate('keydown', {
82+
keyCode: 38,
83+
key: 'ArrowUp',
84+
});
85+
}
86+
expect(simulatedValue()).to.equal(expectedValueAfterKeyDown);
87+
});
88+
7289
it('Successfully updates input through keyboard navigation.', () => {
7390
const expectedValueBeforeSelection = '';
7491
const expectedValueAfterSelection = 'item 2';

lib/autocomplete/tests/edgecases.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { mount, shallow } from 'enzyme';
33
import { expect } from 'chai';
44
import AutoComplete from '..';
55

@@ -16,7 +16,7 @@ describe('AutoComplete Edge Cases tests', () => {
1616

1717
beforeEach(() => {
1818
// Mount root component before test.
19-
wrappedComponent = mount(<AutoComplete data={data} />);
19+
wrappedComponent = mount(shallow(<AutoComplete data={data} />).get(0));
2020
});
2121

2222
afterEach(() => {
@@ -34,4 +34,12 @@ describe('AutoComplete Edge Cases tests', () => {
3434
wrappedComponent.find('input').simulate('focus');
3535
expect(simulatedValue()).equal(expectedValue);
3636
});
37+
38+
it('Shoud toggle blockOnBlur state on mouseneter and mountleave events', () => {
39+
const actualValue = () => wrappedComponent.state().blockOnBlur;
40+
wrappedComponent.find('#autocomplete-list').simulate('mouseenter');
41+
expect(actualValue()).to.equal(true);
42+
wrappedComponent.find('#autocomplete-list').simulate('mouseleave');
43+
expect(actualValue()).to.equal(false);
44+
});
3745
});

0 commit comments

Comments
 (0)