2016-12-14 14:48:09 +08:00
|
|
|
import React from 'react';
|
2018-11-26 12:06:42 +08:00
|
|
|
import { mount } from 'enzyme';
|
2016-12-14 14:48:09 +08:00
|
|
|
import Dropdown from '..';
|
|
|
|
import Menu from '../../menu';
|
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';
|
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>
|
|
|
|
<Menu.Item>foo</Menu.Item>
|
|
|
|
</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>
|
|
|
|
<Menu.Item>foo</Menu.Item>
|
|
|
|
</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>
|
|
|
|
<Menu.Item>foo</Menu.Item>
|
|
|
|
</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>
|
|
|
|
<Menu.Item>foo</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<Dropdown.Button overlay={menu} />);
|
|
|
|
expect(wrapper.type().__ANT_BUTTON).toBe(true);
|
|
|
|
});
|
2021-05-10 10:37:52 +08:00
|
|
|
|
|
|
|
it('should pass mouseEnterDelay and mouseLeaveDelay to Dropdown', () => {
|
|
|
|
const menu = (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item>foo</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<Dropdown.Button mouseEnterDelay={1} mouseLeaveDelay={2} overlay={menu} />);
|
|
|
|
expect(wrapper.find('Dropdown').props().mouseEnterDelay).toBe(1);
|
|
|
|
expect(wrapper.find('Dropdown').props().mouseLeaveDelay).toBe(2);
|
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|