actions.test.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 { ActionTypes } from 'app/containers/Projects/constants'
  21. import actions from 'app/containers/Projects/actions'
  22. import { mockStore } from './fixtures'
  23. describe('Projects Actions', () => {
  24. const {
  25. project,
  26. projectId,
  27. projects,
  28. resolve,
  29. orgId,
  30. isFavorite,
  31. adminIds,
  32. relationId
  33. } = mockStore
  34. describe('clearCurrentProject', () => {
  35. it('clearCurrentProject should return the correct type', () => {
  36. const expectedResult = {
  37. type: ActionTypes.CLEAR_CURRENT_PROJECT
  38. }
  39. expect(actions.clearCurrentProject()).toEqual(expectedResult)
  40. })
  41. })
  42. describe('loadProjects', () => {
  43. it('loadProjects should return the correct type', () => {
  44. const expectedResult = { type: ActionTypes.LOAD_PROJECTS }
  45. expect(actions.loadProjects()).toEqual(expectedResult)
  46. })
  47. })
  48. describe('projectsLoaded', () => {
  49. it('projectsLoaded should return the correct type', () => {
  50. const expectedResult = {
  51. type: ActionTypes.LOAD_PROJECTS_SUCCESS,
  52. payload: {
  53. projects
  54. }
  55. }
  56. expect(actions.projectsLoaded(projects)).toEqual(expectedResult)
  57. })
  58. })
  59. describe('loadProjectsFail', () => {
  60. it('loadProjectsFail should return the correct type', () => {
  61. const expectedResult = {
  62. type: ActionTypes.LOAD_PROJECTS_FAILURE
  63. }
  64. expect(actions.loadProjectsFail()).toEqual(expectedResult)
  65. })
  66. })
  67. describe('addProject', () => {
  68. it('addProject should return the correct type', () => {
  69. const expectedResult = {
  70. type: ActionTypes.ADD_PROJECT,
  71. payload: {
  72. project,
  73. resolve
  74. }
  75. }
  76. expect(actions.addProject(project, resolve)).toEqual(expectedResult)
  77. })
  78. })
  79. describe('projectAdded', () => {
  80. it('projectAdded should return the correct type', () => {
  81. const expectedResult = {
  82. type: ActionTypes.ADD_PROJECT_SUCCESS,
  83. payload: {
  84. result: project
  85. }
  86. }
  87. expect(actions.projectAdded(project)).toEqual(expectedResult)
  88. })
  89. })
  90. describe('addProjectFail', () => {
  91. it('addProjectFail should return the correct type', () => {
  92. const expectedResult = { type: ActionTypes.ADD_PROJECT_FAILURE }
  93. expect(actions.addProjectFail()).toEqual(expectedResult)
  94. })
  95. })
  96. describe('editProject', () => {
  97. it('editProject should return the correct type', () => {
  98. const expectedResult = {
  99. type: ActionTypes.EDIT_PROJECT,
  100. payload: {
  101. project,
  102. resolve
  103. }
  104. }
  105. expect(actions.editProject(project, resolve)).toEqual(expectedResult)
  106. })
  107. })
  108. describe('projectEdited', () => {
  109. it('projectEdited should return the correct type', () => {
  110. const expectedResult = {
  111. type: ActionTypes.EDIT_PROJECT_SUCCESS,
  112. payload: {
  113. result: project
  114. }
  115. }
  116. expect(actions.projectEdited(project)).toEqual(expectedResult)
  117. })
  118. })
  119. describe('editProjectFail', () => {
  120. it('editProjectFail should return the correct type', () => {
  121. const expectedResult = {
  122. type: ActionTypes.EDIT_PROJECT_FAILURE
  123. }
  124. expect(actions.editProjectFail()).toEqual(expectedResult)
  125. })
  126. })
  127. describe('transferProject', () => {
  128. it('transferProject should return the correct type', () => {
  129. const expectedResult = {
  130. type: ActionTypes.TRANSFER_PROJECT,
  131. payload: {
  132. id: projectId,
  133. orgId,
  134. resolve
  135. }
  136. }
  137. expect(actions.transferProject(projectId, orgId, resolve)).toEqual(
  138. expectedResult
  139. )
  140. })
  141. })
  142. describe('projectTransfered', () => {
  143. it('projectTransfered should return the correct type', () => {
  144. const expectedResult = {
  145. type: ActionTypes.TRANSFER_PROJECT_SUCCESS,
  146. payload: { result: project }
  147. }
  148. expect(actions.projectTransfered(project)).toEqual(expectedResult)
  149. })
  150. })
  151. describe('transferProjectFail', () => {
  152. it('transferProjectFail should return the correct type', () => {
  153. const expectedResult = {
  154. type: ActionTypes.TRANSFER_PROJECT_FAILURE
  155. }
  156. expect(actions.transferProjectFail()).toEqual(expectedResult)
  157. })
  158. })
  159. describe('deleteProject', () => {
  160. it('deleteProject should return the correct type', () => {
  161. const expectedResult = {
  162. type: ActionTypes.DELETE_PROJECT,
  163. payload: {
  164. id: projectId,
  165. resolve
  166. }
  167. }
  168. expect(actions.deleteProject(projectId, resolve)).toEqual(expectedResult)
  169. })
  170. })
  171. describe('projectDeleted', () => {
  172. it('projectDeleted should return the correct type', () => {
  173. const expectedResult = {
  174. type: ActionTypes.DELETE_PROJECT_SUCCESS,
  175. payload: {
  176. id: projectId
  177. }
  178. }
  179. expect(actions.projectDeleted(projectId)).toEqual(expectedResult)
  180. })
  181. })
  182. describe('deleteProjectFail', () => {
  183. it('deleteProjectFail should return the correct type', () => {
  184. const expectedResult = {
  185. type: ActionTypes.DELETE_PROJECT_FAILURE
  186. }
  187. expect(actions.deleteProjectFail()).toEqual(expectedResult)
  188. })
  189. })
  190. describe('loadProjectDetail', () => {
  191. it('loadProjectDetail should return the correct type', () => {
  192. const expectedResult = {
  193. type: ActionTypes.LOAD_PROJECT_DETAIL,
  194. payload: { id: projectId }
  195. }
  196. expect(actions.loadProjectDetail(projectId)).toEqual(expectedResult)
  197. })
  198. })
  199. describe('projectDetailLoaded', () => {
  200. it('projectDetailLoaded should return the correct type', () => {
  201. const expectedResult = {
  202. type: ActionTypes.LOAD_PROJECT_DETAIL_SUCCESS,
  203. payload: {
  204. project
  205. }
  206. }
  207. expect(actions.projectDetailLoaded(project)).toEqual(expectedResult)
  208. })
  209. })
  210. describe('loadProjectDetailFail', () => {
  211. it('loadProjectDetailFail should return the correct type', () => {
  212. const expectedResult = {
  213. type: ActionTypes.LOAD_PROJECT_DETAIL_FAILURE
  214. }
  215. expect(actions.loadProjectDetailFail()).toEqual(expectedResult)
  216. })
  217. })
  218. describe('searchProject', () => {
  219. it('searchProject should return the correct type', () => {
  220. const expectedResult = {
  221. type: ActionTypes.SEARCH_PROJECT,
  222. payload: {
  223. param: 'projectName'
  224. }
  225. }
  226. expect(actions.searchProject('projectName')).toEqual(expectedResult)
  227. })
  228. })
  229. describe('projectSearched', () => {
  230. it('projectSearched should return the correct type', () => {
  231. const expectedResult = {
  232. type: ActionTypes.SEARCH_PROJECT_SUCCESS,
  233. payload: {
  234. result: project
  235. }
  236. }
  237. expect(actions.projectSearched(project)).toEqual(expectedResult)
  238. })
  239. })
  240. describe('searchProjectFail', () => {
  241. it('searchProjectFail should return the correct type', () => {
  242. const expectedResult = {
  243. type: ActionTypes.SEARCH_PROJECT_FAILURE
  244. }
  245. expect(actions.searchProjectFail()).toEqual(expectedResult)
  246. })
  247. })
  248. describe('getProjectStarUser', () => {
  249. it('getProjectStarUser should return the correct type', () => {
  250. const expectedResult = {
  251. type: ActionTypes.GET_PROJECT_STAR_USER,
  252. payload: {
  253. id: projectId
  254. }
  255. }
  256. expect(actions.getProjectStarUser(projectId)).toEqual(expectedResult)
  257. })
  258. })
  259. describe('getProjectStarUserSuccess', () => {
  260. it('getProjectStarUserSuccess should return the correct type', () => {
  261. const expectedResult = {
  262. type: ActionTypes.GET_PROJECT_STAR_USER_SUCCESS,
  263. payload: { result: project }
  264. }
  265. expect(actions.getProjectStarUserSuccess(project)).toEqual(expectedResult)
  266. })
  267. })
  268. describe('getProjectStarUserFail', () => {
  269. it('getProjectStarUserFail should return the correct type', () => {
  270. const expectedResult = {
  271. type: ActionTypes.GET_PROJECT_STAR_USER_FAILURE
  272. }
  273. expect(actions.getProjectStarUserFail()).toEqual(expectedResult)
  274. })
  275. })
  276. describe('unStarProject', () => {
  277. it('unStarProject should return the correct type', () => {
  278. const expectedResult = {
  279. type: ActionTypes.PROJECT_UNSTAR,
  280. payload: {
  281. id: projectId,
  282. resolve
  283. }
  284. }
  285. expect(actions.unStarProject(projectId, resolve)).toEqual(expectedResult)
  286. })
  287. })
  288. describe('unStarProjectSuccess', () => {
  289. it('unStarProjectSuccess should return the correct type', () => {
  290. const expectedResult = {
  291. type: ActionTypes.PROJECT_UNSTAR_SUCCESS,
  292. payload: { result: project }
  293. }
  294. expect(actions.unStarProjectSuccess(project)).toEqual(expectedResult)
  295. })
  296. })
  297. describe('unStarProjectFail', () => {
  298. it('unStarProjectFail should return the correct type', () => {
  299. const expectedResult = {
  300. type: ActionTypes.PROJECT_UNSTAR_FAILURE
  301. }
  302. expect(actions.unStarProjectFail()).toEqual(expectedResult)
  303. })
  304. })
  305. describe('loadCollectProjects', () => {
  306. it('loadCollectProjects should return the correct type', () => {
  307. const expectedResult = {
  308. type: ActionTypes.LOAD_COLLECT_PROJECTS
  309. }
  310. expect(actions.loadCollectProjects()).toEqual(expectedResult)
  311. })
  312. })
  313. describe('collectProjectLoaded', () => {
  314. it('collectProjectLoaded should return the correct type', () => {
  315. const expectedResult = {
  316. type: ActionTypes.LOAD_COLLECT_PROJECTS_SUCCESS,
  317. payload: {
  318. result: project
  319. }
  320. }
  321. expect(actions.collectProjectLoaded(project)).toEqual(expectedResult)
  322. })
  323. })
  324. describe('collectProjectFail', () => {
  325. it('collectProjectFail should return the correct type', () => {
  326. const expectedResult = {
  327. type: ActionTypes.LOAD_COLLECT_PROJECTS_FAILURE
  328. }
  329. expect(actions.collectProjectFail()).toEqual(expectedResult)
  330. })
  331. })
  332. describe('clickCollectProjects', () => {
  333. it('clickCollectProjects should return the correct type', () => {
  334. const expectedResult = {
  335. type: ActionTypes.CLICK_COLLECT_PROJECT,
  336. payload: {
  337. isFavorite,
  338. proId: projectId,
  339. resolve
  340. }
  341. }
  342. expect(
  343. actions.clickCollectProjects(isFavorite, projectId, resolve)
  344. ).toEqual(expectedResult)
  345. })
  346. })
  347. describe('collectProjectClicked', () => {
  348. it('collectProjectClicked should return the correct type', () => {
  349. const expectedResult = {
  350. type: ActionTypes.CLICK_COLLECT_PROJECT_SUCCESS,
  351. payload: {
  352. result: project
  353. }
  354. }
  355. expect(actions.collectProjectClicked(project)).toEqual(expectedResult)
  356. })
  357. })
  358. describe('clickCollectProjectFail', () => {
  359. it('clickCollectProjectFail should return the correct type', () => {
  360. const expectedResult = {
  361. type: ActionTypes.CLICK_COLLECT_PROJECT_FAILURE
  362. }
  363. expect(actions.clickCollectProjectFail()).toEqual(expectedResult)
  364. })
  365. })
  366. describe('addProjectAdmin', () => {
  367. it('addProjectAdmin should return the correct type', () => {
  368. const expectedResult = {
  369. type: ActionTypes.ADD_PROJECT_ADMIN,
  370. payload: {
  371. id: projectId,
  372. adminIds,
  373. resolve
  374. }
  375. }
  376. expect(actions.addProjectAdmin(projectId, adminIds, resolve)).toEqual(
  377. expectedResult
  378. )
  379. })
  380. })
  381. describe('projectAdminAdded', () => {
  382. it('projectAdminAdded should return the correct type', () => {
  383. const expectedResult = {
  384. type: ActionTypes.ADD_PROJECT_ADMIN_SUCCESS,
  385. payload: { result: project }
  386. }
  387. expect(actions.projectAdminAdded(project)).toEqual(expectedResult)
  388. })
  389. })
  390. describe('addProjectAdminFail', () => {
  391. it('addProjectAdminFail should return the correct type', () => {
  392. const expectedResult = {
  393. type: ActionTypes.ADD_PROJECT_ADMIN_FAIL
  394. }
  395. expect(actions.addProjectAdminFail()).toEqual(expectedResult)
  396. })
  397. })
  398. describe('deleteProjectAdmin', () => {
  399. it('deleteProjectAdmin should return the correct type', () => {
  400. const expectedResult = {
  401. type: ActionTypes.DELETE_PROJECT_ADMIN,
  402. payload: {
  403. id: projectId,
  404. relationId,
  405. resolve
  406. }
  407. }
  408. expect(
  409. actions.deleteProjectAdmin(projectId, relationId, resolve)
  410. ).toEqual(expectedResult)
  411. })
  412. })
  413. describe('projectAdminDeleted', () => {
  414. it('projectAdminDeleted should return the correct type', () => {
  415. const expectedResult = {
  416. type: ActionTypes.DELETE_PROJECT_ADMIN_SUCCESS,
  417. payload: { result: project }
  418. }
  419. expect(actions.projectAdminDeleted(project)).toEqual(expectedResult)
  420. })
  421. })
  422. describe('deleteProjectAdminFail', () => {
  423. it('deleteProjectAdminFail should return the correct type', () => {
  424. const expectedResult = {
  425. type: ActionTypes.DELETE_PROJECT_ADMIN_FAIL
  426. }
  427. expect(actions.deleteProjectAdminFail()).toEqual(expectedResult)
  428. })
  429. })
  430. describe('addProjectRole', () => {
  431. it('addProjectRole should return the correct type', () => {
  432. const expectedResult = {
  433. type: ActionTypes.ADD_PROJECT_ROLE,
  434. payload: {
  435. projectId,
  436. roleIds: adminIds,
  437. resolve
  438. }
  439. }
  440. expect(actions.addProjectRole(projectId, adminIds, resolve)).toEqual(
  441. expectedResult
  442. )
  443. })
  444. })
  445. describe('projectRoleAdded', () => {
  446. it('projectRoleAdded should return the correct type', () => {
  447. const expectedResult = {
  448. type: ActionTypes.ADD_PROJECT_ROLE_SUCCESS,
  449. payload: { result: project }
  450. }
  451. expect(actions.projectRoleAdded(project)).toEqual(expectedResult)
  452. })
  453. })
  454. describe('addProjectRoleFail', () => {
  455. it('addProjectRoleFail should return the correct type', () => {
  456. const expectedResult = {
  457. type: ActionTypes.ADD_PROJECT_ROLE_FAIL
  458. }
  459. expect(actions.addProjectRoleFail()).toEqual(expectedResult)
  460. })
  461. })
  462. describe('deleteProjectRole', () => {
  463. it('deleteProjectRole should return the correct type', () => {
  464. const expectedResult = {
  465. type: ActionTypes.DELETE_PROJECT_ROLE,
  466. payload: {
  467. id: projectId,
  468. relationId,
  469. resolve
  470. }
  471. }
  472. expect(actions.deleteProjectRole(projectId, relationId, resolve)).toEqual(
  473. expectedResult
  474. )
  475. })
  476. })
  477. describe('projectRoleDeleted', () => {
  478. it('projectRoleDeleted should return the correct type', () => {
  479. const expectedResult = {
  480. type: ActionTypes.DELETE_PROJECT_ROLE_SUCCESS,
  481. payload: { result: project }
  482. }
  483. expect(actions.projectRoleDeleted(project)).toEqual(expectedResult)
  484. })
  485. })
  486. describe('deleteProjectRoleFail', () => {
  487. it('deleteProjectRoleFail should return the correct type', () => {
  488. const expectedResult = {
  489. type: ActionTypes.DELETE_PROJECT_ROLE_FAIL
  490. }
  491. expect(actions.deleteProjectRoleFail()).toEqual(expectedResult)
  492. })
  493. })
  494. describe('updateRelRoleProject', () => {
  495. it('updateRelRoleProject should return the correct type', () => {
  496. const expectedResult = {
  497. type: ActionTypes.UPDATE_RELATION_ROLE_PROJECT,
  498. payload: {
  499. roleId: relationId,
  500. projectId,
  501. projectRole: adminIds
  502. }
  503. }
  504. expect(
  505. actions.updateRelRoleProject(relationId, projectId, adminIds)
  506. ).toEqual(expectedResult)
  507. })
  508. })
  509. describe('relRoleProjectUpdated', () => {
  510. it('relRoleProjectUpdated should return the correct type', () => {
  511. const expectedResult = {
  512. type: ActionTypes.UPDATE_RELATION_ROLE_PROJECT_SUCCESS,
  513. payload: { result: project }
  514. }
  515. expect(actions.relRoleProjectUpdated(project)).toEqual(expectedResult)
  516. })
  517. })
  518. describe('updateRelRoleProjectFail', () => {
  519. it('updateRelRoleProjectFail should return the correct type', () => {
  520. const expectedResult = {
  521. type: ActionTypes.UPDATE_RELATION_ROLE_PROJECT_FAIL
  522. }
  523. expect(actions.updateRelRoleProjectFail()).toEqual(expectedResult)
  524. })
  525. })
  526. describe('deleteRelRoleProject', () => {
  527. it('deleteRelRoleProject should return the correct type', () => {
  528. const expectedResult = {
  529. type: ActionTypes.DELETE_RELATION_ROLE_PROJECT,
  530. payload: {
  531. roleId: relationId,
  532. projectId,
  533. resolve
  534. }
  535. }
  536. expect(
  537. actions.deleteRelRoleProject(relationId, projectId, resolve)
  538. ).toEqual(expectedResult)
  539. })
  540. })
  541. describe('relRoleProjectDeleted', () => {
  542. it('relRoleProjectDeleted should return the correct type', () => {
  543. const expectedResult = {
  544. type: ActionTypes.DELETE_RELATION_ROLE_PROJECT_SUCCESS,
  545. payload: { result: project }
  546. }
  547. expect(actions.relRoleProjectDeleted(project)).toEqual(expectedResult)
  548. })
  549. })
  550. describe('deleteRelRoleProjectFail', () => {
  551. it('deleteRelRoleProjectFail should return the correct type', () => {
  552. const expectedResult = {
  553. type: ActionTypes.DELETE_RELATION_ROLE_PROJECT_FAIL
  554. }
  555. expect(actions.deleteRelRoleProjectFail()).toEqual(expectedResult)
  556. })
  557. })
  558. describe('loadRelRoleProject', () => {
  559. it('loadRelRoleProject should return the correct type', () => {
  560. const expectedResult = {
  561. type: ActionTypes.LOAD_RELATION_ROLE_PROJECT,
  562. payload: {
  563. id: projectId,
  564. roleId: relationId
  565. }
  566. }
  567. expect(actions.loadRelRoleProject(projectId, relationId)).toEqual(
  568. expectedResult
  569. )
  570. })
  571. })
  572. describe('relRoleProjectLoaded', () => {
  573. it('relRoleProjectLoaded should return the correct type', () => {
  574. const expectedResult = {
  575. type: ActionTypes.RELATION_ROLE_PROJECT_LOADED,
  576. payload: {
  577. result: project
  578. }
  579. }
  580. expect(actions.relRoleProjectLoaded(project)).toEqual(expectedResult)
  581. })
  582. })
  583. describe('loadRelRoleProjectFail', () => {
  584. it('loadRelRoleProjectFail should return the correct type', () => {
  585. const expectedResult = {
  586. type: ActionTypes.LOAD_RELATION_ROLE_PROJECT_FAIL
  587. }
  588. expect(actions.loadRelRoleProjectFail()).toEqual(expectedResult)
  589. })
  590. })
  591. describe('excludeRoles', () => {
  592. it('excludeRoles should return the correct type', () => {
  593. const expectedResult = {
  594. type: ActionTypes.EXCLUDE_ROLES,
  595. payload: {
  596. type: 'roleType',
  597. id: relationId,
  598. resolve
  599. }
  600. }
  601. expect(actions.excludeRoles('roleType', relationId, resolve)).toEqual(
  602. expectedResult
  603. )
  604. })
  605. })
  606. describe('rolesExcluded', () => {
  607. it('rolesExcluded should return the correct type', () => {
  608. const expectedResult = {
  609. type: ActionTypes.EXCLUDE_ROLES_SUCCESS,
  610. payload: { result: project }
  611. }
  612. expect(actions.rolesExcluded(project)).toEqual(expectedResult)
  613. })
  614. })
  615. describe('excludeRolesFail', () => {
  616. it('excludeRolesFail should return the correct type', () => {
  617. const expectedResult = {
  618. type: ActionTypes.EXCLUDE_ROLES_FAIL,
  619. payload: {
  620. err: 'err'
  621. }
  622. }
  623. expect(actions.excludeRolesFail('err')).toEqual(expectedResult)
  624. })
  625. })
  626. })