mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 06:58:33 +08:00
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
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 container = mount(<div id="container" />);
|
|
const wrapper = mount(
|
|
<Mention suggestions={['afc163', 'raohai']} getSuggestionContainer={() => container.getDOMNode()} />
|
|
);
|
|
wrapper.find('DraftEditorContents').simulate('focus');
|
|
const ed = wrapper.find('.public-DraftEditor-content');
|
|
ed.simulate('beforeInput', { data: '@' });
|
|
jest.runAllTimers();
|
|
expect(container.getDOMNode().querySelectorAll('.ant-mention-dropdown-item').length).toBe(2);
|
|
expect(container.getDOMNode().querySelectorAll('.ant-mention-dropdown-item')[0].innerHTML).toBe('afc163');
|
|
wrapper.setState({ suggestions: ['yesmeck', 'yiminghe', 'lucy'] });
|
|
jest.runAllTimers();
|
|
expect(container.getDOMNode().querySelectorAll('.ant-mention-dropdown-item').length).toBe(3);
|
|
expect(container.getDOMNode().querySelectorAll('.ant-mention-dropdown-item')[0].innerHTML).toBe('yesmeck');
|
|
});
|
|
});
|