diff --git a/components/layout/__tests__/index.test.js b/components/layout/__tests__/index.test.js index 4157e94f32..878f717436 100644 --- a/components/layout/__tests__/index.test.js +++ b/components/layout/__tests__/index.test.js @@ -1,6 +1,8 @@ import React from 'react'; import { mount, render } from 'enzyme'; import Layout from '..'; +import Icon from '../../icon'; +import Menu from '../../menu'; const { Sider, Content } = Layout; @@ -104,6 +106,36 @@ describe('Layout', () => { ); expect(wrapper.find('.ant-layout').hasClass('ant-layout-has-sider')).toBe(false); }); + + it('render correct with Tooltip', () => { + jest.useFakeTimers(); + const wrapper = mount( + + + + + Light + + + , + ); + + wrapper.find('.ant-menu-item').simulate('mouseenter'); + jest.runAllTimers(); + wrapper.update(); + expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy(); + wrapper.find('.ant-menu-item').simulate('mouseout'); + jest.runAllTimers(); + wrapper.update(); + + wrapper.setProps({ collapsed: true }); + wrapper.find('.ant-menu-item').simulate('mouseenter'); + jest.runAllTimers(); + wrapper.update(); + expect(wrapper.find('.ant-tooltip-inner').length).toBeTruthy(); + + jest.useRealTimers(); + }); }); describe('Sider onBreakpoint', () => { diff --git a/components/menu/MenuItem.tsx b/components/menu/MenuItem.tsx index f9358d5e74..f09cef532c 100644 --- a/components/menu/MenuItem.tsx +++ b/components/menu/MenuItem.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { Item } from 'rc-menu'; import { ClickParam } from '.'; +import { MenuContext, MenuContextProps } from './'; import Tooltip from '../tooltip'; import { SiderContext, SiderContextProps } from '../layout/Sider'; @@ -33,19 +34,25 @@ export default class MenuItem extends React.Component { const { level, children, rootPrefixCls } = this.props; const { title, ...rest } = this.props; - let titleNode = title || (level === 1 ? children : ''); - if (!siderCollapsed) { - titleNode = null; - } - return ( - - - + + {({ inlineCollapsed }: MenuContextProps) => { + let titleNode = title || (level === 1 ? children : ''); + if (!siderCollapsed && !inlineCollapsed) { + titleNode = null; + } + + return ( + + + + ); + }} + ); }; diff --git a/components/menu/__tests__/index.test.js b/components/menu/__tests__/index.test.js index f8c0698c01..33eaa8b6c9 100644 --- a/components/menu/__tests__/index.test.js +++ b/components/menu/__tests__/index.test.js @@ -494,6 +494,8 @@ describe('Menu', () => { const text = wrapper.find('.ant-tooltip-inner').text(); expect(text).toBe('bamboo lucky'); + + jest.useRealTimers(); }); it('render correctly when using with Layout.Sider', () => { @@ -608,4 +610,24 @@ describe('Menu', () => { expect(wrapper.render()).toMatchSnapshot(); }); + + it('not title if not collapsed', () => { + jest.useFakeTimers(); + const wrapper = mount( + + + + Option 1 + + , + ); + + wrapper.find('.ant-menu-item').simulate('mouseenter'); + jest.runAllTimers(); + wrapper.update(); + + expect(wrapper.find('.ant-tooltip-inner').length).toBeFalsy(); + + jest.useRealTimers(); + }); });