2020-04-26 23:16:15 +08:00
|
|
|
import {
|
|
|
|
AppstoreOutlined,
|
2022-06-22 14:57:09 +08:00
|
|
|
InboxOutlined,
|
|
|
|
MailOutlined,
|
2020-04-26 23:16:15 +08:00
|
|
|
PieChartOutlined,
|
|
|
|
UserOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2022-08-30 10:06:38 +08:00
|
|
|
import React, { useState, useMemo } from 'react';
|
2022-08-30 13:05:50 +08:00
|
|
|
import type { MenuProps, MenuRef } from '..';
|
2017-01-16 21:13:59 +08:00
|
|
|
import Menu from '..';
|
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';
|
2022-08-08 13:31:55 +08:00
|
|
|
import { fireEvent, render, act } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Layout from '../../layout';
|
2022-07-19 22:53:38 +08:00
|
|
|
import initCollapseMotion from '../../_util/motion';
|
2022-05-10 15:43:29 +08:00
|
|
|
import { noop } from '../../_util/warning';
|
2017-01-16 21:13:59 +08:00
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', {
|
|
|
|
writable: true,
|
|
|
|
value: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
type MouseEvent = 'click' | 'mouseEnter' | 'mouseLeave';
|
2022-04-06 11:07:15 +08:00
|
|
|
|
2017-10-09 13:23:20 +08:00
|
|
|
const { SubMenu } = Menu;
|
2017-01-16 21:13:59 +08:00
|
|
|
|
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-08-30 10:06:38 +08:00
|
|
|
const expectSubMenuBehavior = (
|
2022-09-30 17:44:24 +08:00
|
|
|
defaultTestProps: MenuProps,
|
2022-08-30 10:06:38 +08:00
|
|
|
instance: ReturnType<typeof render>,
|
|
|
|
enter = noop,
|
|
|
|
leave = noop,
|
|
|
|
) => {
|
2022-04-06 11:07:15 +08:00
|
|
|
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',
|
|
|
|
};
|
2022-09-30 17:44:24 +08:00
|
|
|
const mode = defaultTestProps.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() {
|
2022-08-30 10:06:38 +08:00
|
|
|
return container.querySelector<HTMLUListElement | HTMLDivElement>(
|
|
|
|
mode === 'inline' ? 'ul.ant-menu-sub.ant-menu-inline' : 'div.ant-menu-submenu-popup',
|
|
|
|
);
|
2022-04-06 11:07:15 +08:00
|
|
|
}
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
expect(
|
2022-08-30 10:06:38 +08:00
|
|
|
getSubMenu()?.classList.contains('ant-menu-hidden') ||
|
|
|
|
getSubMenu()?.classList.contains(AnimationClassNames[mode]),
|
2022-04-06 11:07:15 +08:00
|
|
|
).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();
|
2020-11-11 19:05:01 +08:00
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
if (getSubMenu()) {
|
|
|
|
expect(
|
2022-08-30 10:06:38 +08:00
|
|
|
getSubMenu()?.classList.contains('ant-menu-hidden') ||
|
|
|
|
getSubMenu()?.classList.contains(AnimationClassNames[mode]),
|
2022-04-06 11:07:15 +08:00
|
|
|
).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>
|
|
|
|
));
|
|
|
|
|
2022-09-07 14:18:32 +08:00
|
|
|
const RtlDemo: React.FC = () => (
|
2020-01-02 19:10:16 +08:00
|
|
|
<Menu>
|
|
|
|
<Menu.Item />
|
|
|
|
<Menu.ItemGroup />
|
|
|
|
<Menu.SubMenu />
|
|
|
|
</Menu>
|
2022-09-07 14:18:32 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
rtlTest(RtlDemo, { componentName: 'menu' });
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
let div: HTMLDivElement;
|
2021-05-24 16:24:00 +08:00
|
|
|
|
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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2018-06-01 18:09:11 +08:00
|
|
|
<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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelectorAll('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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container, rerender } = render(
|
2021-04-28 15:12:54 +08:00
|
|
|
<Menu mode="horizontal">
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="1-1">
|
|
|
|
<span className="bamboo" />
|
|
|
|
</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('.bamboo')).toBeFalsy();
|
2021-04-28 15:12:54 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
rerender(
|
|
|
|
<Menu mode="horizontal" forceSubMenuRender>
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="1-1">
|
|
|
|
<span className="bamboo" />
|
|
|
|
</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('.bamboo')).toBeTruthy();
|
2021-04-28 15:12:54 +08:00
|
|
|
});
|
|
|
|
|
2017-01-16 21:13:59 +08:00
|
|
|
it('should accept defaultOpenKeys in mode horizontal', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2017-01-16 21:13:59 +08:00
|
|
|
<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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
|
|
|
|
expect(
|
2022-08-30 10:06:38 +08:00
|
|
|
container.querySelector('.ant-menu-submenu-open')?.querySelector('.ant-menu-submenu-title')
|
|
|
|
?.textContent,
|
2022-08-15 16:43:41 +08:00
|
|
|
).toEqual('submenu1');
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept defaultOpenKeys in mode inline', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2017-01-16 21:13:59 +08:00
|
|
|
<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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
|
|
|
|
expect(
|
2022-08-30 10:06:38 +08:00
|
|
|
container.querySelector('.ant-menu-submenu-open')?.querySelector('.ant-menu-submenu-title')
|
|
|
|
?.textContent,
|
2022-08-15 16:43:41 +08:00
|
|
|
).toEqual('submenu1');
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept defaultOpenKeys in mode vertical', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2017-01-16 21:13:59 +08:00
|
|
|
<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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('.ant-menu-sub')).toBeFalsy();
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
it('should accept openKeys in mode horizontal', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
triggerAllTimer();
|
|
|
|
expect(container.querySelector('div.ant-menu-submenu-popup')).not.toHaveClass(
|
|
|
|
'ant-menu-submenu-hidden',
|
|
|
|
);
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept openKeys in mode inline', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2020-09-18 16:53:18 +08:00
|
|
|
<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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).not.toHaveClass('ant-menu-hidden');
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|
|
|
|
|
2020-09-18 16:53:18 +08:00
|
|
|
it('should accept openKeys in mode vertical', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
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
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
triggerAllTimer();
|
|
|
|
expect(container.querySelector('div.ant-menu-submenu-popup')).not.toHaveClass(
|
|
|
|
'ant-menu-submenu-hidden',
|
|
|
|
);
|
2020-09-18 16:53:18 +08:00
|
|
|
});
|
|
|
|
|
2022-04-06 11:07:15 +08:00
|
|
|
it('test submenu in mode horizontal', async () => {
|
2022-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'horizontal' };
|
2022-04-06 11:07:15 +08:00
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps} {...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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'inline' };
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps} {...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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'vertical' };
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps} {...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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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-09-19 22:17:26 +08:00
|
|
|
describe('allows the overriding of theme at the popup submenu level', () => {
|
|
|
|
const menuModesWithPopupSubMenu: MenuProps['mode'][] = ['horizontal', 'vertical'];
|
2022-11-19 13:47:33 +08:00
|
|
|
menuModesWithPopupSubMenu.forEach((menuMode) => {
|
2022-09-19 22:17:26 +08:00
|
|
|
it(`when menu is mode ${menuMode}`, () => {
|
|
|
|
const { container } = render(
|
|
|
|
<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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-04-06 11:07:15 +08:00
|
|
|
<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', () => {
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-08-15 16:43:41 +08:00
|
|
|
<Menu defaultOpenKeys={['1']} mode="inline" {...props}>
|
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>
|
2022-08-15 16:43:41 +08:00
|
|
|
</Menu>
|
2017-06-30 23:08:11 +08:00
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container, rerender } = render(<Demo />);
|
2017-07-07 19:45:59 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('li.ant-menu-submenu-inline')).toHaveClass(
|
|
|
|
'ant-menu-submenu-open',
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
// inlineCollapsed
|
2022-08-15 16:43:41 +08:00
|
|
|
rerender(<Demo inlineCollapsed />);
|
|
|
|
|
2020-11-11 19:05:01 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-root')).toHaveClass('ant-menu-vertical');
|
|
|
|
expect(container.querySelector('.ant-menu-submenu-popup')).toBeFalsy();
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
// !inlineCollapsed
|
2022-08-15 16:43:41 +08:00
|
|
|
rerender(<Demo inlineCollapsed={false} />);
|
|
|
|
|
2021-05-24 16:24:00 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-sub')).toHaveClass('ant-menu-inline');
|
|
|
|
expect(container.querySelector('li.ant-menu-submenu-inline')).toHaveClass(
|
|
|
|
'ant-menu-submenu-open',
|
|
|
|
);
|
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-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-04-06 11:07:15 +08:00
|
|
|
<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');
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent(container.querySelector('ul')!, transitionEndEvent);
|
2022-04-06 11:07:15 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('.ant-menu-submenu-title')!);
|
2022-04-06 11:07:15 +08:00
|
|
|
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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2020-03-13 19:43:10 +08:00
|
|
|
<Menu
|
|
|
|
defaultOpenKeys={['not-existed']}
|
|
|
|
mode="inline"
|
|
|
|
inlineCollapsed
|
2022-11-19 13:47:33 +08:00
|
|
|
getPopupContainer={(node) => node.parentNode as HTMLElement}
|
2020-03-13 19:43:10 +08:00
|
|
|
>
|
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>,
|
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[0]);
|
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[1]);
|
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[2]);
|
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[3]);
|
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[4]);
|
|
|
|
fireEvent.mouseEnter(container.querySelectorAll('li.ant-menu-item')[5]);
|
|
|
|
|
|
|
|
triggerAllTimer();
|
|
|
|
// when title is null or '' and false, tooltip will not render.
|
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner').length).toBe(3);
|
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner')[0].textContent).toBe('item');
|
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner')[1].textContent).toBe('title');
|
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner')[2].textContent).toBe('item');
|
2020-03-13 19:43:10 +08:00
|
|
|
});
|
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
describe('open submenu when click submenu title', () => {
|
2022-08-30 10:06:38 +08:00
|
|
|
const toggleMenu = (
|
|
|
|
instance: ReturnType<typeof render>,
|
|
|
|
index: number,
|
|
|
|
event: MouseEvent,
|
|
|
|
): void => {
|
2022-04-06 11:07:15 +08:00
|
|
|
fireEvent[event](instance.container.querySelectorAll('.ant-menu-submenu-title')[index]);
|
|
|
|
triggerAllTimer();
|
2017-11-11 00:07:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
it('inline', () => {
|
2022-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'inline' };
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps} {...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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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 = {
|
2022-07-19 22:53:38 +08:00
|
|
|
...initCollapseMotion(),
|
2021-05-24 16:24:00 +08:00
|
|
|
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-08-30 10:06:38 +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-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'vertical' };
|
2022-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps}>
|
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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'vertical', triggerSubMenuAction: 'click' };
|
2022-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps}>
|
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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
instance,
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
|
|
|
() => toggleMenu(instance, 0, 'click'),
|
2020-06-28 22:41:59 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('horizontal with hover(default)', () => {
|
2022-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'horizontal' };
|
2022-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps}>
|
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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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-09-30 17:44:24 +08:00
|
|
|
const defaultTestProps: MenuProps = { mode: 'horizontal', triggerSubMenuAction: 'click' };
|
2022-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => (
|
2022-09-30 17:44:24 +08:00
|
|
|
<Menu {...defaultTestProps}>
|
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-09-30 17:44:24 +08:00
|
|
|
defaultTestProps,
|
2022-04-06 11:07:15 +08:00
|
|
|
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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
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
|
|
|
);
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('.ant-menu-item')!);
|
2022-04-06 11:07:15 +08:00
|
|
|
triggerAllTimer();
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelector('.ant-tooltip-inner')?.textContent).toBe('bamboo lucky');
|
2018-11-20 23:26:40 +08:00
|
|
|
});
|
2019-03-14 21:04:13 +08:00
|
|
|
|
|
|
|
it('render correctly when using with Layout.Sider', () => {
|
2022-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => {
|
|
|
|
const [collapsed, setCollapsed] = useState<boolean>(false);
|
|
|
|
return (
|
|
|
|
<Layout style={{ minHeight: '100vh' }}>
|
|
|
|
<Layout.Sider
|
|
|
|
collapsible
|
|
|
|
collapsed={collapsed}
|
|
|
|
onCollapse={() => setCollapsed(!collapsed)}
|
|
|
|
>
|
|
|
|
<div className="logo" />
|
|
|
|
<Menu theme="dark" defaultSelectedKeys={['1']} mode="inline">
|
|
|
|
<SubMenu key="sub1" icon={<UserOutlined />} title="User">
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
};
|
2019-03-14 21:04:13 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(<Demo />);
|
|
|
|
|
|
|
|
expect(container.querySelector('ul.ant-menu-root')).toHaveClass('ant-menu-inline');
|
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-menu-submenu-title')!);
|
|
|
|
fireEvent.click(container.querySelector('.ant-layout-sider-trigger')!);
|
2022-04-06 11:07:15 +08:00
|
|
|
triggerAllTimer();
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-root')).toHaveClass('ant-menu-inline-collapsed');
|
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('ul.ant-menu-root')!);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('ul.ant-menu-root')).not.toHaveClass('ant-menu-inline');
|
|
|
|
expect(container.querySelector('ul.ant-menu-root')).toHaveClass('ant-menu-vertical');
|
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();
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2019-03-15 21:56:41 +08:00
|
|
|
<Menu onMouseEnter={onMouseEnter} defaultSelectedKeys={['test1']}>
|
|
|
|
<Menu.Item key="test1">Navigation One</Menu.Item>
|
|
|
|
<Menu.Item key="test2">Navigation Two</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('ul.ant-menu-root')!);
|
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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2019-03-28 09:24:16 +08:00
|
|
|
<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
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('li.ant-menu-item')!);
|
2021-05-24 16:24:00 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner').length).toBe(0);
|
2019-03-28 09:24:16 +08:00
|
|
|
});
|
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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2020-04-26 23:16:15 +08:00
|
|
|
<Menu>
|
|
|
|
<Menu.Item key="mail" icon={<MailOutlined />}>
|
|
|
|
Navigation One
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('.ant-menu-item .anticon')).toHaveClass('anticon-mail');
|
2020-04-26 23:16:15 +08:00
|
|
|
});
|
|
|
|
|
2019-04-05 16:15:01 +08:00
|
|
|
it('should controlled collapse work', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { asFragment, rerender } = render(
|
2019-04-05 16:15:01 +08:00
|
|
|
<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>,
|
|
|
|
);
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2019-04-05 16:15:01 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
rerender(
|
|
|
|
<Menu mode="inline" inlineCollapsed>
|
|
|
|
<Menu.Item key="1" icon={<PieChartOutlined />}>
|
|
|
|
Option 1
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>,
|
|
|
|
);
|
2019-04-05 16:15:01 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2019-04-05 16:15:01 +08:00
|
|
|
});
|
2019-04-08 22:20:18 +08:00
|
|
|
|
|
|
|
it('not title if not collapsed', () => {
|
|
|
|
jest.useFakeTimers();
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2019-04-08 22:20:18 +08:00
|
|
|
<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>,
|
|
|
|
);
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('.ant-menu-item')!);
|
2022-08-08 13:31:55 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2019-04-08 22:20:18 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelectorAll('.ant-tooltip-inner').length).toBeFalsy();
|
2019-04-08 22:20:18 +08:00
|
|
|
|
|
|
|
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-08-30 10:06:38 +08:00
|
|
|
const Demo: React.FC = () => {
|
2022-11-19 13:47:33 +08:00
|
|
|
const menuProps = useMemo<MenuProps>(() => ({ onOpen, onClose }) as MenuProps, []);
|
2022-08-30 10:06:38 +08:00
|
|
|
return (
|
|
|
|
<Menu
|
|
|
|
{...menuProps}
|
|
|
|
defaultOpenKeys={['1']}
|
|
|
|
mode="inline"
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
key: '1',
|
|
|
|
label: 'submenu1',
|
|
|
|
children: [
|
|
|
|
{ key: 'submenu1', label: 'Option 1' },
|
|
|
|
{ key: 'submenu2', label: 'Option 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ key: '2', label: 'menu2' },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
render(<Demo />);
|
2019-07-09 11:46:21 +08:00
|
|
|
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();
|
2022-06-23 11:25:21 +08:00
|
|
|
errorSpy.mockRestore();
|
2019-07-09 11:46:21 +08:00
|
|
|
});
|
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();
|
2022-11-19 13:47:33 +08:00
|
|
|
const Demo: React.FC<MenuProps> = (props) => {
|
|
|
|
const menuProps = useMemo<MenuProps>(() => ({ collapsedWidth: 0 }) as MenuProps, []);
|
2022-08-30 10:06:38 +08:00
|
|
|
return (
|
|
|
|
<Menu
|
|
|
|
mode="inline"
|
|
|
|
inlineCollapsed={false}
|
|
|
|
defaultSelectedKeys={['1']}
|
|
|
|
openKeys={['3']}
|
|
|
|
{...menuProps}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
<Menu.Item key="1">Option 1</Menu.Item>
|
|
|
|
<Menu.Item key="2">Option 2</Menu.Item>
|
|
|
|
<Menu.SubMenu key="3" title="Option 3">
|
|
|
|
<Menu.Item key="4">Option 4</Menu.Item>
|
|
|
|
</Menu.SubMenu>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
};
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container, rerender } = render(<Demo />);
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelector('li.ant-menu-item-selected')?.textContent).toBe('Option 1');
|
2022-08-15 16:43:41 +08:00
|
|
|
fireEvent.click(container.querySelectorAll('li.ant-menu-item')[1]);
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelector('li.ant-menu-item-selected')?.textContent).toBe('Option 2');
|
2022-08-15 16:43:41 +08:00
|
|
|
|
|
|
|
rerender(<Demo inlineCollapsed />);
|
2021-05-24 16:24:00 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelector('li.ant-menu-item-selected')?.textContent).toBe('O');
|
2021-05-24 16:24:00 +08:00
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
rerender(<Demo inlineCollapsed={false} />);
|
|
|
|
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelector('li.ant-menu-item-selected')?.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', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { asFragment } = render(
|
2020-04-26 23:16:15 +08:00
|
|
|
<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>,
|
|
|
|
);
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2020-04-26 23:16:15 +08:00
|
|
|
});
|
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>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(<App />);
|
2022-08-30 10:06:38 +08:00
|
|
|
fireEvent.click(container.querySelector('button')!);
|
2020-05-03 00:10:21 +08:00
|
|
|
expect(onOpenChange).toHaveBeenCalledWith([]);
|
|
|
|
});
|
2021-05-24 16:24:00 +08:00
|
|
|
|
|
|
|
it('Use first char as Icon when collapsed', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2021-05-24 16:24:00 +08:00
|
|
|
<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>,
|
|
|
|
);
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelectorAll('.ant-menu-inline-collapsed-noicon')[0]?.textContent).toEqual(
|
2022-08-15 16:43:41 +08:00
|
|
|
'L',
|
|
|
|
);
|
2022-08-30 10:06:38 +08:00
|
|
|
expect(container.querySelectorAll('.ant-menu-inline-collapsed-noicon')[1]?.textContent).toEqual(
|
2022-08-15 16:43:41 +08:00
|
|
|
'B',
|
|
|
|
);
|
2021-05-24 16:24:00 +08:00
|
|
|
});
|
2021-07-19 15:42:07 +08:00
|
|
|
|
|
|
|
it('divider should show', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2021-07-19 15:42:07 +08:00
|
|
|
<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>,
|
|
|
|
);
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelectorAll('li.ant-menu-item-divider').length).toBe(2);
|
|
|
|
expect(container.querySelectorAll('li.ant-menu-item-divider-dashed').length).toBe(1);
|
2021-07-19 15:42:07 +08:00
|
|
|
});
|
2022-03-28 14:43:10 +08:00
|
|
|
|
|
|
|
it('should support ref', async () => {
|
2022-08-30 13:05:50 +08:00
|
|
|
const ref = React.createRef<MenuRef>();
|
2022-04-26 18:17:55 +08:00
|
|
|
const { container } = render(
|
2022-03-28 14:43:10 +08:00
|
|
|
<Menu ref={ref}>
|
2022-05-07 11:36:34 +08:00
|
|
|
<Menu.Item key="1">Option 1</Menu.Item>
|
2022-03-28 14:43:10 +08:00
|
|
|
</Menu>,
|
|
|
|
);
|
2022-04-26 18:17:55 +08:00
|
|
|
expect(ref.current?.menu?.list).toBe(container.querySelector('ul'));
|
|
|
|
ref.current?.focus();
|
2022-05-07 11:36:34 +08:00
|
|
|
expect(document.activeElement).toBe(container.querySelector('li'));
|
2022-03-28 14:43:10 +08:00
|
|
|
});
|
2022-04-11 17:41:54 +08:00
|
|
|
|
2022-04-11 15:32:00 +08:00
|
|
|
it('expandIcon', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { container } = render(
|
2022-04-11 15:32:00 +08:00
|
|
|
<Menu defaultOpenKeys={['1']} mode="inline" expandIcon={() => <span className="bamboo" />}>
|
|
|
|
<SubMenu key="1" title="submenu1">
|
|
|
|
<Menu.Item key="submenu1">Option 1</Menu.Item>
|
|
|
|
</SubMenu>
|
|
|
|
</Menu>,
|
|
|
|
);
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(container.querySelector('.bamboo')).toBeTruthy();
|
2022-04-11 15:32:00 +08:00
|
|
|
});
|
2022-06-08 10:25:49 +08:00
|
|
|
|
|
|
|
it('all types must be available in the "items" syntax', () => {
|
2022-08-15 16:43:41 +08:00
|
|
|
const { asFragment } = render(
|
2022-06-08 10:25:49 +08:00
|
|
|
<Menu
|
|
|
|
mode="inline"
|
|
|
|
defaultOpenKeys={['submenu', 'group-submenu']}
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
key: 'submenu',
|
|
|
|
label: 'Submenu',
|
|
|
|
children: [
|
|
|
|
{ key: 'submenu-item1', label: 'SubmenuItem 1' },
|
|
|
|
{ key: 'submenu-item2', label: 'SubmenuItem 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ key: 'divider', type: 'divider' },
|
|
|
|
{
|
|
|
|
key: 'group',
|
|
|
|
type: 'group',
|
|
|
|
label: 'Group',
|
|
|
|
children: [
|
2022-08-30 10:06:38 +08:00
|
|
|
{ key: 'group-item', label: 'GroupItem' },
|
2022-06-08 10:25:49 +08:00
|
|
|
{ key: 'group-divider', type: 'divider' },
|
|
|
|
{
|
|
|
|
key: 'group-submenu',
|
|
|
|
label: 'GroupSubmenu',
|
|
|
|
children: [
|
|
|
|
{ key: 'group-submenu-item1', label: 'GroupSubmenuItem 1' },
|
|
|
|
{ key: 'group-submenu-item2', label: 'GroupSubmenuItem 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-08-15 16:43:41 +08:00
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2022-06-08 10:25:49 +08:00
|
|
|
});
|
2022-06-23 11:25:21 +08:00
|
|
|
|
|
|
|
it('should not warning deprecated message when items={undefined}', () => {
|
2022-11-28 14:19:25 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-08-15 16:43:41 +08:00
|
|
|
render(<Menu items={undefined} />);
|
2022-06-23 11:25:21 +08:00
|
|
|
expect(errorSpy).not.toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining('`children` will be removed in next major version'),
|
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2023-01-07 21:50:09 +08:00
|
|
|
|
|
|
|
it('expandIconClassName', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<Menu
|
|
|
|
expandIcon={<span className="custom-expand-icon" />}
|
|
|
|
inlineCollapsed
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
label: 'Option 1',
|
|
|
|
key: '1',
|
|
|
|
icon: '112',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Option 1-1',
|
|
|
|
key: '1-1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(container.querySelector('.custom-expand-icon')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/40041
|
|
|
|
it('should not show icon when inlineCollapsed', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<Menu
|
|
|
|
expandIcon={<span className="bamboo">I</span>}
|
|
|
|
inlineCollapsed
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
label: 'Option 1',
|
|
|
|
key: '1',
|
|
|
|
icon: '112',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Option 1-1',
|
|
|
|
key: '1-1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container.querySelector('.bamboo')).toBeTruthy();
|
|
|
|
expect(getComputedStyle(container.querySelector('.bamboo') as HTMLElement)).toHaveProperty(
|
|
|
|
'opacity',
|
|
|
|
'0',
|
|
|
|
);
|
|
|
|
});
|
2017-01-16 21:13:59 +08:00
|
|
|
});
|