2019-03-26 14:47:50 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import AutoComplete from '..';
|
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
|
|
|
|
|
|
describe('AutoComplete could be focus', () => {
|
|
|
|
focusTest(AutoComplete);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('AutoComplete children could be focus', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
let container;
|
|
|
|
beforeEach(() => {
|
|
|
|
container = document.createElement('div');
|
|
|
|
document.body.appendChild(container);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.body.removeChild(container);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('focus() and onFocus', () => {
|
|
|
|
const handleFocus = jest.fn();
|
2019-04-03 15:54:26 +08:00
|
|
|
const wrapper = mount(<AutoComplete onFocus={handleFocus} />, { attachTo: container });
|
|
|
|
wrapper
|
|
|
|
.find('input')
|
|
|
|
.instance()
|
|
|
|
.focus();
|
2019-03-26 14:47:50 +08:00
|
|
|
jest.runAllTimers();
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleFocus).toHaveBeenCalled();
|
2019-03-26 14:47:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('blur() and onBlur', () => {
|
|
|
|
const handleBlur = jest.fn();
|
2019-04-03 15:54:26 +08:00
|
|
|
const wrapper = mount(<AutoComplete onBlur={handleBlur} />, { attachTo: container });
|
|
|
|
wrapper
|
|
|
|
.find('input')
|
|
|
|
.instance()
|
|
|
|
.focus();
|
2019-03-26 14:47:50 +08:00
|
|
|
jest.runAllTimers();
|
2019-04-03 15:54:26 +08:00
|
|
|
wrapper
|
|
|
|
.find('input')
|
|
|
|
.instance()
|
|
|
|
.blur();
|
2019-03-26 14:47:50 +08:00
|
|
|
jest.runAllTimers();
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleBlur).toHaveBeenCalled();
|
2019-03-26 14:47:50 +08:00
|
|
|
});
|
|
|
|
});
|