2018-02-24 11:40:44 +08:00
|
|
|
import React from 'react';
|
2018-06-02 13:18:11 +08:00
|
|
|
import { mount, render } from 'enzyme';
|
2018-02-24 11:40:44 +08:00
|
|
|
import Badge from '../index';
|
2018-05-23 13:11:49 +08:00
|
|
|
import Tooltip from '../../tooltip';
|
2018-02-24 11:40:44 +08:00
|
|
|
|
|
|
|
describe('Badge', () => {
|
2018-05-23 13:11:49 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2018-05-25 16:04:38 +08:00
|
|
|
it('badge dot not scaling count > 9', () => {
|
2018-02-24 11:40:44 +08:00
|
|
|
const badge = mount(<Badge count={10} dot />);
|
|
|
|
expect(badge.find('.ant-card-multiple-words').length).toBe(0);
|
|
|
|
});
|
2018-04-10 01:09:18 +08:00
|
|
|
|
2019-01-09 22:32:06 +08:00
|
|
|
it('badge should support float number', () => {
|
|
|
|
let wrapper = render(<Badge count={3.5} />);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper = mount(<Badge count="3.5" />);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-05-25 16:04:38 +08:00
|
|
|
it('badge dot not showing count == 0', () => {
|
2018-02-24 11:40:44 +08:00
|
|
|
const badge = mount(<Badge count={0} dot />);
|
|
|
|
expect(badge.find('.ant-badge-dot').length).toBe(0);
|
|
|
|
});
|
2018-04-10 01:09:18 +08:00
|
|
|
|
|
|
|
it('should have an overriden title attribute', () => {
|
|
|
|
const badge = mount(<Badge count={10} title="Custom title" />);
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
|
|
|
badge
|
|
|
|
.find('.ant-scroll-number')
|
|
|
|
.getDOMNode()
|
|
|
|
.attributes.getNamedItem('title').value,
|
|
|
|
).toEqual('Custom title');
|
2018-04-10 01:09:18 +08:00
|
|
|
});
|
2018-05-23 13:11:49 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/10626
|
|
|
|
it('should be composable with Tooltip', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Tooltip title="Fix the error">
|
|
|
|
<Badge status="error" />
|
2018-12-07 16:17:45 +08:00
|
|
|
</Tooltip>,
|
2018-05-23 13:11:49 +08:00
|
|
|
);
|
|
|
|
wrapper.find('Badge').simulate('mouseenter');
|
|
|
|
jest.runAllTimers();
|
|
|
|
expect(wrapper.instance().tooltip.props.visible).toBe(true);
|
|
|
|
});
|
2018-05-25 17:00:32 +08:00
|
|
|
|
|
|
|
it('should render when count is changed', () => {
|
|
|
|
const wrapper = mount(<Badge count={9} />);
|
|
|
|
wrapper.setProps({ count: 10 });
|
|
|
|
jest.runAllTimers();
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 11 });
|
|
|
|
jest.runAllTimers();
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 11 });
|
|
|
|
jest.runAllTimers();
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 10 });
|
|
|
|
jest.runAllTimers();
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.setProps({ count: 9 });
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be compatible with borderColor style', () => {
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = render(
|
|
|
|
<Badge
|
|
|
|
count={4}
|
|
|
|
style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }}
|
|
|
|
/>,
|
|
|
|
);
|
2018-06-02 13:18:11 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2018-05-25 17:00:32 +08:00
|
|
|
});
|
2018-12-18 18:31:12 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13694
|
|
|
|
it('should support offset when count is a ReactNode', () => {
|
|
|
|
const wrapper = render(
|
|
|
|
<Badge count={<span className="custom" style={{ color: '#f5222d' }} />} offset={[10, 20]}>
|
|
|
|
<a href="#" className="head-example" />
|
|
|
|
</Badge>,
|
|
|
|
);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-03-14 15:53:51 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/15349
|
|
|
|
it('should color style works on Badge', () => {
|
|
|
|
const wrapper = mount(<Badge style={{ color: 'red' }} status="success" text="Success" />);
|
|
|
|
expect(wrapper.find('.ant-badge-status-text').props().style.color).toBe('red');
|
|
|
|
});
|
2019-04-02 19:01:12 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/15799
|
|
|
|
it('render correct with negative number', () => {
|
|
|
|
const wrapper = render(
|
|
|
|
<div>
|
|
|
|
<Badge count="-10" />
|
|
|
|
<Badge count={-10} />
|
|
|
|
</div>,
|
|
|
|
);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-02-24 11:40:44 +08:00
|
|
|
});
|