2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Badge from '../index';
|
2018-05-18 02:10:17 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
import { asyncExpect } from '@/tests/utils';
|
2018-05-18 02:10:17 +00:00
|
|
|
describe('Badge', () => {
|
2018-09-05 13:28:54 +00:00
|
|
|
it('badge dot not scaling count > 9', () => {
|
2018-05-18 02:10:17 +00:00
|
|
|
const badge = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Badge count={10} dot />;
|
2018-05-18 02:10:17 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(badge.findAll('.ant-card-multiple-words').length).toBe(0);
|
|
|
|
});
|
2019-03-12 04:04:40 +00:00
|
|
|
it('badge should support float number', () => {
|
2020-07-24 10:46:45 +00:00
|
|
|
let wrapper = mount({
|
2019-03-12 04:04:40 +00:00
|
|
|
render() {
|
|
|
|
return <Badge count={3.5} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.text()).toMatchSnapshot();
|
|
|
|
wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <Badge count={3.5} />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
it('badge dot not showing count == 0', () => {
|
2018-05-18 02:10:17 +00:00
|
|
|
const badge = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Badge count={0} dot />;
|
2018-05-18 02:10:17 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(badge.findAll('.ant-badge-dot').length).toBe(0);
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('should have an overriden title attribute', () => {
|
|
|
|
const badge = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Badge count={10} title="Custom title" />;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(badge.find('.ant-scroll-number').element.attributes.getNamedItem('title').value).toEqual(
|
|
|
|
'Custom title',
|
|
|
|
);
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/10626
|
|
|
|
// it('should be composable with Tooltip', async () => {
|
|
|
|
// const wrapper = mount({
|
|
|
|
// render () {
|
|
|
|
// return <Tooltip ref='tooltip' title='Fix the error'>
|
|
|
|
// <Badge status='error' />
|
|
|
|
// </Tooltip>
|
|
|
|
// },
|
|
|
|
// }, { sync: false })
|
|
|
|
// await asyncExpect(() => {
|
|
|
|
// wrapper.find({ name: 'ABadge' }).trigger('mouseenter')
|
|
|
|
// }, 0)
|
|
|
|
|
|
|
|
// expect(wrapper.vm.$refs.tooltip.sVisible).toBe(true)
|
|
|
|
// })
|
|
|
|
|
|
|
|
it('should render when count is changed', async () => {
|
|
|
|
const wrapper = mount(Badge, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-09-05 13:28:54 +00:00
|
|
|
count: 9,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
wrapper.setProps({ count: 10 });
|
|
|
|
}, 100);
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 11 });
|
|
|
|
}, 100);
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 11 });
|
|
|
|
}, 100);
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 10 });
|
|
|
|
}, 100);
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ count: 9 });
|
|
|
|
}, 100);
|
2018-09-05 13:28:54 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
}, 100);
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('should be compatible with borderColor style', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Badge
|
|
|
|
count={4}
|
|
|
|
style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }}
|
|
|
|
/>
|
|
|
|
);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-01-03 12:46:53 +00:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13694
|
2020-03-07 11:45:13 +00:00
|
|
|
it('should support offset when count is a VueNode', () => {
|
2019-01-03 12:46:53 +00:00
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2019-01-03 12:46:53 +00:00
|
|
|
return (
|
2019-01-12 03:33:27 +00:00
|
|
|
<Badge count={<span class="custom" style={{ color: '#f5222d' }} />} offset={[10, 20]}>
|
2020-03-07 11:45:13 +00:00
|
|
|
<a href="#" class="head-example">
|
|
|
|
head
|
|
|
|
</a>
|
2019-01-03 12:46:53 +00:00
|
|
|
</Badge>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2019-01-03 12:46:53 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2020-03-07 11:45:13 +00:00
|
|
|
// https://github.com/ant-design/ant-design/issues/15799
|
|
|
|
it('render correct with negative number', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Badge count="-10" />
|
|
|
|
<Badge count={-10} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|