Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions packages/vue/src/badge/__tests__/badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ describe('PC Mode', () => {
value={5}
v-slots={{
content: () => <div class="badge__content">自定义</div>
}}
>
}}>
自定义内容插槽
</Badge>
))
Expand All @@ -56,11 +55,15 @@ describe('PC Mode', () => {
test('href', () => {
const num = 1
const text = '跳转链接'
const wrapper = mount(() => <Badge value={num} href={"/"}>{text}</Badge>)
const wrapper = mount(() => (
<Badge value={num} href={'/'}>
{text}
</Badge>
))

expect(wrapper.find('.tiny-badge a').exists()).toBe(true)
})


test('default slot', () => {
const wrapper = mount(() => {
return (
Expand All @@ -69,7 +72,7 @@ describe('PC Mode', () => {
v-slots={{
default: () => <div class="badge__default__slot">插槽内容</div>
}}
></Badge>
/>
)
})
expect(wrapper.find('.badge__default__slot').exists()).toBe(true)
Expand All @@ -84,20 +87,27 @@ describe('PC Mode', () => {
},
slots: {
default: () => <div class="badge__default__slot">我的待办</div>
},
}
})

expect(wrapper.find('.tiny-badge').exists()).toBe(true)
expect(wrapper.find('.tiny-badge__content-text').text()).toEqual('2')
expect(wrapper.find('.badge__default__slot').text()).toEqual('我的待办')

await wrapper.setProps({ value: 1 })
await wrapper.setProps({ hidden: 1 === 0 })
await wrapper.setProps({ hidden: false })
expect(wrapper.find('.tiny-badge').exists()).toBe(true)
expect(wrapper.find('.tiny-badge__content-text').text()).toEqual('1')

await wrapper.setProps({ value: 0 })
await wrapper.setProps({ hidden: 0 === 0 })

await wrapper.setProps({ hidden: true })
expect(wrapper.find('.tiny-badge').exists()).toBe(false)
})

test('is-dot with value', () => {
const wrapper = mount(() => <Badge value={2} is-dot />)
expect(wrapper.find('.tiny-badge').exists()).toBe(true)
expect(wrapper.find('.tiny-badge__content-text').text()).toBe('')
})
})
6 changes: 5 additions & 1 deletion packages/vue/src/badge/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
>
<slot name="content">
<a v-if="state.href" :href="state.href" :target="target" rel="noopener noreferrer">{{ state.content }}</a>
<span class="tiny-badge__content-text" v-if="!state.href">{{ state.content }}</span>
<span class="tiny-badge__content-text" v-if="!state.href">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the isDot condition is correctly applied to prevent content text from displaying when isDot is true. This change addresses the issue with the dot badge style.

<template v-if="!isDot">
{{ state.content }}
</template>
</span>
</slot>
</div>
</div>
Expand Down
Loading