Skip to content

Commit 480d550

Browse files
committed
test(badge): improve test coverage
1 parent 4e2707b commit 480d550

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

packages/varlet-ui/src/badge/__tests__/index.spec.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ describe('test badge component props', () => {
7878
wrapper.unmount()
7979
})
8080

81+
test('badge maxValue with string values', () => {
82+
const wrapper = mount(VarBadge, {
83+
props: {
84+
maxValue: '9',
85+
value: '10',
86+
},
87+
})
88+
89+
expect(wrapper.find('.var-badge__content').html()).toContain('<span>9+</span>')
90+
wrapper.unmount()
91+
})
92+
93+
test('badge maxValue not provided', () => {
94+
const wrapper = mount(VarBadge, {
95+
props: {
96+
value: 8,
97+
},
98+
})
99+
100+
expect(wrapper.find('.var-badge__content').html()).toContain('<span>8</span>')
101+
wrapper.unmount()
102+
})
103+
104+
test('badge value not provided', () => {
105+
const wrapper = mount(VarBadge, {
106+
props: {
107+
maxValue: 9,
108+
},
109+
})
110+
111+
expect(wrapper.find('.var-badge__content span').exists()).toBe(true)
112+
expect(wrapper.find('.var-badge__content span').text()).toBe('0')
113+
wrapper.unmount()
114+
})
115+
81116
test('badge position', () => {
82117
;['right-top', 'right-bottom', 'left-top', 'left-bottom'].forEach((position) => {
83118
const wrapper = mount(VarBadge, {
@@ -152,8 +187,31 @@ describe('test badge component props', () => {
152187
})
153188

154189
expect(wrapper.find('.var-icon').classes()).toContain('var-icon-notebook')
190+
expect(wrapper.find('.var-badge__icon').exists()).toBe(true)
155191
wrapper.unmount()
156192
})
193+
194+
test('badge computed value respects maxValue', () => {
195+
const wrapper = mount(VarBadge, {
196+
props: {
197+
maxValue: 9,
198+
value: 10,
199+
},
200+
})
201+
202+
expect(wrapper.vm.value).toBe('9+')
203+
wrapper.unmount()
204+
205+
const wrapperEqual = mount(VarBadge, {
206+
props: {
207+
maxValue: 9,
208+
value: 9,
209+
},
210+
})
211+
212+
expect(wrapperEqual.vm.value).toBe(9)
213+
wrapperEqual.unmount()
214+
})
157215
})
158216

159217
describe('test badge component slots', () => {

0 commit comments

Comments
 (0)