2018-11-26 12:06:42 +08:00
|
|
|
import { mount } from 'enzyme';
|
2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2016-12-14 14:48:09 +08:00
|
|
|
import Dropdown from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Menu from '../../menu';
|
2016-12-14 14:48:09 +08:00
|
|
|
|
|
|
|
describe('DropdownButton', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Dropdown.Button);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Dropdown.Button);
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
it('pass appropriate props to Dropdown', () => {
|
|
|
|
const props = {
|
|
|
|
align: {
|
|
|
|
offset: [10, 20],
|
|
|
|
},
|
|
|
|
overlay: (
|
|
|
|
<Menu>
|
2021-06-29 17:55:02 +08:00
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
2016-12-14 14:48:09 +08:00
|
|
|
</Menu>
|
|
|
|
),
|
2018-01-18 23:39:34 +08:00
|
|
|
disabled: false,
|
2016-12-14 14:48:09 +08:00
|
|
|
trigger: ['hover'],
|
|
|
|
visible: true,
|
|
|
|
onVisibleChange: () => {},
|
|
|
|
};
|
|
|
|
|
2018-11-26 12:06:42 +08:00
|
|
|
const wrapper = mount(<Dropdown.Button {...props} />);
|
2016-12-14 14:48:09 +08:00
|
|
|
const dropdownProps = wrapper.find(Dropdown).props();
|
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
Object.keys(props).forEach(key => {
|
2020-04-03 15:02:11 +08:00
|
|
|
expect(dropdownProps[key]).toBe(props[key]);
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
it("don't pass visible to Dropdown if it's not exits", () => {
|
2018-11-26 12:06:42 +08:00
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2021-06-29 17:55:02 +08:00
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
2018-11-26 12:06:42 +08:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<Dropdown.Button overlay={menu} />);
|
2016-12-14 14:48:09 +08:00
|
|
|
const dropdownProps = wrapper.find(Dropdown).props();
|
|
|
|
|
|
|
|
expect('visible' in dropdownProps).toBe(false);
|
|
|
|
});
|
2018-12-21 21:12:36 +08:00
|
|
|
|
|
|
|
it('should support href like Button', () => {
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2021-06-29 17:55:02 +08:00
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
2018-12-21 21:12:36 +08:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<Dropdown.Button overlay={menu} href="https://ant.design" />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2020-01-17 12:10:59 +08:00
|
|
|
|
|
|
|
it('have static property for type detecting', () => {
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2021-06-29 17:55:02 +08:00
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
2020-01-17 12:10:59 +08:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<Dropdown.Button overlay={menu} />);
|
2022-04-18 21:02:11 +08:00
|
|
|
expect(wrapper.find(Dropdown.Button).type().__ANT_BUTTON).toBe(true);
|
2020-01-17 12:10:59 +08:00
|
|
|
});
|
2021-05-10 10:37:52 +08:00
|
|
|
|
|
|
|
it('should pass mouseEnterDelay and mouseLeaveDelay to Dropdown', () => {
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2021-06-29 17:55:02 +08:00
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
2021-05-10 10:37:52 +08:00
|
|
|
</Menu>
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Dropdown.Button mouseEnterDelay={1} mouseLeaveDelay={2} overlay={menu} />,
|
|
|
|
);
|
2021-05-10 10:37:52 +08:00
|
|
|
expect(wrapper.find('Dropdown').props().mouseEnterDelay).toBe(1);
|
|
|
|
expect(wrapper.find('Dropdown').props().mouseLeaveDelay).toBe(2);
|
|
|
|
});
|
2021-06-29 17:55:02 +08:00
|
|
|
|
|
|
|
it('should support overlayClassName and overlayStyle', () => {
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item key="1">foo</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(
|
|
|
|
<Dropdown.Button
|
|
|
|
overlayClassName="className"
|
|
|
|
overlayStyle={{ color: 'red' }}
|
|
|
|
overlay={menu}
|
|
|
|
visible
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-dropdown').getDOMNode().className).toContain('className');
|
|
|
|
expect(wrapper.find('.ant-dropdown').getDOMNode().style.color).toContain('red');
|
|
|
|
});
|
2021-10-21 21:07:55 +08:00
|
|
|
|
|
|
|
it('should support loading', () => {
|
|
|
|
const wrapper = mount(<Dropdown.Button loading />);
|
|
|
|
|
|
|
|
expect(wrapper.find('.ant-dropdown-button .ant-btn-loading').getDOMNode().className).toContain(
|
|
|
|
'ant-btn',
|
|
|
|
);
|
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|