|
1 | 1 | import { mount } from 'enzyme';
|
2 |
| -import React from 'react'; |
| 2 | +import React, { useState } from 'react'; |
3 | 3 | import { act } from 'react-dom/test-utils';
|
4 | 4 | import Select from '../src';
|
| 5 | +import { fireEvent, render } from '@testing-library/react'; |
5 | 6 |
|
6 | 7 | describe('Select.Focus', () => {
|
7 | 8 | it('disabled should reset focused', () => {
|
@@ -31,6 +32,45 @@ describe('Select.Focus', () => {
|
31 | 32 | jest.useRealTimers();
|
32 | 33 | });
|
33 | 34 |
|
| 35 | + it('after onBlur is triggered the focused does not need to be reset', () => { |
| 36 | + jest.useFakeTimers(); |
| 37 | + |
| 38 | + const onFocus = jest.fn(); |
| 39 | + |
| 40 | + const Demo: React.FC = () => { |
| 41 | + const [disabled, setDisabled] = useState(false); |
| 42 | + return ( |
| 43 | + <> |
| 44 | + <Select disabled={disabled} onFocus={onFocus} onBlur={() => setDisabled(true)} /> |
| 45 | + <button onClick={() => setDisabled(false)} /> |
| 46 | + </> |
| 47 | + ); |
| 48 | + }; |
| 49 | + |
| 50 | + const { container } = render(<Demo />); |
| 51 | + |
| 52 | + fireEvent.focus(container.querySelector('input')); |
| 53 | + jest.runAllTimers(); |
| 54 | + |
| 55 | + // trigger disabled |
| 56 | + fireEvent.blur(container.querySelector('input')); |
| 57 | + jest.runAllTimers(); |
| 58 | + |
| 59 | + // reset focused |
| 60 | + onFocus.mockReset(); |
| 61 | + |
| 62 | + expect(container.querySelector('.rc-select-disabled')).toBeTruthy(); |
| 63 | + |
| 64 | + // reset disabled |
| 65 | + fireEvent.click(container.querySelector('button')); |
| 66 | + fireEvent.focus(container.querySelector('input')); |
| 67 | + jest.runAllTimers(); |
| 68 | + |
| 69 | + expect(onFocus).toHaveBeenCalled(); |
| 70 | + |
| 71 | + jest.useRealTimers(); |
| 72 | + }); |
| 73 | + |
34 | 74 | it('IE focus', () => {
|
35 | 75 | jest.clearAllTimers();
|
36 | 76 | jest.useFakeTimers();
|
|
0 commit comments