Browse Source

Add test case

pull/6686/head
afc163 8 years ago
parent
commit
50e37796b8
  1. 28
      components/menu/__tests__/index.test.js
  2. 2
      components/menu/index.tsx

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

@ -1,6 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
import Menu from '..';
import Icon from '../../Icon';
const SubMenu = Menu.SubMenu;
@ -127,4 +128,31 @@ describe('Menu', () => {
wrapper.setProps({ mode: 'inline' });
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
});
it('should always follow openKeys when mode is switched', () => {
const wrapper = mount(
<Menu defaultOpenKeys={['1']} mode="inline">
<Menu.Item key="menu1">
<Icon type="inbox" />
<span>Option</span>
</Menu.Item>
<SubMenu key="1" title="submenu1">
<Menu.Item key="submenu1">
Option
</Menu.Item>
<Menu.Item key="submenu2">
Option
</Menu.Item>
</SubMenu>
</Menu>
);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-inline')).toBe(true);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(false);
wrapper.setProps({ inlineCollapsed: true });
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-vertical')).toBe(true);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(true);
wrapper.setProps({ inlineCollapsed: false });
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-inline')).toBe(true);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).toBe(false);
});
});

2
components/menu/index.tsx

@ -140,7 +140,7 @@ export default class Menu extends React.Component<MenuProps, any> {
}
getInlineCollapsed() {
const { inlineCollapsed } = this.props;
if ('siderCollapsed' in this.context) {
if (this.context.siderCollapsed !== undefined) {
return this.context.siderCollapsed;
}
return inlineCollapsed;

Loading…
Cancel
Save