badge.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { nextTick, ref } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, test } from 'vitest'
  4. import Badge from '../src/badge.vue'
  5. const AXIOM = 'Rem is the best girl'
  6. describe('Badge', () => {
  7. test('has value', () => {
  8. const wrapper = mount(() => <Badge value={80} />)
  9. expect(wrapper.find('.el-badge__content').text()).toEqual('80')
  10. })
  11. test('is fixed', () => {
  12. const wrapper = mount(() => (
  13. <Badge
  14. v-slots={{
  15. default: () => AXIOM,
  16. }}
  17. />
  18. ))
  19. expect(wrapper.find('.el-badge__content.is-fixed').exists()).toBe(true)
  20. expect(wrapper.find('.el-badge').text()).toBe(AXIOM)
  21. })
  22. test('is dot', () => {
  23. const wrapper = mount(() => (
  24. <Badge
  25. isDot={true}
  26. v-slots={{
  27. default: () => AXIOM,
  28. }}
  29. />
  30. ))
  31. expect(wrapper.find('.el-badge__content.is-dot').exists()).toBe(true)
  32. expect(
  33. wrapper.find('.el-badge__content.el-badge__content--danger').exists()
  34. ).toBe(true)
  35. })
  36. test('is dot with type', () => {
  37. const wrapper = mount(() => (
  38. <Badge
  39. isDot={true}
  40. type={'success'}
  41. v-slots={{
  42. default: () => AXIOM,
  43. }}
  44. />
  45. ))
  46. expect(wrapper.find('.el-badge__content.is-dot').exists()).toBe(true)
  47. expect(
  48. wrapper.find('.el-badge__content.el-badge__content--success').exists()
  49. ).toBe(true)
  50. })
  51. test('max', async () => {
  52. const badgeValue = ref(200)
  53. const wrapper = mount(() => <Badge max={100} value={badgeValue.value} />)
  54. expect(wrapper.find('.el-badge__content').text()).toEqual('100+')
  55. badgeValue.value = 80
  56. await nextTick()
  57. expect(wrapper.find('.el-badge__content').text()).toEqual('80')
  58. })
  59. })