user_profile.spec.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. }
  11. const actions = {
  12. fetchUser: () => {},
  13. fetchUserByScreenName: () => {}
  14. }
  15. const testGetters = {
  16. findUser: state => getters.findUser(state.users),
  17. relationship: state => getters.relationship(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. relationships: {}
  94. }
  95. }
  96. })
  97. const localProfileStore = new Vuex.Store({
  98. mutations,
  99. actions,
  100. getters: testGetters,
  101. state: {
  102. api: {
  103. fetchers: {},
  104. backendInteractor: backendInteractorService('')
  105. },
  106. interface: {
  107. browserSupport: ''
  108. },
  109. config: {
  110. colors: '',
  111. highlight: {},
  112. customTheme: {
  113. colors: []
  114. }
  115. },
  116. instance: {
  117. hideUserStats: true
  118. },
  119. statuses: {
  120. timelines: {
  121. user: {
  122. statuses: [],
  123. statusesObject: {},
  124. faves: [],
  125. visibleStatuses: [],
  126. visibleStatusesObject: {},
  127. newStatusCount: 0,
  128. maxId: 0,
  129. minVisibleId: 0,
  130. loading: false,
  131. followers: [],
  132. friends: [],
  133. viewing: 'statuses',
  134. userId: 100,
  135. flushMarker: 0
  136. },
  137. media: {
  138. statuses: [],
  139. statusesObject: {},
  140. faves: [],
  141. visibleStatuses: [],
  142. visibleStatusesObject: {},
  143. newStatusCount: 0,
  144. maxId: 0,
  145. minVisibleId: 0,
  146. loading: false,
  147. followers: [],
  148. friends: [],
  149. viewing: 'statuses',
  150. userId: 100,
  151. flushMarker: 0
  152. }
  153. }
  154. },
  155. users: {
  156. currentUser: {
  157. credentials: ''
  158. },
  159. usersObject: { 100: localUser, 'testuser': localUser },
  160. users: [localUser],
  161. relationships: {}
  162. }
  163. }
  164. })
  165. describe('UserProfile', () => {
  166. it('renders external profile', () => {
  167. const wrapper = mount(UserProfile, {
  168. localVue,
  169. store: externalProfileStore,
  170. mocks: {
  171. $route: {
  172. params: { id: 100 },
  173. name: 'external-user-profile'
  174. },
  175. $t: (msg) => msg
  176. }
  177. })
  178. expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser@test.instance')
  179. })
  180. it('renders local profile', () => {
  181. const wrapper = mount(UserProfile, {
  182. localVue,
  183. store: localProfileStore,
  184. mocks: {
  185. $route: {
  186. params: { name: 'testUser' },
  187. name: 'user-profile'
  188. },
  189. $t: (msg) => msg
  190. }
  191. })
  192. expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser')
  193. })
  194. })