sagas.test.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import { expectSaga } from 'redux-saga-test-plan'
  21. import * as matchers from 'redux-saga-test-plan/matchers'
  22. import { throwError } from 'redux-saga-test-plan/providers'
  23. import request from 'app/utils/request'
  24. import actions from 'app/containers/Display/actions'
  25. import VizActions from 'app/containers/Viz/actions'
  26. import {
  27. getSlideDetail,
  28. uploadCurrentSlideCover,
  29. addSlideLayers,
  30. editSlideLayers,
  31. editSlideLayerParams,
  32. deleteSlideLayers,
  33. resizeLayer,
  34. copySlideLayers,
  35. pasteSlideLayers,
  36. changeLayersStack,
  37. updateLayersAlignment,
  38. getDisplayShareLink
  39. } from 'app/containers/Display/sagas'
  40. import {
  41. mockDisplayId,
  42. mockSlideId,
  43. mockSlideDetail,
  44. mockGraphLayerFormed,
  45. mockWidgetFormed,
  46. mockCover,
  47. mockSlide,
  48. mockSlideCoverUploadImgSrc,
  49. mockGraphLayerId,
  50. mockViewItem,
  51. mockLayerParamsUnChanged,
  52. mockChangedParams,
  53. mockSlideSize,
  54. mockLayerScale,
  55. mockDeltaPosition,
  56. mockEventTrigger,
  57. mockFinish,
  58. mockDeltaSize,
  59. mockOperation,
  60. mockAlignmentType,
  61. mockAuthShareToken,
  62. mockShareLinkParams,
  63. mockShareTokenReq,
  64. mockDisplayDefaultState,
  65. mockDisplayState,
  66. mockVizState,
  67. mockViewState
  68. } from './fixtures'
  69. import { getMockResponse } from 'test/utils/fixtures'
  70. describe('getSlideDetail Saga', () => {
  71. it('should dispatch the slideDetailLoaded action if it requests the data successfully', () => {
  72. return expectSaga(
  73. getSlideDetail,
  74. actions.loadSlideDetail(mockDisplayId, mockSlideId)
  75. )
  76. .withState(mockDisplayState)
  77. .provide([[matchers.call.fn(request), getMockResponse(mockSlideDetail)]])
  78. .dispatch(
  79. actions.slideDetailLoaded(
  80. mockSlideId,
  81. [mockGraphLayerFormed],
  82. [mockWidgetFormed],
  83. {[mockWidgetFormed.viewId]: {
  84. ...mockViewItem,
  85. model: {},
  86. variable: []
  87. }}
  88. )
  89. )
  90. .run()
  91. })
  92. it('should call the loadSlideDetailFail action if the response errors', () => {
  93. const errors = new Error('error')
  94. return expectSaga(
  95. getSlideDetail,
  96. actions.loadSlideDetail(mockDisplayId, mockSlideId)
  97. )
  98. .withState(mockDisplayState)
  99. .provide([[matchers.call.fn(request), throwError(errors)]])
  100. .dispatch(actions.loadSlideDetailFail(errors))
  101. .run()
  102. })
  103. })
  104. describe('uploadCurrentSlideCover saga', () => {
  105. it('should call the currentSlideCoverUploaded action if it requests the data successfully', () => {
  106. return expectSaga(
  107. uploadCurrentSlideCover,
  108. actions.uploadCurrentSlideCover(mockCover, mockSlide)
  109. )
  110. .provide([
  111. [matchers.call.fn(request), getMockResponse(mockSlideCoverUploadImgSrc)]
  112. ])
  113. .dispatch(actions.currentSlideCoverUploaded(mockSlideCoverUploadImgSrc))
  114. .dispatch(VizActions.editSlides([mockSlide]))
  115. .run()
  116. })
  117. it('should call the uploadCurrentSlideCoverFail action if the response errors', () => {
  118. const errors = new Error('error')
  119. return expectSaga(
  120. uploadCurrentSlideCover,
  121. actions.uploadCurrentSlideCover(mockCover, mockSlide)
  122. )
  123. .provide([[matchers.call.fn(request), throwError(errors)]])
  124. .dispatch(actions.uploadCurrentSlideCoverFail(errors))
  125. .run()
  126. })
  127. })
  128. describe('addSlideLayers saga', () => {
  129. it('should call the slideLayersAdded action if it requests the data successfully', () => {
  130. return expectSaga(
  131. addSlideLayers,
  132. actions.addSlideLayers(
  133. mockDisplayId,
  134. mockSlideId,
  135. [mockGraphLayerFormed],
  136. [mockWidgetFormed]
  137. )
  138. )
  139. .withState(mockViewState)
  140. .provide([
  141. [matchers.call.fn(request), getMockResponse([mockGraphLayerFormed])]
  142. ])
  143. .dispatch(
  144. actions.slideLayersAdded(
  145. mockSlideId,
  146. [mockGraphLayerFormed],
  147. [mockWidgetFormed]
  148. )
  149. )
  150. .run()
  151. })
  152. it('should call the addSlideLayersFail action if the response errors', () => {
  153. const errors = new Error('error')
  154. return expectSaga(
  155. addSlideLayers,
  156. actions.addSlideLayers(
  157. mockDisplayId,
  158. mockSlideId,
  159. [mockGraphLayerFormed],
  160. [mockWidgetFormed]
  161. )
  162. )
  163. .withState(mockViewState)
  164. .provide([[matchers.call.fn(request), throwError(errors)]])
  165. .dispatch(actions.addSlideLayersFail())
  166. .run()
  167. })
  168. })
  169. describe('editSlideLayers saga', () => {
  170. it('should call the slideLayersEdited action if it requests the data successfully', () => {
  171. return expectSaga(
  172. editSlideLayers,
  173. actions.editSlideLayers(
  174. mockDisplayId,
  175. mockSlideId,
  176. [mockGraphLayerFormed],
  177. mockLayerParamsUnChanged
  178. )
  179. )
  180. .dispatch(actions.slideLayersEdited(mockSlideId, [mockGraphLayerFormed]))
  181. .run()
  182. })
  183. it('should call the editSlideLayersFail action if the response errors', () => {
  184. return expectSaga(
  185. editSlideLayers,
  186. actions.editSlideLayers(
  187. mockDisplayId,
  188. mockSlideId,
  189. [mockGraphLayerFormed],
  190. mockLayerParamsUnChanged
  191. )
  192. )
  193. .dispatch(actions.editSlideLayersFail())
  194. .run()
  195. })
  196. })
  197. describe('editSlideLayerParams saga', () => {
  198. it('should call the editSlideLayers action if it requests the data successfully', () => {
  199. return expectSaga(
  200. editSlideLayerParams,
  201. actions.editSlideLayerParams(mockGraphLayerId, mockChangedParams)
  202. )
  203. .withState(mockDisplayState)
  204. .withState(mockVizState)
  205. .dispatch(
  206. actions.editSlideLayers(
  207. mockDisplayId,
  208. mockSlideId,
  209. [mockGraphLayerFormed],
  210. mockLayerParamsUnChanged
  211. )
  212. )
  213. .run()
  214. })
  215. })
  216. describe('deleteSlideLayers saga', () => {
  217. it('should call the slideLayersDeleted action if it requests the data successfully', () => {
  218. return expectSaga(
  219. deleteSlideLayers,
  220. actions.deleteSlideLayers(mockDisplayId, mockSlideId)
  221. )
  222. .withState(mockDisplayState)
  223. .provide([[matchers.call.fn(request), getMockResponse({})]])
  224. .dispatch(actions.slideLayersDeleted(mockSlideId, [mockGraphLayerId]))
  225. .run()
  226. })
  227. it('should call the slideLayersDeleted action if the response errors', () => {
  228. const errors = new Error('error')
  229. return expectSaga(
  230. deleteSlideLayers,
  231. actions.deleteSlideLayers(mockDisplayId, mockSlideId)
  232. )
  233. .withState(mockDisplayState)
  234. .provide([[matchers.call.fn(request), throwError(errors)]])
  235. .dispatch(actions.deleteSlideLayersFail())
  236. .run()
  237. })
  238. })
  239. describe('resizeLayer saga', () => {
  240. it('should call the resizeLayerAdjusted action if it requests the data successfully', () => {
  241. return expectSaga(
  242. resizeLayer,
  243. actions.dragLayer(
  244. mockSlideSize,
  245. mockLayerScale,
  246. mockDeltaPosition,
  247. mockEventTrigger,
  248. mockFinish,
  249. mockGraphLayerId
  250. )
  251. )
  252. .withState(mockDisplayState)
  253. .dispatch(
  254. actions.resizeLayerAdjusted([mockGraphLayerId], mockDeltaSize, mockFinish)
  255. )
  256. .run()
  257. })
  258. })
  259. describe('copySlideLayers saga', () => {
  260. it('should call the slideLayersCopied action if it requests the data successfully', () => {
  261. return expectSaga(copySlideLayers, actions.copySlideLayers())
  262. .withState(mockDisplayState)
  263. .dispatch(actions.slideLayersCopied([mockGraphLayerFormed]))
  264. .run()
  265. })
  266. })
  267. describe('pasteSlideLayers saga', () => {
  268. it('should call the addSlideLayers action if it requests the data successfully', () => {
  269. return expectSaga(pasteSlideLayers, actions.pasteSlideLayers())
  270. .withState(mockDisplayState)
  271. .dispatch(
  272. actions.addSlideLayers(mockDisplayId, mockSlideId, [mockGraphLayerFormed])
  273. )
  274. .run()
  275. })
  276. })
  277. describe('changeLayersStack saga', () => {
  278. it('should call the editSlideLayers action if it requests the data successfully', () => {
  279. return expectSaga(
  280. changeLayersStack,
  281. actions.changeLayersStack(mockOperation)
  282. )
  283. .withState(mockDisplayState)
  284. .dispatch(
  285. actions.editSlideLayers(mockDisplayId, mockSlideId, [mockGraphLayerFormed])
  286. )
  287. .run()
  288. })
  289. })
  290. describe('updateLayersAlignment saga', () => {
  291. it('should call the editSlideLayers action if it requests the data successfully', () => {
  292. return expectSaga(
  293. updateLayersAlignment,
  294. actions.setLayersAlignment(mockAlignmentType)
  295. )
  296. .withState(mockDisplayState)
  297. .dispatch(
  298. actions.editSlideLayers(
  299. mockDisplayId,
  300. mockSlideId,
  301. [mockGraphLayerFormed],
  302. mockLayerParamsUnChanged
  303. )
  304. )
  305. .run()
  306. })
  307. })
  308. describe('getDisplayShareLink saga', () => {
  309. it('should call the displayAuthorizedShareLinkLoaded action if it requests the data successfully', () => {
  310. return expectSaga(
  311. getDisplayShareLink,
  312. actions.loadDisplayShareLink(mockShareLinkParams)
  313. )
  314. .provide([
  315. [matchers.call.fn(request), getMockResponse(mockShareTokenReq)]
  316. ])
  317. .dispatch(actions.displayAuthorizedShareLinkLoaded(mockAuthShareToken))
  318. .run()
  319. })
  320. it('should call the loadDisplayShareLinkFail action if the response errors', () => {
  321. const errors = new Error('error')
  322. return expectSaga(
  323. getDisplayShareLink,
  324. actions.loadDisplayShareLink(mockShareLinkParams)
  325. )
  326. .provide([[matchers.call.fn(request), throwError(errors)]])
  327. .put(actions.loadDisplayShareLinkFail())
  328. .run()
  329. })
  330. })