it('should remove the new option after closing on blur', () => { createControl(); typeSearchText('9'); TestUtils.Simulate.blur(filterInputNode); expect(creatableInstance.inputValue, 'to equal', ''); });
it('should not display the options menu when touched and dragged', function() { TestUtils.Simulate.touchStart(getSelectControl(instance)); TestUtils.Simulate.touchMove(getSelectControl(instance)); TestUtils.Simulate.touchEnd(getSelectControl(instance)); var node = ReactDOM.findDOMNode(instance); expect(node, 'to contain no elements matching', '.Select-option'); });
var findAndFocusInputControl = () => { // Focus on the input, such that mouse events are accepted var searchInstance = ReactDOM.findDOMNode(instance.input); searchInputNode = null; if (searchInstance) { searchInputNode = searchInstance.querySelector('input'); if (searchInputNode) { TestUtils.Simulate.focus(searchInputNode); } } }
it('is does not close menu when disabled option is clicked', () => { clickArrowToOpen(); TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(instance).querySelectorAll('.Select-option')[1]); var options = ReactDOM.findDOMNode(instance).querySelectorAll('.Select-option'); expect(options.length, 'to equal', 3); });
describe('.focus()', () => { beforeEach(() => { createControl({}); TestUtils.Simulate.blur(filterInputNode); }); it('focuses the search input', () => { expect(filterInputNode, 'not to equal', document.activeElement); creatableInstance.focus(); expect(filterInputNode, 'to equal', document.activeElement); }); });
it('should loop round to top item when down is pressed on the last item', () => { var selectControl = getSelectControl(instance); TestUtils.Simulate.mouseDown(selectControl, { button: 0 }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option.is-focused', 'to have items satisfying', 'to have text', 'One'); });
it('should focus the first value on mouse click', () => { TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(instance).querySelector('.Select-control'), { button: 0 }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option.is-focused', 'to have items satisfying', 'to have text', 'One'); });
it('doesn\'t focus anything when all options are disabled', () => { wrapper = createControlWithWrapper({ options: [ { value: 'one', label: 'One', disabled: true }, { value: 'two', label: 'Two', disabled: true }, { value: 'three', label: 'Three', disabled: true } ] }); clickArrowToOpen(); TestUtils.Simulate.keyDown(getSelectControl(instance), { keyCode: 40, key: 'ArrowDown' }); expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-option.is-focused'); });
it('jumps over the disabled option', () => { clickArrowToOpen(); // Press down to get to the second option TestUtils.Simulate.keyDown(getSelectControl(instance), { keyCode: 40, key: 'ArrowDown' }); // Check the focused option is the one after the disabled option expect(ReactDOM.findDOMNode(instance), 'queried for first', '.Select-option.is-focused', 'to have text', 'Three'); });
it('should ignore a right mouse click on the arrow', () => { var selectArrow = ReactDOM.findDOMNode(instance).querySelector('.Select-arrow'); TestUtils.Simulate.mouseDown(selectArrow, { button: 1 }); expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-option'); });
it('should show the options on mouse click', function () { TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(instance).querySelector('.Select-control'), { button: 0 }); var node = ReactDOM.findDOMNode(instance); expect(node, 'queried for', '.Select-option', 'to have length', 3); });
it('should move the focused value to the second value when down pressed', () => { var selectControl = getSelectControl(instance); TestUtils.Simulate.mouseDown(selectControl, { button: 0 }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option.is-focused', 'to have items satisfying', 'to have text', 'Three'); });
it('should move the focused value to the end if page down is pressed and number of items is less than page size', () => { var selectControl = getSelectControl(instance); TestUtils.Simulate.mouseDown(selectControl, { button: 0 }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 34, key: 'PageDown' }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option.is-focused', 'to have items satisfying', 'to have text', 'Three'); });
it('should remove the new option after closing on escape', () => { createControl(); typeSearchText('9'); TestUtils.Simulate.keyDown(filterInputNode, { keyCode: 27 }); expect(creatableInstance.inputValue, 'to equal', ''); });
it('should move the focused value to the start if page up is pressed and number of items is less than page size', () => { var selectControl = getSelectControl(instance); TestUtils.Simulate.mouseDown(selectControl, { button: 0 }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 34, key: 'PageDown' }); TestUtils.Simulate.keyDown(selectControl, { keyCode: 33, key: 'PageUp' }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option.is-focused', 'to have items satisfying', 'to have text', 'One'); });