ant-design/components/dropdown/__tests__/dropdown-button.test.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

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';
2016-12-14 14:48:09 +08:00
describe('DropdownButton', () => {
2019-08-26 22:53:20 +08:00
mountTest(() => <Dropdown menu={<Menu />}><span /></Dropdown>);
mountTest(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>
),
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 => {
expect(dropdownProps[key]).toBe(props[key]); // eslint-disable-line
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);
});
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();
});
2016-12-14 14:48:09 +08:00
});