user_profile.spec.js 4.2 KB

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