Browse Source

Fix test case for menu

pull/6763/head
afc163 7 years ago
parent
commit
f2268c2877
  1. 20
      components/menu/__tests__/index.test.js

20
components/menu/__tests__/index.test.js

@ -3,6 +3,7 @@ import { mount } from 'enzyme';
import Menu from '..';
const SubMenu = Menu.SubMenu;
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
describe('Menu', () => {
it('should accept defaultOpenKeys in mode horizontal', () => {
@ -128,10 +129,10 @@ describe('Menu', () => {
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
});
it('should open submenu when click submenu title (inline)', () => {
it('should open submenu when click submenu title (inline)', async () => {
const wrapper = mount(
<Menu mode="inline">
<SubMenu key="1" title={<div id="submenu">submenu1</div>}>
<SubMenu key="1" title="submenu1">
<Menu.Item key="submenu1">Option 1</Menu.Item>
<Menu.Item key="submenu2">Option 2</Menu.Item>
</SubMenu>
@ -139,15 +140,18 @@ describe('Menu', () => {
</Menu>
);
expect(wrapper.find('.ant-menu-sub').length).toBe(0);
wrapper.find('#submenu').simulate('click');
wrapper.find('.ant-menu-submenu-title').simulate('click');
expect(wrapper.find('.ant-menu-sub').length).toBe(1);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
wrapper.find('.ant-menu-submenu-title').simulate('click');
await delay(300);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(true);
});
it('should open submenu when hover submenu title (vertical)', async () => {
const wrapper = mount(
<Menu mode="vertical">
<SubMenu key="1" title={<div id="submenu">submenu1</div>}>
<SubMenu key="1" title="submenu1">
<Menu.Item key="submenu1">Option 1</Menu.Item>
<Menu.Item key="submenu2">Option 2</Menu.Item>
</SubMenu>
@ -158,12 +162,15 @@ describe('Menu', () => {
wrapper.find('.ant-menu-submenu-title').simulate('mouseenter');
expect(wrapper.find('.ant-menu-sub').length).toBe(1);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
wrapper.find('.ant-menu-submenu').simulate('mouseleave');
await delay(300);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(true);
});
it('should open submenu when hover submenu title (horizontal)', async () => {
const wrapper = mount(
<Menu mode="horizontal">
<SubMenu key="1" title={<div id="submenu">submenu1</div>}>
<SubMenu key="1" title="submenu1">
<Menu.Item key="submenu1">Option 1</Menu.Item>
<Menu.Item key="submenu2">Option 2</Menu.Item>
</SubMenu>
@ -174,5 +181,8 @@ describe('Menu', () => {
wrapper.find('.ant-menu-submenu-title').simulate('mouseenter');
expect(wrapper.find('.ant-menu-sub').length).toBe(1);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
wrapper.find('.ant-menu-submenu').simulate('mouseleave');
await delay(300);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(true);
});
});

Loading…
Cancel
Save