mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
Add test cases for Mention
This commit is contained in:
parent
89ed0dcb35
commit
292a91a777
58
components/mention/__tests__/index.test.js
Normal file
58
components/mention/__tests__/index.test.js
Normal file
@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import Mention from '..';
|
||||
|
||||
const { toContentState } = Mention;
|
||||
|
||||
describe('Mention', () => {
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should has focus function', () => {
|
||||
const handleFocus = jest.fn();
|
||||
const wrapper = mount(
|
||||
<Mention
|
||||
defaultValue={toContentState('@afc163')}
|
||||
onFocus={handleFocus}
|
||||
suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
|
||||
/>
|
||||
);
|
||||
wrapper.instance().focus();
|
||||
jest.runAllTimers();
|
||||
expect(handleFocus).toBeCalled();
|
||||
});
|
||||
|
||||
it('basic suggestion', () => {
|
||||
const handleSearch = jest.fn();
|
||||
const wrapper = mount(
|
||||
<Mention
|
||||
suggestions={['afc163', 'raohai']}
|
||||
onSearchChange={handleSearch}
|
||||
/>
|
||||
);
|
||||
wrapper.find('DraftEditorContents').simulate('focus');
|
||||
const ed = wrapper.find('.public-DraftEditor-content');
|
||||
ed.simulate('beforeInput', { data: '@a' });
|
||||
jest.runAllTimers();
|
||||
expect(handleSearch).toBeCalledWith('a', '@');
|
||||
});
|
||||
|
||||
it('change suggestions', () => {
|
||||
const wrapper = mount(
|
||||
<Mention suggestions={['afc163', 'raohai']} />
|
||||
);
|
||||
wrapper.find('DraftEditorContents').simulate('focus');
|
||||
const ed = wrapper.find('.public-DraftEditor-content');
|
||||
ed.simulate('beforeInput', { data: '@' });
|
||||
expect(wrapper.find('Nav').length).toBe(2);
|
||||
expect(wrapper.find('Nav').first().text()).toBe('afc163');
|
||||
wrapper.setState({ suggestions: ['yesmeck', 'yiminghe', 'lucy'] });
|
||||
expect(wrapper.find('Nav').length).toBe(3);
|
||||
expect(wrapper.find('Nav').first().text()).toBe('yesmeck');
|
||||
});
|
||||
});
|
@ -5,6 +5,7 @@ if (typeof window !== 'undefined') {
|
||||
global.window.innerHeight = height || global.window.innerHeight;
|
||||
global.window.dispatchEvent(new Event('resize'));
|
||||
};
|
||||
global.window.scrollTo = () => {};
|
||||
}
|
||||
|
||||
// The built-in requestAnimationFrame and cancelAnimationFrame not working with jest.runFakeTimes()
|
||||
|
Loading…
Reference in New Issue
Block a user