Header.spec.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { describe, it, expect, vi } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import { createPinia, setActivePinia } from 'pinia'
  4. import { ref } from 'vue'
  5. import Header from '../Base/Header.vue'
  6. // Создаем Pinia
  7. const pinia = createPinia()
  8. setActivePinia(pinia)
  9. // Мокаем useRouter
  10. vi.mock('vue-router', () => ({
  11. useRouter: () => ({
  12. currentRoute: {
  13. value: {
  14. name: 'test-route'
  15. }
  16. }
  17. })
  18. }))
  19. // Мокаем updateColors
  20. vi.mock('~/composables/useColors', () => ({
  21. updateColors: vi.fn()
  22. }))
  23. // Создаем мок для useSideBar
  24. const mockShow = vi.fn()
  25. vi.mock('~/store/useSideBar', () => ({
  26. useSideBar: () => ({
  27. isVisible: ref(false),
  28. isRendered: ref(false),
  29. toggle: vi.fn(),
  30. close: vi.fn(),
  31. open: vi.fn(),
  32. show: mockShow
  33. })
  34. }))
  35. describe('Header', () => {
  36. it('отображает название текущего маршрута', async () => {
  37. const wrapper = mount(Header, {
  38. global: {
  39. plugins: [pinia],
  40. mocks: {
  41. $router: {
  42. currentRoute: {
  43. value: {
  44. name: 'test-route'
  45. }
  46. }
  47. }
  48. }
  49. }
  50. })
  51. expect(wrapper.text()).toContain('test-route')
  52. })
  53. it('открывает меню при клике на кнопку', async () => {
  54. const wrapper = mount(Header, {
  55. global: {
  56. plugins: [pinia],
  57. mocks: {
  58. $router: {
  59. currentRoute: {
  60. value: {
  61. name: 'test-route'
  62. }
  63. }
  64. }
  65. }
  66. }
  67. })
  68. await wrapper.find('.w-8.h-8').trigger('click')
  69. expect(mockShow).toHaveBeenCalled()
  70. })
  71. })