2017-02-26 16:48:42 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { render, mount } from 'enzyme';
|
2017-03-28 13:51:58 +08:00
|
|
|
import KeyCode from 'rc-util/lib/KeyCode';
|
2017-02-26 16:48:42 +08:00
|
|
|
import Cascader from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2017-02-26 16:48:42 +08:00
|
|
|
|
|
|
|
const options = [{
|
|
|
|
value: 'zhejiang',
|
|
|
|
label: 'Zhejiang',
|
|
|
|
children: [{
|
|
|
|
value: 'hangzhou',
|
|
|
|
label: 'Hangzhou',
|
|
|
|
children: [{
|
|
|
|
value: 'xihu',
|
|
|
|
label: 'West Lake',
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
value: 'jiangsu',
|
|
|
|
label: 'Jiangsu',
|
|
|
|
children: [{
|
|
|
|
value: 'nanjing',
|
|
|
|
label: 'Nanjing',
|
|
|
|
children: [{
|
|
|
|
value: 'zhonghuamen',
|
|
|
|
label: 'Zhong Hua Men',
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}];
|
|
|
|
|
|
|
|
describe('Cascader', () => {
|
2017-11-19 01:41:40 +08:00
|
|
|
focusTest(Cascader);
|
|
|
|
|
2017-02-26 16:48:42 +08:00
|
|
|
it('popup correctly when panel is hidden', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Cascader options={options} />
|
|
|
|
);
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
2017-02-26 16:48:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('popup correctly when panel is open', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Cascader options={options} />
|
|
|
|
);
|
|
|
|
wrapper.find('input').simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
2017-02-26 16:48:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('popup correctly with defaultValue', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Cascader options={options} defaultValue={['zhejiang', 'hangzhou']} />
|
|
|
|
);
|
|
|
|
wrapper.find('input').simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
2017-02-26 16:48:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can be selected', () => {
|
|
|
|
const wrapper = mount(<Cascader options={options} />);
|
|
|
|
wrapper.find('input').simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
let popupWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-02-26 16:48:42 +08:00
|
|
|
popupWrapper.find('.ant-cascader-menu').at(0).find('.ant-cascader-menu-item').at(0)
|
|
|
|
.simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
|
|
|
popupWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-02-26 16:48:42 +08:00
|
|
|
popupWrapper.find('.ant-cascader-menu').at(1).find('.ant-cascader-menu-item').at(0)
|
|
|
|
.simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
|
|
|
popupWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-02-26 16:48:42 +08:00
|
|
|
popupWrapper.find('.ant-cascader-menu').at(2).find('.ant-cascader-menu-item').at(0)
|
|
|
|
.simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
2017-02-26 16:48:42 +08:00
|
|
|
});
|
2017-03-28 13:51:58 +08:00
|
|
|
|
|
|
|
it('backspace should work with `Cascader[showSearch]`', () => {
|
|
|
|
const wrapper = mount(<Cascader options={options} showSearch />);
|
|
|
|
wrapper.find('input').simulate('change', { target: { value: '123' } });
|
|
|
|
expect(wrapper.state('inputValue')).toBe('123');
|
|
|
|
wrapper.find('input').simulate('keydown', { keyCode: KeyCode.BACKSPACE });
|
|
|
|
// Simulate onKeyDown will not trigger onChange by default, so the value is still '123'
|
|
|
|
expect(wrapper.state('inputValue')).toBe('123');
|
|
|
|
});
|
2017-02-26 16:48:42 +08:00
|
|
|
});
|