result.test.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { nextTick, ref } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, test } from 'vitest'
  4. import Result from '../src/result.vue'
  5. import type { ResultProps } from '../src/result'
  6. const AXIOM = 'Rem is the best girl'
  7. describe('Result.vue', () => {
  8. test('render test', () => {
  9. const wrapper = mount(() => <Result />)
  10. expect(wrapper.find('.el-result__icon').exists()).toBe(true)
  11. expect(wrapper.classes()).toContain('el-result')
  12. })
  13. test('should render title props', () => {
  14. const wrapper = mount(() => <Result title={AXIOM} />)
  15. expect(wrapper.find('.el-result__title').text()).toBe(AXIOM)
  16. })
  17. test('should render sub-title props', () => {
  18. const wrapper = mount(() => <Result subTitle={AXIOM} />)
  19. expect(wrapper.find('.el-result__subtitle').text()).toBe(AXIOM)
  20. })
  21. test('should render icon props', async () => {
  22. const icon = ref<ResultProps['icon']>('success')
  23. const wrapper = mount(() => <Result icon={icon.value} />)
  24. expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
  25. expect(wrapper.find('.el-result__icon svg').classes()).toContain(
  26. 'icon-success'
  27. )
  28. icon.value = 'error'
  29. await nextTick()
  30. expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
  31. expect(wrapper.find('.el-result__icon svg').classes()).toContain(
  32. 'icon-error'
  33. )
  34. icon.value = 'warning'
  35. await nextTick()
  36. expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
  37. expect(wrapper.find('.el-result__icon svg').classes()).toContain(
  38. 'icon-warning'
  39. )
  40. icon.value = 'info'
  41. await nextTick()
  42. expect(wrapper.find('.el-result__icon svg').exists()).toBe(true)
  43. expect(wrapper.find('.el-result__icon svg').classes()).toContain(
  44. 'icon-info'
  45. )
  46. })
  47. test('should render icon slots', () => {
  48. const wrapper = mount(() => (
  49. <Result
  50. v-slots={{
  51. icon: () => AXIOM,
  52. }}
  53. />
  54. ))
  55. expect(wrapper.find('.el-result__icon').exists()).toBe(true)
  56. expect(wrapper.find('.el-result__icon').text()).toBe(AXIOM)
  57. })
  58. test('should render title slots', () => {
  59. const wrapper = mount(() => (
  60. <Result
  61. v-slots={{
  62. title: () => AXIOM,
  63. }}
  64. />
  65. ))
  66. expect(wrapper.find('.el-result__title').exists()).toBe(true)
  67. expect(wrapper.find('.el-result__title').text()).toBe(AXIOM)
  68. })
  69. test('should render sub-title slots', () => {
  70. const wrapper = mount(() => (
  71. <Result
  72. v-slots={{
  73. 'sub-title': () => AXIOM,
  74. }}
  75. />
  76. ))
  77. expect(wrapper.find('.el-result__subtitle').exists()).toBe(true)
  78. expect(wrapper.find('.el-result__subtitle').text()).toBe(AXIOM)
  79. })
  80. test('should render extra slots', () => {
  81. const wrapper = mount(() => (
  82. <Result
  83. v-slots={{
  84. extra: () => AXIOM,
  85. }}
  86. />
  87. ))
  88. expect(wrapper.find('.el-result__extra').exists()).toBe(true)
  89. expect(wrapper.find('.el-result__extra').text()).toBe(AXIOM)
  90. })
  91. })