user_profile.spec.js 4.4 KB

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