mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
2ea28af6ed
* init * fix firefox * add active style * adjust arrow style * update select * update icon logic * render empty * init multiple * fix ff display style * sync font size * adjust padding style * add padding * padding it * hotfix of chrome * single sm * multiple size * update option group style * update snapshot * clean up transition * rm combobox in ts define * auto complete init * fix auto option def * update demo * update demo * update uncertain demo * update demo * warning if user set `size` on AutoComplete * add debug demo * updat demo * update demo of disabled * update snapshot * rm useless test * fix pagination test * fix Table test * fix calendar test case * fix calendar test case * adjust style * add big data demo * support clean up * fix ts define * fix lint * fix demo lint * fix style lint fix * rm useless deps * update snapshot * stop mock * add space
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import AutoComplete from '..';
|
|
|
|
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();
|
|
const wrapper = mount(<AutoComplete onFocus={handleFocus} />, { attachTo: container });
|
|
wrapper
|
|
.find('input')
|
|
.instance()
|
|
.focus();
|
|
jest.runAllTimers();
|
|
expect(handleFocus).toHaveBeenCalled();
|
|
});
|
|
|
|
it('blur() and onBlur', () => {
|
|
const handleBlur = jest.fn();
|
|
const wrapper = mount(<AutoComplete onBlur={handleBlur} />, { attachTo: container });
|
|
wrapper
|
|
.find('input')
|
|
.instance()
|
|
.focus();
|
|
jest.runAllTimers();
|
|
wrapper
|
|
.find('input')
|
|
.instance()
|
|
.blur();
|
|
jest.runAllTimers();
|
|
expect(handleBlur).toHaveBeenCalled();
|
|
});
|
|
|
|
it('child.ref should work', () => {
|
|
const mockRef = jest.fn();
|
|
mount(
|
|
<AutoComplete dataSource={[]}>
|
|
<input ref={mockRef} />
|
|
</AutoComplete>,
|
|
);
|
|
expect(mockRef).toHaveBeenCalled();
|
|
});
|
|
|
|
it('child.ref instance should support be focused and blured', () => {
|
|
let inputRef;
|
|
mount(
|
|
<AutoComplete dataSource={[]}>
|
|
<input
|
|
ref={node => {
|
|
inputRef = node;
|
|
}}
|
|
/>
|
|
</AutoComplete>,
|
|
);
|
|
expect(typeof inputRef.focus).toBe('function');
|
|
expect(typeof inputRef.blur).toBe('function');
|
|
});
|
|
});
|