PersonCard.spec.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { describe, it, expect, vi } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import PersonCard from '../PersonCard.vue'
  4. import { Browser } from '@capacitor/browser'
  5. // Мокаем Browser.open
  6. vi.mock('@capacitor/browser', () => ({
  7. Browser: {
  8. open: vi.fn()
  9. }
  10. }))
  11. // Мокаем иконки
  12. const IVk = { template: '<div class="vk-icon"></div>' }
  13. const ITg = { template: '<div class="tg-icon"></div>' }
  14. const IGithub = { template: '<div class="github-icon"></div>' }
  15. describe('PersonCard', () => {
  16. const defaultProps = {
  17. name: 'Иван Иванов',
  18. nickname: '@ivan',
  19. avatar: 'avatar.jpg',
  20. github: 'https://github.com/ivan',
  21. vk: 'https://vk.com/ivan',
  22. tg: 'https://t.me/ivan'
  23. }
  24. it('рендерит все данные пользователя', () => {
  25. const wrapper = mount(PersonCard, {
  26. props: defaultProps,
  27. global: {
  28. components: { IVk, ITg, IGithub }
  29. }
  30. })
  31. expect(wrapper.find('img').attributes('src')).toBe('/avatar.jpg')
  32. expect(wrapper.find('img').attributes('alt')).toBe('avatar')
  33. expect(wrapper.text()).toContain('Иван Иванов')
  34. expect(wrapper.text()).toContain('@ivan')
  35. })
  36. it('отображает все иконки социальных сетей', () => {
  37. const wrapper = mount(PersonCard, {
  38. props: defaultProps,
  39. global: {
  40. components: { IVk, ITg, IGithub }
  41. }
  42. })
  43. expect(wrapper.find('.vk-icon').exists()).toBe(true)
  44. expect(wrapper.find('.tg-icon').exists()).toBe(true)
  45. expect(wrapper.find('.github-icon').exists()).toBe(true)
  46. })
  47. it('скрывает иконки, если ссылки не предоставлены', () => {
  48. const wrapper = mount(PersonCard, {
  49. props: {
  50. ...defaultProps,
  51. vk: '',
  52. tg: '',
  53. github: ''
  54. },
  55. global: {
  56. components: { IVk, ITg, IGithub }
  57. }
  58. })
  59. expect(wrapper.find('.vk-icon').exists()).toBe(false)
  60. expect(wrapper.find('.tg-icon').exists()).toBe(false)
  61. expect(wrapper.find('.github-icon').exists()).toBe(false)
  62. })
  63. it('открывает ссылку при клике на иконку VK', async () => {
  64. const wrapper = mount(PersonCard, {
  65. props: defaultProps,
  66. global: {
  67. components: { IVk, ITg, IGithub }
  68. }
  69. })
  70. await wrapper.find('.vk-icon').trigger('click')
  71. expect(Browser.open).toHaveBeenCalledWith({ url: 'https://vk.com/ivan' })
  72. })
  73. it('открывает ссылку при клике на иконку Telegram', async () => {
  74. const wrapper = mount(PersonCard, {
  75. props: defaultProps,
  76. global: {
  77. components: { IVk, ITg, IGithub }
  78. }
  79. })
  80. await wrapper.find('.tg-icon').trigger('click')
  81. expect(Browser.open).toHaveBeenCalledWith({ url: 'https://t.me/ivan' })
  82. })
  83. it('открывает ссылку при клике на иконку GitHub', async () => {
  84. const wrapper = mount(PersonCard, {
  85. props: defaultProps,
  86. global: {
  87. components: { IVk, ITg, IGithub }
  88. }
  89. })
  90. await wrapper.find('.github-icon').trigger('click')
  91. expect(Browser.open).toHaveBeenCalledWith({ url: 'https://github.com/ivan' })
  92. })
  93. })