user_profile.spec.js 4.4 KB

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