Skip to content

Commit b5cc90a

Browse files
committed
✅ add more tests to select
improves coverage
1 parent 0c42294 commit b5cc90a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/select/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class Select extends Component {
168168
className={cx(theme.option, { [`${theme['option-hover']}`]: (focus === index) })}
169169
onClick={() => this.handleSelect(option)}
170170
key={option.label}
171+
data-react-active-item={focus === index ? 'active' : undefined}
171172
>
172173
<span>{option.label}</span>
173174
</span>

lib/select/tests/accessibility.test.js

Lines changed: 25 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 Select from '..';
55

@@ -20,7 +20,7 @@ describe('Select Accessibility tests', () => {
2020
};
2121

2222
beforeEach(() => {
23-
wrappedComponent = mount(<Select options={data} />);
23+
wrappedComponent = mount(shallow(<Select options={data} />).get(0));
2424
});
2525

2626
afterEach(() => {
@@ -62,4 +62,27 @@ describe('Select Accessibility tests', () => {
6262
});
6363
expect(simulatedValue()).to.equal(expectedValueAfterSelection);
6464
});
65+
66+
it('Successfully navigates to last item through keypress', () => {
67+
const expectedValueAfterKeyDown = 'item 3';
68+
focusOnInput();
69+
wrappedComponent.find('#select').simulate('keydown', {
70+
keyCode: 38,
71+
key: 'ArrowUp',
72+
});
73+
expect(wrappedComponent.find('#select-dropdown span[data-react-active-item="active"]').text()).equals(expectedValueAfterKeyDown);
74+
});
75+
76+
const simulateEvent = (component, event) => wrappedComponent.find(component).simulate(event);
77+
78+
it('Should toggle blockBlurEvent state properly on mouseenter and mouse leave', () => {
79+
const expectedValueBefore = true;
80+
const expectedValueAfter = false;
81+
const actualValue = () => wrappedComponent.state().blockOnBlur;
82+
focusOnInput();
83+
simulateEvent('div#select-dropdown', 'mouseenter');
84+
expect(actualValue()).to.equal(expectedValueBefore);
85+
simulateEvent('div#select-dropdown', 'mouseleave');
86+
expect(actualValue()).to.equal(expectedValueAfter);
87+
});
6588
});

0 commit comments

Comments
 (0)