SideBarElement.spec.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { describe, it, expect } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import SideBarElement from '../Base/SideBar/element.vue'
  4. describe('SideBarElement', () => {
  5. it('отображает иконку типа home', () => {
  6. const wrapper = mount(SideBarElement, {
  7. props: {
  8. type: 'home',
  9. text: 'Домой',
  10. color: '#FF4646'
  11. }
  12. })
  13. expect(wrapper.find('svg').exists()).toBe(true)
  14. expect(wrapper.find('path').attributes('stroke')).toBe('#FF4646')
  15. })
  16. it('отображает иконку типа license', () => {
  17. const wrapper = mount(SideBarElement, {
  18. props: {
  19. type: 'license',
  20. text: 'Лицензия',
  21. color: '#EDE8D8'
  22. }
  23. })
  24. expect(wrapper.find('svg').exists()).toBe(true)
  25. expect(wrapper.find('path').attributes('stroke')).toBe('#EDE8D8')
  26. })
  27. it('отображает иконку типа calendar', () => {
  28. const wrapper = mount(SideBarElement, {
  29. props: {
  30. type: 'calendar',
  31. text: 'Календарь',
  32. color: '#FF4646'
  33. }
  34. })
  35. expect(wrapper.find('svg').exists()).toBe(true)
  36. expect(wrapper.find('path').attributes('stroke')).toBe('#FF4646')
  37. })
  38. it('отображает текст элемента', () => {
  39. const text = 'Тестовый элемент'
  40. const wrapper = mount(SideBarElement, {
  41. props: {
  42. type: 'home',
  43. text,
  44. color: '#FF4646'
  45. }
  46. })
  47. expect(wrapper.text()).toContain(text)
  48. })
  49. it('применяет цвет к иконке', () => {
  50. const color = '#FF4646'
  51. const wrapper = mount(SideBarElement, {
  52. props: {
  53. type: 'home',
  54. text: 'Домой',
  55. color
  56. }
  57. })
  58. const paths = wrapper.findAll('path')
  59. paths.forEach(path => {
  60. expect(path.attributes('stroke')).toBe(color)
  61. })
  62. })
  63. it('вызывает обработчик клика', async () => {
  64. const wrapper = mount(SideBarElement, {
  65. props: {
  66. type: 'home',
  67. text: 'Домой',
  68. color: '#FF4646'
  69. }
  70. })
  71. await wrapper.find('.cursor-pointer').trigger('click')
  72. expect(wrapper.emitted('click')).toBeTruthy()
  73. })
  74. it('применяет hover эффект', () => {
  75. const wrapper = mount(SideBarElement, {
  76. props: {
  77. type: 'home',
  78. text: 'Домой',
  79. color: '#FF4646'
  80. }
  81. })
  82. expect(wrapper.find('.hover\\:bg-opacity-25').exists()).toBe(true)
  83. })
  84. })