2017-01-16 21:13:59 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Menu from '..';
|
2017-07-01 14:04:26 +08:00
|
|
|
import Icon from '../../icon';
|
2019-03-14 21:04:13 +08:00
|
|
|
import Layout from '../../layout';
|
2017-01-16 21:13:59 +08:00
|
|
|
|
2018-08-30 16:33:11 +08:00
|
|
|
jest.mock('mutationobserver-shim', () => {
|
|
|
|
global.MutationObserver = function MutationObserver() {
|
|
|
|
this.observe = () => {};
|
|
|
|
this.disconnect = () => {};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2017-10-09 13:23:20 +08:00
|
|
|
const { SubMenu } = Menu;
|
2017-01-16 21:13:59 +08:00
|
|
|
|
|
|
|
describe('Menu', () => {
|
2017-11-16 17:12:36 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2018-06-01 18:09:11 +08:00
|
|
|
it('If has select nested submenu item ,the menu items on the grandfather level should be highlight', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultSelectedKeys={['1-3-2']} mode="vertical">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="1-1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="1-2">Option 2</Menu.Item>
|
|
|
|
<SubMenu key="1-3" title="submenu1-3">
|
|
|
|
<Menu.Item key="1-3-1">Option 3</Menu.Item>
|
|
|
|
<Menu.Item key="1-3-2">Option 4</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2018-06-01 18:09:11 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-submenu-selected').length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2017-01-16 21:13:59 +08:00
|
|
|
it('should accept defaultOpenKeys in mode horizontal', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultOpenKeys={['1']} mode="horizontal">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept defaultOpenKeys in mode inline', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultOpenKeys={['1']} mode="inline">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept defaultOpenKeys in mode vertical', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultOpenKeys={['1']} mode="vertical">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
it('horizontal', () => {
|
2017-01-16 21:13:59 +08:00
|
|
|
const wrapper = mount(
|
2017-02-15 18:00:20 +08:00
|
|
|
<Menu openKeys={['1']} mode="horizontal" openTransitionName="">
|
2017-01-16 21:13:59 +08:00
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: [] });
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: ['1'] });
|
2018-08-24 12:28:51 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
it('inline', () => {
|
2017-01-16 21:13:59 +08:00
|
|
|
const wrapper = mount(
|
2017-02-15 18:00:20 +08:00
|
|
|
<Menu openKeys={['1']} mode="inline" openAnimation="">
|
2017-01-16 21:13:59 +08:00
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: [] });
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: ['1'] });
|
2018-08-24 12:28:51 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
it('vertical', () => {
|
2017-01-16 21:13:59 +08:00
|
|
|
const wrapper = mount(
|
2017-02-15 18:00:20 +08:00
|
|
|
<Menu openKeys={['1']} mode="vertical" openTransitionName="">
|
2017-01-16 21:13:59 +08:00
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: [] });
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-02-15 18:00:20 +08:00
|
|
|
wrapper.setProps({ openKeys: ['1'] });
|
2018-08-24 12:28:51 +08:00
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
2017-01-23 19:10:50 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/pulls/4677
|
|
|
|
// https://github.com/ant-design/ant-design/issues/4692
|
|
|
|
// TypeError: Cannot read property 'indexOf' of undefined
|
|
|
|
it('pr #4677 and issue #4692', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="horizontal">
|
|
|
|
<SubMenu title="submenu">
|
|
|
|
<Menu.Item key="1">menu1</Menu.Item>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
|
|
|
</SubMenu>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-01-23 19:10:50 +08:00
|
|
|
);
|
|
|
|
wrapper.update();
|
|
|
|
// just expect no error emit
|
|
|
|
});
|
2017-02-15 16:24:56 +08:00
|
|
|
|
|
|
|
it('should always follow openKeys when mode is switched', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu openKeys={['1']} mode="inline">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-02-15 16:24:56 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-02-15 16:24:56 +08:00
|
|
|
wrapper.setProps({ mode: 'vertical' });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-02-15 16:24:56 +08:00
|
|
|
wrapper.setProps({ mode: 'inline' });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-02-15 16:24:56 +08:00
|
|
|
});
|
2017-06-30 23:08:11 +08:00
|
|
|
|
2018-04-29 23:01:58 +08:00
|
|
|
it('should always follow openKeys when inlineCollapsed is switched', () => {
|
2017-06-30 23:08:11 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultOpenKeys={['1']} mode="inline">
|
|
|
|
<Menu.Item key="menu1">
|
|
|
|
<Icon type="inbox" />
|
|
|
|
<span>Option</span>
|
|
|
|
</Menu.Item>
|
|
|
|
<SubMenu key="1" title="submenu1">
|
2018-12-07 16:17:45 +08:00
|
|
|
<Menu.Item key="submenu1">Option</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option</Menu.Item>
|
2017-06-30 23:08:11 +08:00
|
|
|
</SubMenu>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-06-30 23:08:11 +08:00
|
|
|
);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-inline'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-07-07 19:45:59 +08:00
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
|
|
|
// 动画结束后套样式;
|
|
|
|
jest.runAllTimers();
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
2018-10-30 15:09:40 +08:00
|
|
|
wrapper.simulate('transitionEnd', { propertyName: 'width' });
|
2017-07-07 16:51:06 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-root')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-vertical'),
|
|
|
|
).toBe(true);
|
2018-04-29 23:01:58 +08:00
|
|
|
expect(wrapper.find('ul.ant-menu-sub').length).toBe(0);
|
2017-11-11 00:07:03 +08:00
|
|
|
|
|
|
|
wrapper.setProps({ inlineCollapsed: false });
|
|
|
|
jest.runAllTimers();
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-inline'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-07-07 16:51:06 +08:00
|
|
|
});
|
|
|
|
|
2017-12-17 18:54:31 +08:00
|
|
|
it('inlineCollapsed should works well when specify a not existed default openKeys', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultOpenKeys={['not-existed']} mode="inline">
|
|
|
|
<Menu.Item key="menu1">
|
|
|
|
<Icon type="inbox" />
|
|
|
|
<span>Option</span>
|
|
|
|
</Menu.Item>
|
|
|
|
<SubMenu key="1" title="submenu1">
|
2018-12-07 16:17:45 +08:00
|
|
|
<Menu.Item key="submenu1">Option</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option</Menu.Item>
|
2017-12-17 18:54:31 +08:00
|
|
|
</SubMenu>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-12-17 18:54:31 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-sub').length).toBe(0);
|
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
2018-10-30 15:09:40 +08:00
|
|
|
wrapper.simulate('transitionEnd', { propertyName: 'width' });
|
2018-12-07 16:17:45 +08:00
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-submenu-title')
|
|
|
|
.at(0)
|
|
|
|
.simulate('mouseEnter');
|
2017-12-17 18:54:31 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-submenu')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-submenu-vertical'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-submenu')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-submenu-open'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-vertical'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('ul.ant-menu-sub')
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(false);
|
2017-12-17 18:54:31 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
describe('open submenu when click submenu title', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
const toggleMenu = (wrapper, index, event) => {
|
2018-12-07 16:17:45 +08:00
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-submenu-title')
|
|
|
|
.at(index)
|
|
|
|
.simulate(event);
|
2017-11-11 00:07:03 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
it('inline', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="inline">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-sub').length).toBe(0);
|
|
|
|
toggleMenu(wrapper, 0, 'click');
|
|
|
|
expect(wrapper.find('.ant-menu-sub').hostNodes().length).toBe(1);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
toggleMenu(wrapper, 0, 'click');
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('vertical', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="vertical">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-sub').length).toBe(0);
|
|
|
|
toggleMenu(wrapper, 0, 'mouseenter');
|
|
|
|
expect(wrapper.find('.ant-menu-sub').hostNodes().length).toBe(1);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
toggleMenu(wrapper, 0, 'mouseleave');
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('horizontal', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="horizontal">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-sub').length).toBe(0);
|
|
|
|
toggleMenu(wrapper, 0, 'mouseenter');
|
|
|
|
expect(wrapper.find('.ant-menu-sub').hostNodes().length).toBe(1);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).not.toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
toggleMenu(wrapper, 0, 'mouseleave');
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-menu-sub')
|
|
|
|
.hostNodes()
|
|
|
|
.at(0)
|
|
|
|
.hasClass('ant-menu-hidden'),
|
|
|
|
).toBe(true);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
2017-07-07 16:51:06 +08:00
|
|
|
});
|
2018-11-20 23:26:40 +08:00
|
|
|
|
|
|
|
it('inline title', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Menu mode="inline" inlineCollapsed>
|
2018-11-20 23:26:40 +08:00
|
|
|
<Menu.Item key="1" title="bamboo lucky">
|
|
|
|
<Icon type="pie-chart" />
|
|
|
|
<span>
|
|
|
|
Option 1
|
|
|
|
<img
|
|
|
|
style={{ width: 20 }}
|
|
|
|
alt="test"
|
|
|
|
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2018-11-20 23:26:40 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.find('.ant-menu-item').simulate('mouseenter');
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
const text = wrapper.find('.ant-tooltip-inner').text();
|
|
|
|
expect(text).toBe('bamboo lucky');
|
|
|
|
});
|
2019-03-14 21:04:13 +08:00
|
|
|
|
|
|
|
it('render correctly when using with Layout.Sider', () => {
|
|
|
|
class Demo extends React.Component {
|
|
|
|
state = {
|
|
|
|
collapsed: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
onCollapse = collapsed => this.setState({ collapsed });
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { collapsed } = this.state;
|
|
|
|
return (
|
|
|
|
<Layout style={{ minHeight: '100vh' }}>
|
|
|
|
<Layout.Sider collapsible collapsed={collapsed} onCollapse={this.onCollapse}>
|
|
|
|
<div className="logo" />
|
|
|
|
<Menu theme="dark" defaultSelectedKeys={['1']} mode="inline">
|
|
|
|
<SubMenu
|
|
|
|
key="sub1"
|
|
|
|
title={
|
|
|
|
<span>
|
|
|
|
<Icon type="user" />
|
|
|
|
<span>User</span>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Menu.Item key="3">Tom</Menu.Item>
|
|
|
|
<Menu.Item key="4">Bill</Menu.Item>
|
|
|
|
<Menu.Item key="5">Alex</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>
|
|
|
|
</Layout.Sider>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const wrapper = mount(<Demo />);
|
|
|
|
wrapper.find('.ant-menu-submenu-title').simulate('click');
|
|
|
|
wrapper.find('.ant-layout-sider-trigger').simulate('click');
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.find('.ant-menu-submenu-popup').length).toBe(0);
|
|
|
|
});
|
2019-03-25 19:07:22 +08:00
|
|
|
|
2019-03-09 11:53:17 +08:00
|
|
|
it('onMouseEnter should work', () => {
|
|
|
|
const event = { target: 'test' };
|
|
|
|
const onMouseEnter = e => {
|
|
|
|
expect(e).toEqual(event);
|
|
|
|
};
|
|
|
|
const wrapper = mount(<Menu onMouseEnter={onMouseEnter} />).instance();
|
|
|
|
wrapper.handleMouseEnter(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('onOpenChange should work', () => {
|
|
|
|
const event = [];
|
|
|
|
const onOpenChange = e => {
|
|
|
|
expect(e).toEqual(event);
|
|
|
|
};
|
|
|
|
const wrapper = mount(<Menu onOpenChange={onOpenChange} />).instance();
|
|
|
|
wrapper.handleOpenChange(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('get correct animation type when switched from inline', () => {
|
|
|
|
const wrapper = mount(<Menu mode="inline" />);
|
|
|
|
wrapper.setProps({ mode: 'horizontal' });
|
|
|
|
expect(wrapper.instance().getMenuOpenAnimation('')).toBe('');
|
|
|
|
expect(wrapper.instance().switchingModeFromInline).toBe(false);
|
|
|
|
});
|
|
|
|
|
2019-03-25 19:07:22 +08:00
|
|
|
it('Menu should not shake when collapsed changed', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu
|
|
|
|
defaultSelectedKeys={['5']}
|
|
|
|
defaultOpenKeys={['sub1']}
|
|
|
|
mode="inline"
|
|
|
|
inlineCollapsed={false}
|
|
|
|
>
|
|
|
|
<SubMenu
|
|
|
|
key="sub1"
|
|
|
|
title={
|
|
|
|
<span>
|
|
|
|
<span>Navigation One</span>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Menu.Item key="5">Option 5</Menu.Item>
|
|
|
|
<Menu.Item key="6">Option 6</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
expect(wrapper.instance().contextSiderCollapsed).toBe(true);
|
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
|
|
|
expect(wrapper.instance().contextSiderCollapsed).toBe(false);
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
expect(wrapper.instance().contextSiderCollapsed).toBe(false);
|
|
|
|
});
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|