2020-05-03 00:10:21 +08:00
|
|
|
import React, { useState } from 'react';
|
2017-01-16 21:13:59 +08:00
|
|
|
import { mount } from 'enzyme';
|
2020-04-26 23:16:15 +08:00
|
|
|
import {
|
|
|
|
MailOutlined,
|
|
|
|
InboxOutlined,
|
|
|
|
AppstoreOutlined,
|
|
|
|
PieChartOutlined,
|
|
|
|
UserOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2022-04-06 11:07:15 +08:00
|
|
|
import { render, fireEvent } from '@testing-library/react';
|
|
|
|
import '@testing-library/jest-dom';
|
2020-10-15 10:42:15 +08:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2017-01-16 21:13:59 +08:00
|
|
|
import Menu from '..';
|
2019-03-14 21:04:13 +08:00
|
|
|
import Layout from '../../layout';
|
2020-03-13 19:43:10 +08:00
|
|
|
import Tooltip from '../../tooltip';
|
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';
|
2020-09-20 21:13:43 +08:00
|
|
|
import collapseMotion from '../../_util/motion';
|
2017-01-16 21:13:59 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
|
2017-10-09 13:23:20 +08:00
|
|
|
const { SubMenu } = Menu;
|
2017-01-16 21:13:59 +08:00
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
const noop = () => {};
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
describe('Menu', () => {
|
|
|
|
function triggerAllTimer() {
|
|
|
|
for (let i = 0; i < 10; i += 1) {
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
}
|
2020-09-18 16:53:18 +08:00
|
|
|
}
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
const expectSubMenuBehavior = (defaultProps, instance, enter = noop, leave = noop) => {
|
|
|
|
const { container } = instance;
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
expect(container.querySelectorAll('ul.ant-menu-sub')).toHaveLength(0);
|
|
|
|
const AnimationClassNames = {
|
|
|
|
horizontal: 'ant-slide-up-leave',
|
|
|
|
inline: 'ant-motion-collapse-leave',
|
|
|
|
vertical: 'ant-zoom-big-leave',
|
|
|
|
};
|
|
|
|
const mode = defaultProps.mode || 'horizontal';
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
act(() => {
|
|
|
|
enter();
|
|
|
|
});
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
// React concurrent may delay creat this
|
|
|
|
triggerAllTimer();
|
|
|
|
|
|
|
|
function getSubMenu() {
|
|
|
|
if (mode === 'inline') {
|
|
|
|
return container.querySelector('ul.ant-menu-sub.ant-menu-inline');
|
|
|
|
}
|
|
|
|
return container.querySelector('div.ant-menu-submenu-popup');
|
|
|
|
}
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
expect(
|
2022-04-06 11:07:15 +08:00
|
|
|
getSubMenu().classList.contains('ant-menu-hidden') ||
|
|
|
|
getSubMenu().classList.contains(AnimationClassNames[mode]),
|
|
|
|
).toBeFalsy();
|
2020-09-18 16:53:18 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
act(() => {
|
|
|
|
leave();
|
|
|
|
});
|
|
|
|
|
|
|
|
// React concurrent may delay creat this
|
|
|
|
triggerAllTimer();
|
|
|
|
|
|
|
|
if (getSubMenu()) {
|
|
|
|
expect(
|
|
|
|
getSubMenu().classList.contains('ant-menu-hidden') ||
|
|
|
|
getSubMenu().classList.contains(AnimationClassNames[mode]),
|
|
|
|
).toBeTruthy();
|
|
|
|
}
|
|
|
|
};
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
// window.requestAnimationFrame = callback => window.setTimeout(callback, 16);
|
|
|
|
// window.cancelAnimationFrame = window.clearTimeout;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-06-01 10:11:24 +08:00
|
|
|
jest.useFakeTimers();
|
2022-04-06 11:07:15 +08:00
|
|
|
jest.clearAllTimers();
|
2021-06-01 10:11:24 +08:00
|
|
|
});
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
afterEach(() => {
|
2021-06-01 10:11:24 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2019-08-29 23:41:46 +08:00
|
|
|
mountTest(() => (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item />
|
|
|
|
<Menu.ItemGroup />
|
|
|
|
<Menu.SubMenu />
|
|
|
|
</Menu>
|
2020-01-02 19:10:16 +08:00
|
|
|
));
|
|
|
|
|
2020-09-09 16:52:04 +08:00
|
|
|
mountTest(() => (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item />
|
|
|
|
<>
|
|
|
|
<Menu.ItemGroup />
|
|
|
|
<Menu.SubMenu />
|
|
|
|
{null}
|
|
|
|
</>
|
2021-11-26 12:18:21 +08:00
|
|
|
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
|
2020-09-09 16:52:04 +08:00
|
|
|
<>
|
|
|
|
<Menu.Item />
|
|
|
|
</>
|
|
|
|
{undefined}
|
2021-11-26 12:18:21 +08:00
|
|
|
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
|
2020-09-09 16:52:04 +08:00
|
|
|
<>
|
2021-11-26 12:18:21 +08:00
|
|
|
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
|
2020-09-09 16:52:04 +08:00
|
|
|
<>
|
|
|
|
<Menu.Item />
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
</Menu>
|
|
|
|
));
|
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(() => (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item />
|
|
|
|
<Menu.ItemGroup />
|
|
|
|
<Menu.SubMenu />
|
|
|
|
</Menu>
|
2019-08-29 23:41:46 +08:00
|
|
|
));
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
let div;
|
|
|
|
|
2017-11-16 17:12:36 +08:00
|
|
|
beforeEach(() => {
|
2021-05-24 16:24:00 +08:00
|
|
|
div = document.createElement('div');
|
|
|
|
document.body.appendChild(div);
|
2017-11-16 17:12:36 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-05-24 16:24:00 +08:00
|
|
|
document.body.removeChild(div);
|
2017-11-16 17:12:36 +08:00
|
|
|
});
|
|
|
|
|
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
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('li.ant-menu-submenu-selected').length).toBe(1);
|
2018-06-01 18:09:11 +08:00
|
|
|
});
|
|
|
|
|
2021-04-28 15:12:54 +08:00
|
|
|
it('forceSubMenuRender', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="horizontal">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="1-1">
|
|
|
|
<span className="bamboo" />
|
|
|
|
</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('.bamboo').hostNodes()).toHaveLength(0);
|
|
|
|
|
|
|
|
wrapper.setProps({ forceSubMenuRender: true });
|
|
|
|
expect(wrapper.find('.bamboo').hostNodes()).toHaveLength(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
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.exists('.ant-menu-sub')).toBeFalsy();
|
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
|
|
|
);
|
2020-04-26 23:16:15 +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
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('PopupTrigger').first().prop('visible')).toBeTruthy();
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
it('should accept openKeys in mode horizontal', () => {
|
2017-01-16 21:13:59 +08:00
|
|
|
const wrapper = mount(
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu openKeys={['1']} mode="horizontal">
|
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
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('PopupTrigger').first().prop('visible')).toBeTruthy();
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept openKeys in mode inline', () => {
|
|
|
|
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>
|
|
|
|
</Menu>,
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('InlineSubMenuList').first().prop('open')).toBeTruthy();
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
it('should accept openKeys in mode vertical', () => {
|
2017-01-16 21:13:59 +08:00
|
|
|
const wrapper = mount(
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu openKeys={['1']} mode="vertical">
|
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
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('PopupTrigger').first().prop('visible')).toBeTruthy();
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
it('test submenu in mode horizontal', async () => {
|
|
|
|
const defaultProps = {
|
|
|
|
mode: 'horizontal',
|
|
|
|
};
|
|
|
|
|
|
|
|
const Demo = props => (
|
|
|
|
<Menu {...defaultProps} {...props}>
|
2020-09-18 16:53:18 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => instance.rerender(<Demo openKeys={['1']} />),
|
|
|
|
() => instance.rerender(<Demo openKeys={[]} />),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
instance.rerender(<Demo openKeys={['1']} />);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
it('test submenu in mode inline', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'inline' };
|
|
|
|
|
|
|
|
const Demo = props => (
|
|
|
|
<Menu {...defaultProps} {...props}>
|
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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-01-16 21:13:59 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
const instance = render(<Demo />);
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => instance.rerender(<Demo openKeys={['1']} />),
|
|
|
|
() => instance.rerender(<Demo openKeys={[]} />),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('test submenu in mode vertical', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'vertical', openTransitionName: '' };
|
|
|
|
|
|
|
|
const Demo = props => (
|
|
|
|
<Menu {...defaultProps} {...props}>
|
2020-09-18 16:53:18 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2020-09-18 16:53:18 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => instance.rerender(<Demo openKeys={['1']} />),
|
|
|
|
() => instance.rerender(<Demo openKeys={[]} />),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
2017-01-23 19:10:50 +08:00
|
|
|
|
2022-02-14 15:21:33 +08:00
|
|
|
describe('allows the overriding of theme at the popup submenu level', () => {
|
|
|
|
const menuModesWithPopupSubMenu = ['horizontal', 'vertical'];
|
|
|
|
|
|
|
|
menuModesWithPopupSubMenu.forEach(menuMode => {
|
|
|
|
it(`when menu is mode ${menuMode}`, () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const { container } = render(
|
2022-02-14 15:21:33 +08:00
|
|
|
<Menu mode={menuMode} openKeys={['1']} theme="dark">
|
|
|
|
<SubMenu key="1" title="submenu1" theme="light">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="submenu2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Item key="2">menu2</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-root')).toHaveClass('ant-menu-dark');
|
|
|
|
expect(container.querySelector('div.ant-menu-submenu-popup')).toHaveClass('ant-menu-light');
|
2022-02-14 15:21:33 +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', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
render(
|
2017-01-23 19:10:50 +08:00
|
|
|
<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
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2017-01-23 19:10:50 +08:00
|
|
|
// just expect no error emit
|
|
|
|
});
|
2017-02-15 16:24:56 +08:00
|
|
|
|
|
|
|
it('should always follow openKeys when mode is switched', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const Demo = props => (
|
|
|
|
<Menu openKeys={['1']} mode="inline" {...props}>
|
2017-02-15 16:24:56 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-02-15 16:24:56 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const { container, rerender } = render(<Demo />);
|
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).not.toHaveClass('ant-menu-hidden');
|
|
|
|
|
|
|
|
rerender(<Demo mode="vertical" />);
|
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).not.toHaveClass('ant-menu-hidden');
|
|
|
|
|
|
|
|
rerender(<Demo mode="inline" />);
|
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).not.toHaveClass('ant-menu-hidden');
|
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">
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="menu1" icon={<InboxOutlined />}>
|
|
|
|
Option
|
2017-06-30 23:08:11 +08:00
|
|
|
</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
|
|
|
);
|
2017-07-07 19:45:59 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('InlineSubMenuList').prop('open')).toBeTruthy();
|
2017-07-07 16:51:06 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
// inlineCollapsed
|
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
2020-11-11 19:05:01 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
});
|
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('ul.ant-menu-root').hasClass('ant-menu-vertical')).toBeTruthy();
|
|
|
|
expect(wrapper.find('PopupTrigger').prop('visible')).toBeFalsy();
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
// !inlineCollapsed
|
2017-11-11 00:07:03 +08:00
|
|
|
wrapper.setProps({ inlineCollapsed: false });
|
2021-05-24 16:24:00 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
});
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('ul.ant-menu-sub').last().hasClass('ant-menu-inline')).toBeTruthy();
|
|
|
|
expect(wrapper.find('InlineSubMenuList').prop('open')).toBeTruthy();
|
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', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const Demo = props => (
|
|
|
|
<Menu defaultOpenKeys={['not-existed']} mode="inline" {...props}>
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="menu1" icon={<InboxOutlined />}>
|
|
|
|
Option
|
2017-12-17 18:54:31 +08:00
|
|
|
</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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-12-17 18:54:31 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
const { container, rerender } = render(<Demo />);
|
|
|
|
|
|
|
|
expect(container.querySelectorAll('.ant-menu-sub')).toHaveLength(0);
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
rerender(<Demo inlineCollapsed />);
|
2020-11-11 19:05:01 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
const transitionEndEvent = new Event('transitionend');
|
|
|
|
fireEvent(container.querySelector('ul'), transitionEndEvent);
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.mouseEnter(container.querySelector('.ant-menu-submenu-title'));
|
|
|
|
triggerAllTimer();
|
|
|
|
|
|
|
|
expect(container.querySelector('.ant-menu-submenu')).toHaveClass('ant-menu-submenu-vertical');
|
|
|
|
expect(container.querySelector('.ant-menu-submenu')).toHaveClass('ant-menu-submenu-open');
|
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).toHaveClass('ant-menu-vertical');
|
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).not.toHaveClass('ant-menu-hidden');
|
2017-12-17 18:54:31 +08:00
|
|
|
});
|
|
|
|
|
2020-03-13 19:43:10 +08:00
|
|
|
it('inlineCollapsed Menu.Item Tooltip can be removed', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu
|
|
|
|
defaultOpenKeys={['not-existed']}
|
|
|
|
mode="inline"
|
|
|
|
inlineCollapsed
|
|
|
|
getPopupContainer={node => node.parentNode}
|
|
|
|
>
|
2020-03-29 10:39:46 +08:00
|
|
|
<Menu.Item key="menu1">item</Menu.Item>
|
2020-03-13 19:43:10 +08:00
|
|
|
<Menu.Item key="menu2" title="title">
|
|
|
|
item
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="menu3" title={undefined}>
|
|
|
|
item
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="menu4" title={null}>
|
|
|
|
item
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="menu5" title="">
|
|
|
|
item
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="menu6" title={false}>
|
|
|
|
item
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2020-04-26 23:16:15 +08:00
|
|
|
expect(wrapper.find(Menu.Item).at(0).find(Tooltip).props().title).toBe('item');
|
|
|
|
expect(wrapper.find(Menu.Item).at(1).find(Tooltip).props().title).toBe('title');
|
|
|
|
expect(wrapper.find(Menu.Item).at(2).find(Tooltip).props().title).toBe('item');
|
|
|
|
expect(wrapper.find(Menu.Item).at(3).find(Tooltip).props().title).toBe(null);
|
|
|
|
expect(wrapper.find(Menu.Item).at(4).find(Tooltip).props().title).toBe('');
|
|
|
|
expect(wrapper.find(Menu.Item).at(4).find(Tooltip).props().title).toBe('');
|
2020-03-13 19:43:10 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
describe('open submenu when click submenu title', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const toggleMenu = (instance, index, event) => {
|
|
|
|
fireEvent[event](instance.container.querySelectorAll('.ant-menu-submenu-title')[index]);
|
|
|
|
|
|
|
|
triggerAllTimer();
|
2017-11-11 00:07:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
it('inline', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'inline' };
|
|
|
|
|
|
|
|
const Demo = props => (
|
|
|
|
<Menu {...defaultProps} {...props}>
|
2017-11-11 00:07:03 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
|
|
|
|
2020-09-20 21:13:43 +08:00
|
|
|
it('inline menu collapseMotion should be triggered', async () => {
|
2021-05-24 16:24:00 +08:00
|
|
|
const cloneMotion = {
|
|
|
|
...collapseMotion,
|
|
|
|
motionDeadline: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
const onOpenChange = jest.fn();
|
|
|
|
const onEnterEnd = jest.spyOn(cloneMotion, 'onEnterEnd');
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
const { container } = render(
|
2021-05-24 16:24:00 +08:00
|
|
|
<Menu mode="inline" motion={cloneMotion} onOpenChange={onOpenChange}>
|
2020-09-20 21:13:43 +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>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-menu-submenu-title'));
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
triggerAllTimer();
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
expect(onOpenChange).toHaveBeenCalled();
|
|
|
|
expect(onEnterEnd).toHaveBeenCalledTimes(1);
|
2020-09-20 21:13:43 +08:00
|
|
|
});
|
|
|
|
|
2020-06-28 22:41:59 +08:00
|
|
|
it('vertical with hover(default)', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'vertical' };
|
|
|
|
|
|
|
|
const Demo = () => (
|
|
|
|
<Menu {...defaultProps}>
|
2017-11-11 00:07:03 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'mouseEnter'),
|
|
|
|
() => toggleMenu(instance, 0, 'mouseLeave'),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
|
|
|
|
2020-06-28 22:41:59 +08:00
|
|
|
it('vertical with click', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'vertical', triggerSubMenuAction: 'click' };
|
|
|
|
const Demo = () => (
|
|
|
|
<Menu {...defaultProps}>
|
2020-06-28 22:41: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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('horizontal with hover(default)', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'horizontal' };
|
|
|
|
const Demo = () => (
|
|
|
|
<Menu {...defaultProps}>
|
2017-11-11 00:07:03 +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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2017-11-11 00:07:03 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'mouseEnter'),
|
|
|
|
() => toggleMenu(instance, 0, 'mouseLeave'),
|
2020-04-26 23:16:15 +08:00
|
|
|
);
|
2017-11-11 00:07:03 +08:00
|
|
|
});
|
2020-06-28 22:41:59 +08:00
|
|
|
|
|
|
|
it('horizontal with click', () => {
|
2022-04-06 11:07:15 +08:00
|
|
|
const defaultProps = { mode: 'horizontal', triggerSubMenuAction: 'click' };
|
|
|
|
const Demo = () => (
|
|
|
|
<Menu {...defaultProps}>
|
2020-06-28 22:41: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>
|
2022-04-06 11:07:15 +08:00
|
|
|
</Menu>
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
|
|
|
|
const instance = render(<Demo />);
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
expectSubMenuBehavior(
|
2022-04-06 11:07:15 +08:00
|
|
|
defaultProps,
|
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
|
|
|
});
|
2017-07-07 16:51:06 +08:00
|
|
|
});
|
2018-11-20 23:26:40 +08:00
|
|
|
|
|
|
|
it('inline title', () => {
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Menu mode="inline" inlineCollapsed>
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="1" title="bamboo lucky" icon={<PieChartOutlined />}>
|
|
|
|
Option 1
|
|
|
|
<img
|
|
|
|
style={{ width: 20 }}
|
|
|
|
alt="test"
|
|
|
|
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
|
|
/>
|
2018-11-20 23:26:40 +08:00
|
|
|
</Menu.Item>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Menu>,
|
2018-11-20 23:26:40 +08:00
|
|
|
);
|
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
wrapper.find('.ant-menu-item').hostNodes().simulate('mouseenter');
|
2022-04-06 11:07:15 +08:00
|
|
|
triggerAllTimer();
|
2018-11-20 23:26:40 +08:00
|
|
|
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">
|
2020-09-18 16:53:18 +08:00
|
|
|
<SubMenu key="sub1" icon={<UserOutlined />} title="User">
|
2019-03-14 21:04:13 +08:00
|
|
|
<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 />);
|
2020-10-15 10:42:15 +08:00
|
|
|
expect(wrapper.find(Menu).at(0).getDOMNode().classList.contains('ant-menu-inline')).toBe(true);
|
2019-03-14 21:04:13 +08:00
|
|
|
wrapper.find('.ant-menu-submenu-title').simulate('click');
|
|
|
|
wrapper.find('.ant-layout-sider-trigger').simulate('click');
|
2022-04-06 11:07:15 +08:00
|
|
|
triggerAllTimer();
|
2019-03-14 21:04:13 +08:00
|
|
|
wrapper.update();
|
2020-10-15 10:42:15 +08:00
|
|
|
expect(wrapper.find(Menu).getDOMNode().classList.contains('ant-menu-inline-collapsed')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
wrapper.find(Menu).simulate('mouseenter');
|
|
|
|
expect(wrapper.find(Menu).getDOMNode().classList.contains('ant-menu-inline')).toBe(false);
|
|
|
|
expect(wrapper.find(Menu).getDOMNode().classList.contains('ant-menu-vertical')).toBe(true);
|
2019-03-14 21:04:13 +08:00
|
|
|
});
|
2019-03-25 19:07:22 +08:00
|
|
|
|
2019-03-09 11:53:17 +08:00
|
|
|
it('onMouseEnter should work', () => {
|
2019-03-15 21:56:41 +08:00
|
|
|
const onMouseEnter = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu onMouseEnter={onMouseEnter} defaultSelectedKeys={['test1']}>
|
|
|
|
<Menu.Item key="test1">Navigation One</Menu.Item>
|
|
|
|
<Menu.Item key="test2">Navigation Two</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
wrapper.find('ul.ant-menu-root').simulate('mouseenter');
|
2019-03-15 21:56:41 +08:00
|
|
|
expect(onMouseEnter).toHaveBeenCalled();
|
2019-03-09 11:53:17 +08:00
|
|
|
});
|
|
|
|
|
2019-03-28 09:24:16 +08:00
|
|
|
it('MenuItem should not render Tooltip when inlineCollapsed is false', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu defaultSelectedKeys={['mail']} defaultOpenKeys={['mail']} mode="horizontal">
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="mail" icon={<MailOutlined />}>
|
2019-03-28 09:24:16 +08:00
|
|
|
Navigation One
|
|
|
|
</Menu.Item>
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="app" icon={<AppstoreOutlined />}>
|
2019-03-28 09:24:16 +08:00
|
|
|
Navigation Two
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="alipay">
|
|
|
|
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
|
|
|
|
Navigation Four - Link
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
2021-05-24 16:24:00 +08:00
|
|
|
{ attachTo: div },
|
2019-03-28 09:24:16 +08:00
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
wrapper.find('li.ant-menu-item').first().simulate('mouseenter');
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
});
|
|
|
|
|
2019-03-28 09:24:16 +08:00
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBe(0);
|
|
|
|
});
|
2019-04-05 16:15:01 +08:00
|
|
|
|
2020-04-26 23:16:15 +08:00
|
|
|
it('MenuItem should render icon and icon should be the first child when icon exists', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item key="mail" icon={<MailOutlined />}>
|
|
|
|
Navigation One
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-menu-item .anticon').hasClass('anticon-mail')).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-04-05 16:15:01 +08:00
|
|
|
it('should controlled collapse work', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="inline" inlineCollapsed={false}>
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="1" icon={<PieChartOutlined />}>
|
|
|
|
Option 1
|
2019-04-05 16:15:01 +08:00
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
|
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
|
|
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-04-08 22:20:18 +08:00
|
|
|
|
|
|
|
it('not title if not collapsed', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="inline" inlineCollapsed={false}>
|
2020-09-18 16:53:18 +08:00
|
|
|
<Menu.Item key="1" icon={<PieChartOutlined />}>
|
|
|
|
Option 1
|
2019-04-08 22:20:18 +08:00
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
wrapper.find('.ant-menu-item').hostNodes().simulate('mouseenter');
|
2019-04-08 22:20:18 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
|
|
|
|
expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy();
|
|
|
|
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2019-07-09 11:46:21 +08:00
|
|
|
|
|
|
|
it('props#onOpen and props#onClose do not warn anymore', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
const onOpen = jest.fn();
|
|
|
|
const onClose = jest.fn();
|
2022-04-06 11:07:15 +08:00
|
|
|
render(
|
2019-07-09 11:46:21 +08:00
|
|
|
<Menu defaultOpenKeys={['1']} mode="inline" onOpen={onOpen} onClose={onClose}>
|
|
|
|
<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>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(errorSpy.mock.calls.length).toBe(1);
|
|
|
|
expect(errorSpy.mock.calls[0][0]).not.toContain(
|
|
|
|
'`onOpen` and `onClose` are removed, please use `onOpenChange` instead, see: https://u.ant.design/menu-on-open-change.',
|
|
|
|
);
|
|
|
|
expect(onOpen).not.toHaveBeenCalled();
|
|
|
|
expect(onClose).not.toHaveBeenCalled();
|
|
|
|
});
|
2019-09-23 10:08:32 +08:00
|
|
|
|
2019-09-19 22:04:24 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/18825
|
|
|
|
// https://github.com/ant-design/ant-design/issues/8587
|
|
|
|
it('should keep selectedKeys in state when collapsed to 0px', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu
|
|
|
|
mode="inline"
|
|
|
|
inlineCollapsed={false}
|
|
|
|
defaultSelectedKeys={['1']}
|
|
|
|
collapsedWidth={0}
|
|
|
|
openKeys={['3']}
|
|
|
|
>
|
2019-09-23 10:08:32 +08:00
|
|
|
<Menu.Item key="1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="2">Option 2</Menu.Item>
|
2019-09-19 22:04:24 +08:00
|
|
|
<Menu.SubMenu key="3" title="Option 3">
|
2019-09-23 10:08:32 +08:00
|
|
|
<Menu.Item key="4">Option 4</Menu.Item>
|
2019-09-19 22:04:24 +08:00
|
|
|
</Menu.SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('li.ant-menu-item-selected').getDOMNode().textContent).toBe('Option 1');
|
|
|
|
wrapper.find('li.ant-menu-item').at(1).simulate('click');
|
|
|
|
expect(wrapper.find('li.ant-menu-item-selected').getDOMNode().textContent).toBe('Option 2');
|
2019-09-19 22:04:24 +08:00
|
|
|
wrapper.setProps({ inlineCollapsed: true });
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.update();
|
|
|
|
});
|
|
|
|
|
2019-12-05 16:15:10 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
2021-05-24 16:24:00 +08:00
|
|
|
.find('PopupTrigger')
|
2019-12-05 16:15:10 +08:00
|
|
|
.map(node => node.prop('popupVisible'))
|
|
|
|
.findIndex(node => !!node),
|
|
|
|
).toBe(-1);
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2019-09-19 22:04:24 +08:00
|
|
|
wrapper.setProps({ inlineCollapsed: false });
|
2021-05-24 16:24:00 +08:00
|
|
|
expect(wrapper.find('li.ant-menu-item-selected').getDOMNode().textContent).toBe('Option 2');
|
2019-09-19 22:04:24 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2020-04-26 23:16:15 +08:00
|
|
|
|
|
|
|
it('Menu.Item with icon children auto wrap span', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu>
|
|
|
|
<Menu.Item key="1" icon={<MailOutlined />}>
|
|
|
|
Navigation One
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="2" icon={<MailOutlined />}>
|
|
|
|
<span>Navigation One</span>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.SubMenu key="3" icon={<MailOutlined />} title="Navigation One" />
|
|
|
|
<Menu.SubMenu key="4" icon={<MailOutlined />} title={<span>Navigation One</span>} />
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2020-05-03 00:10:21 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/23755
|
|
|
|
it('should trigger onOpenChange when collapse inline menu', () => {
|
|
|
|
const onOpenChange = jest.fn();
|
|
|
|
function App() {
|
|
|
|
const [inlineCollapsed, setInlineCollapsed] = useState(false);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
setInlineCollapsed(!inlineCollapsed);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
collapse menu
|
|
|
|
</button>
|
|
|
|
<Menu mode="inline" onOpenChange={onOpenChange} inlineCollapsed={inlineCollapsed}>
|
|
|
|
<Menu.SubMenu key="1" title="menu">
|
|
|
|
<Menu.Item key="1-1">menu</Menu.Item>
|
|
|
|
<Menu.Item key="1-2">menu</Menu.Item>
|
|
|
|
</Menu.SubMenu>
|
|
|
|
</Menu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const wrapper = mount(<App />);
|
|
|
|
wrapper.find('button').simulate('click');
|
|
|
|
expect(onOpenChange).toHaveBeenCalledWith([]);
|
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
it('Use first char as Icon when collapsed', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="inline" inlineCollapsed>
|
2021-05-24 17:36:18 +08:00
|
|
|
<Menu.SubMenu title="Light" />
|
2021-05-24 16:24:00 +08:00
|
|
|
<Menu.Item>Bamboo</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
2021-05-24 17:36:18 +08:00
|
|
|
expect(wrapper.find('.ant-menu-inline-collapsed-noicon').first().text()).toEqual('L');
|
|
|
|
expect(wrapper.find('.ant-menu-inline-collapsed-noicon').last().text()).toEqual('B');
|
2021-05-24 16:24:00 +08:00
|
|
|
});
|
2021-07-19 15:42:07 +08:00
|
|
|
|
|
|
|
it('divider should show', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Menu mode="vertical">
|
|
|
|
<SubMenu key="sub1" title="Navigation One">
|
|
|
|
<Menu.Item key="1">Option 1</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Divider dashed />
|
|
|
|
<SubMenu key="sub2" title="Navigation Two">
|
|
|
|
<Menu.Item key="2">Option 2</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
<Menu.Divider />
|
|
|
|
<SubMenu key="sub4" title="Navigation Three">
|
|
|
|
<Menu.Item key="3">Option 3</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('li.ant-menu-item-divider').length).toBe(2);
|
|
|
|
expect(wrapper.find('li.ant-menu-item-divider-dashed').length).toBe(1);
|
|
|
|
});
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|