Message.spec.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { describe, it, expect } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import Message from '../Base/Message.vue'
  4. import { nextTick } from 'vue'
  5. // Мокаем иконки
  6. const ICheckAlt = { template: '<div class="check-icon"></div>' }
  7. const IAlert = { template: '<div class="alert-icon"></div>' }
  8. const IClose = { template: '<div class="close-icon"></div>' }
  9. describe('Message', () => {
  10. it('отображает сообщение типа done по умолчанию', async () => {
  11. const wrapper = mount(Message, {
  12. global: {
  13. components: {
  14. ICheckAlt,
  15. IAlert,
  16. IClose
  17. }
  18. }
  19. })
  20. await nextTick()
  21. expect(wrapper.find('.check-icon').exists()).toBe(true)
  22. expect(wrapper.element.className).toContain('text-green-500')
  23. })
  24. it('отображает сообщение типа warn', async () => {
  25. const wrapper = mount(Message, {
  26. props: {
  27. type: 'warn'
  28. },
  29. global: {
  30. components: {
  31. ICheckAlt,
  32. IAlert,
  33. IClose
  34. }
  35. }
  36. })
  37. await nextTick()
  38. expect(wrapper.find('.alert-icon').exists()).toBe(true)
  39. expect(wrapper.element.className).toContain('text-yellow-500')
  40. })
  41. it('отображает сообщение типа danger', async () => {
  42. const wrapper = mount(Message, {
  43. props: {
  44. type: 'danger'
  45. },
  46. global: {
  47. components: {
  48. ICheckAlt,
  49. IAlert,
  50. IClose
  51. }
  52. }
  53. })
  54. await nextTick()
  55. expect(wrapper.find('.close-icon').exists()).toBe(true)
  56. expect(wrapper.element.className).toContain('text-red-500')
  57. })
  58. it('скрывает иконку, если icon=false', async () => {
  59. const wrapper = mount(Message, {
  60. props: {
  61. icon: false
  62. },
  63. global: {
  64. components: {
  65. ICheckAlt,
  66. IAlert,
  67. IClose
  68. }
  69. }
  70. })
  71. expect(wrapper.find('.check-icon').exists()).toBe(false)
  72. })
  73. it('отображает текст сообщения', async () => {
  74. const wrapper = mount(Message, {
  75. props: {
  76. text: 'Test message'
  77. },
  78. global: {
  79. components: {
  80. ICheckAlt,
  81. IAlert,
  82. IClose
  83. }
  84. }
  85. })
  86. expect(wrapper.text()).toContain('Test message')
  87. })
  88. it('отображает слот', async () => {
  89. const wrapper = mount(Message, {
  90. slots: {
  91. default: '<div class="custom-slot">Custom content</div>'
  92. },
  93. global: {
  94. components: {
  95. ICheckAlt,
  96. IAlert,
  97. IClose
  98. }
  99. }
  100. })
  101. expect(wrapper.find('.custom-slot').exists()).toBe(true)
  102. expect(wrapper.text()).toContain('Custom content')
  103. })
  104. })