user_profile.spec.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { mount, createLocalVue } from '@vue/test-utils'
  2. import Vuex from 'vuex'
  3. import UserProfile from 'src/components/user_profile/user_profile.vue'
  4. import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js'
  5. import { getters } from 'src/modules/users.js'
  6. const localVue = createLocalVue()
  7. localVue.use(Vuex)
  8. const mutations = {
  9. clearTimeline: () => {},
  10. setError: () => {}
  11. }
  12. const testGetters = {
  13. userByName: state => getters.userByName(state.users),
  14. userById: state => getters.userById(state.users)
  15. }
  16. const localUser = {
  17. id: 100,
  18. is_local: true,
  19. screen_name: 'testUser'
  20. }
  21. const extUser = {
  22. id: 100,
  23. is_local: false,
  24. screen_name: 'testUser@test.instance'
  25. }
  26. const externalProfileStore = new Vuex.Store({
  27. mutations,
  28. getters: testGetters,
  29. state: {
  30. api: {
  31. backendInteractor: backendInteractorService('')
  32. },
  33. interface: {
  34. browserSupport: ''
  35. },
  36. config: {
  37. colors: '',
  38. highlight: {},
  39. customTheme: {
  40. colors: []
  41. }
  42. },
  43. instance: {
  44. hideUserStats: true
  45. },
  46. statuses: {
  47. timelines: {
  48. user: {
  49. statuses: [],
  50. statusesObject: {},
  51. faves: [],
  52. visibleStatuses: [],
  53. visibleStatusesObject: {},
  54. newStatusCount: 0,
  55. maxId: 0,
  56. minVisibleId: 0,
  57. loading: false,
  58. followers: [],
  59. friends: [],
  60. viewing: 'statuses',
  61. userId: 100,
  62. flushMarker: 0
  63. },
  64. media: {
  65. statuses: [],
  66. statusesObject: {},
  67. faves: [],
  68. visibleStatuses: [],
  69. visibleStatusesObject: {},
  70. newStatusCount: 0,
  71. maxId: 0,
  72. minVisibleId: 0,
  73. loading: false,
  74. followers: [],
  75. friends: [],
  76. viewing: 'statuses',
  77. userId: 100,
  78. flushMarker: 0
  79. }
  80. }
  81. },
  82. users: {
  83. currentUser: {
  84. credentials: ''
  85. },
  86. usersObject: [extUser],
  87. users: [extUser]
  88. }
  89. }
  90. })
  91. const localProfileStore = new Vuex.Store({
  92. mutations,
  93. getters: testGetters,
  94. state: {
  95. api: {
  96. backendInteractor: backendInteractorService('')
  97. },
  98. interface: {
  99. browserSupport: ''
  100. },
  101. config: {
  102. colors: '',
  103. highlight: {},
  104. customTheme: {
  105. colors: []
  106. }
  107. },
  108. instance: {
  109. hideUserStats: true
  110. },
  111. statuses: {
  112. timelines: {
  113. user: {
  114. statuses: [],
  115. statusesObject: {},
  116. faves: [],
  117. visibleStatuses: [],
  118. visibleStatusesObject: {},
  119. newStatusCount: 0,
  120. maxId: 0,
  121. minVisibleId: 0,
  122. loading: false,
  123. followers: [],
  124. friends: [],
  125. viewing: 'statuses',
  126. userId: 100,
  127. flushMarker: 0
  128. },
  129. media: {
  130. statuses: [],
  131. statusesObject: {},
  132. faves: [],
  133. visibleStatuses: [],
  134. visibleStatusesObject: {},
  135. newStatusCount: 0,
  136. maxId: 0,
  137. minVisibleId: 0,
  138. loading: false,
  139. followers: [],
  140. friends: [],
  141. viewing: 'statuses',
  142. userId: 100,
  143. flushMarker: 0
  144. }
  145. }
  146. },
  147. users: {
  148. currentUser: {
  149. credentials: ''
  150. },
  151. usersObject: [localUser],
  152. users: [localUser]
  153. }
  154. }
  155. })
  156. describe('UserProfile', () => {
  157. it('renders external profile', () => {
  158. const wrapper = mount(UserProfile, {
  159. localVue,
  160. store: externalProfileStore,
  161. mocks: {
  162. $route: {
  163. params: { id: 100 },
  164. name: 'external-user-profile'
  165. },
  166. $t: (msg) => msg
  167. }
  168. })
  169. expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser@test.instance')
  170. })
  171. it('renders local profile', () => {
  172. const wrapper = mount(UserProfile, {
  173. localVue,
  174. store: localProfileStore,
  175. mocks: {
  176. $route: {
  177. params: { name: 'testUser' },
  178. name: 'user-profile'
  179. },
  180. $t: (msg) => msg
  181. }
  182. })
  183. expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser')
  184. })
  185. })