statistic.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { nextTick, ref } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, it } from 'vitest'
  4. import Statistic from '../src/statistic.vue'
  5. const TITLE_CLASS = '.el-statistic__head'
  6. const CONTENT_CLASS = '.el-statistic__content'
  7. const PERFIX_CLASS = '.el-statistic__prefix'
  8. const SUFFIX_CLASS = '.el-statistic__suffix'
  9. describe('Statistic.vue', () => {
  10. it('render test', () => {
  11. const wrapper = mount(() => <Statistic title="test" value={57454157} />)
  12. expect(wrapper.find(TITLE_CLASS).text()).toBe('test')
  13. expect(wrapper.find(CONTENT_CLASS).text()).toBe('57,454,157')
  14. })
  15. it('basics test', () => {
  16. const wrapper = mount(() => <Statistic value={268500.123456} />)
  17. expect(wrapper.find(CONTENT_CLASS).text()).toBe('268,500')
  18. })
  19. it('precision', async () => {
  20. const precision = ref(6)
  21. const wrapper = mount(() => (
  22. <Statistic precision={precision.value} value={268500.123456} />
  23. ))
  24. expect(wrapper.find(CONTENT_CLASS).text()).toBe('268,500.123456')
  25. precision.value = 4
  26. await nextTick()
  27. expect(wrapper.find(CONTENT_CLASS).text()).toBe('268,500.1234')
  28. })
  29. it('prefix & suffix', () => {
  30. const slots = {
  31. prefix: () => 'prefix',
  32. suffix: () => 'suffix',
  33. }
  34. const wrapper = mount(() => <Statistic v-slots={slots} value={57454157} />)
  35. expect(wrapper.find(PERFIX_CLASS).text()).toBe('prefix')
  36. expect(wrapper.find(SUFFIX_CLASS).text()).toBe('suffix')
  37. expect(wrapper.find(CONTENT_CLASS).text()).toBe('prefix57,454,157suffix')
  38. })
  39. })