@@ -5,18 +5,18 @@ describe('Unit tests for teams controller', function () {
55
66 var $controller , createController , $injector , $rootScope , $scope , utilities , $mdDialog , $state , $http , vm ;
77
8- beforeEach ( inject ( function ( _$controller_ , _$rootScope_ , _$injector_ , _utilities_ , _$mdDialog_ , _loaderService_ , _$state_ , _$http_ , ) {
8+ beforeEach ( inject ( function ( _$controller_ , _$rootScope_ , _$injector_ , _utilities_ , _$mdDialog_ , _loaderService_ , _$state_ , _$http_ , ) {
99 $controller = _$controller_ ;
1010 $rootScope = _$rootScope_ ;
1111 utilities = _utilities_ ;
1212 $mdDialog = _$mdDialog_ ;
13- $state = _$state_ ;
13+ $state = _$state_ ;
1414 $http = _$http_ ;
1515 $injector = _$injector_ ;
1616
1717 $scope = $rootScope . $new ( ) ;
1818 createController = function ( ) {
19- return $controller ( 'TeamsCtrl' , { $scope : $scope } ) ;
19+ return $controller ( 'TeamsCtrl' , { $scope : $scope } ) ;
2020 } ;
2121 vm = $controller ( 'TeamsCtrl' , { $scope : $scope } ) ;
2222 } ) ) ;
@@ -172,7 +172,7 @@ describe('Unit tests for teams controller', function () {
172172 // team pagination response
173173 next : 'page=4' ,
174174 previous : 'page=2' ,
175- } ;
175+ } ;
176176 vm = createController ( ) ;
177177 spyOn ( vm , 'startLoader' ) ;
178178 spyOn ( $http , 'get' ) . and . callFake ( function ( ) {
@@ -186,7 +186,7 @@ describe('Unit tests for teams controller', function () {
186186 var headers = {
187187 'Authorization' : "Token " + utilities . getData ( 'userKey' )
188188 } ;
189- expect ( $http . get ) . toHaveBeenCalledWith ( url , { headers : headers } ) ;
189+ expect ( $http . get ) . toHaveBeenCalledWith ( url , { headers : headers } ) ;
190190 } ) ;
191191
192192 it ( 'backend error for the global function \
@@ -201,60 +201,6 @@ describe('Unit tests for teams controller', function () {
201201 expect ( $state . go ) . toHaveBeenCalledWith ( 'web.permission-denied' ) ;
202202 expect ( utilities . hideLoader ) . toHaveBeenCalled ( ) ;
203203 } ) ;
204-
205- it ( 'should set pagination variables correctly when next and previous are null in load()' , function ( done ) {
206- var response = {
207- data : {
208- next : null ,
209- previous : null ,
210- count : 20
211- }
212- } ;
213- vm = createController ( ) ;
214- spyOn ( vm , 'startLoader' ) ;
215- spyOn ( vm , 'stopLoader' ) ;
216- spyOn ( $http , 'get' ) . and . callFake ( function ( ) {
217- return {
218- then : function ( cb ) {
219- cb ( response ) ;
220- expect ( vm . existTeam ) . toEqual ( response . data ) ;
221- expect ( vm . isNext ) . toBe ( 'disabled' ) ;
222- expect ( vm . currentPage ) . toBe ( 2 ) ;
223- expect ( vm . isPrev ) . toBe ( 'disabled' ) ;
224- expect ( vm . stopLoader ) . toHaveBeenCalled ( ) ;
225- done ( ) ;
226- }
227- } ;
228- } ) ;
229- vm . load ( 'someurl' ) ;
230- } ) ;
231-
232- it ( 'should set pagination variables correctly when next and previous are present in load()' , function ( done ) {
233- var response = {
234- data : {
235- next : 'someurl?page=3' ,
236- previous : 'someurl?page=1' ,
237- count : 30
238- }
239- } ;
240- vm = createController ( ) ;
241- spyOn ( vm , 'startLoader' ) ;
242- spyOn ( vm , 'stopLoader' ) ;
243- spyOn ( $http , 'get' ) . and . callFake ( function ( ) {
244- return {
245- then : function ( cb ) {
246- cb ( response ) ;
247- expect ( vm . existTeam ) . toEqual ( response . data ) ;
248- expect ( vm . isNext ) . toBe ( '' ) ;
249- expect ( vm . currentPage ) . toBe ( 2 ) ;
250- expect ( vm . isPrev ) . toBe ( '' ) ;
251- expect ( vm . stopLoader ) . toHaveBeenCalled ( ) ;
252- done ( ) ;
253- }
254- } ;
255- } ) ;
256- vm . load ( 'someurl' ) ;
257- } ) ;
258204 } ) ;
259205
260206 describe ( 'Unit tests for createNewTeam function' , function ( ) {
@@ -308,8 +254,7 @@ describe('Unit tests for teams controller', function () {
308254
309255 teamList . forEach ( response => {
310256 it ( 'when pagination next is ' + response . next + 'and previous is ' + response . previous + '\
311- `participants/participant_team`' , function ( ) {
312- ;
257+ `participants/participant_team`' , function ( ) { ;
313258 success = true ;
314259 successResponse = response ;
315260 vm . team . teamName = "Team Name" ;
@@ -380,97 +325,6 @@ describe('Unit tests for teams controller', function () {
380325 vm . confirmDelete ( ev , participantTeamId ) ;
381326 expect ( $mdDialog . show ) . toHaveBeenCalledWith ( confirm ) ;
382327 } ) ;
383-
384- it ( 'should remove self from team successfully and update team list' , function ( done ) {
385- var participantTeamId = 1 ;
386- var ev = new Event ( '$click' ) ;
387- var confirm = $mdDialog . confirm ( )
388- . title ( 'Would you like to remove yourself?' )
389- . textContent ( 'Note: This action will remove you from the team.' )
390- . ariaLabel ( 'Lucky day' )
391- . targetEvent ( ev )
392- . ok ( 'Yes' )
393- . cancel ( "No" ) ;
394-
395-
396- $mdDialog . show . and . returnValue ( Promise . resolve ( ) ) ;
397-
398-
399- var sendRequestSpy = spyOn ( utilities , 'sendRequest' ) . and . callFake ( function ( params ) {
400- if ( params . method === 'DELETE' ) {
401- params . callback . onSuccess ( ) ;
402- } else if ( params . method === 'GET' ) {
403- params . callback . onSuccess ( {
404- status : 200 ,
405- data : {
406- next : null ,
407- previous : null ,
408- count : 0
409- }
410- } ) ;
411- }
412- } ) ;
413-
414- spyOn ( vm , 'startLoader' ) . and . callThrough ( ) ;
415- spyOn ( vm , 'stopLoader' ) . and . callThrough ( ) ;
416- spyOn ( $rootScope , 'notify' ) ;
417-
418- vm . confirmDelete ( ev , participantTeamId ) ;
419-
420- setTimeout ( function ( ) {
421- expect ( $mdDialog . show ) . toHaveBeenCalledWith ( confirm ) ;
422- expect ( vm . startLoader ) . toHaveBeenCalled ( ) ;
423- expect ( sendRequestSpy ) . toHaveBeenCalled ( ) ;
424- expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "info" , "You have removed yourself successfully" ) ;
425- expect ( vm . existTeam . count ) . toBe ( 0 ) ;
426- expect ( vm . showPagination ) . toBe ( false ) ;
427- expect ( vm . paginationMsg ) . toBe ( "No team exists for now. Start by creating a new team!" ) ;
428- expect ( vm . stopLoader ) . toHaveBeenCalled ( ) ;
429- done ( ) ;
430- } , 0 ) ;
431- } ) ;
432-
433- it ( 'should show error notification if remove self from team fails' , function ( done ) {
434- var participantTeamId = 1 ;
435- var ev = new Event ( '$click' ) ;
436- $mdDialog . show . and . returnValue ( Promise . resolve ( ) ) ;
437-
438- spyOn ( vm , 'startLoader' ) . and . callThrough ( ) ;
439- spyOn ( vm , 'stopLoader' ) . and . callThrough ( ) ;
440- spyOn ( $rootScope , 'notify' ) ;
441-
442- spyOn ( utilities , 'sendRequest' ) . and . callFake ( function ( params ) {
443- if ( params . method === 'DELETE' ) {
444- params . callback . onError ( { data : { error : 'Some error' } } ) ;
445- }
446- } ) ;
447-
448- vm . confirmDelete ( ev , participantTeamId ) ;
449-
450- setTimeout ( function ( ) {
451- expect ( vm . startLoader ) . toHaveBeenCalled ( ) ;
452- expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "error" , "Some error" ) ;
453- expect ( vm . stopLoader ) . toHaveBeenCalled ( ) ;
454- done ( ) ;
455- } , 0 ) ;
456- } ) ;
457-
458- it ( 'should do nothing if dialog is cancelled' , function ( done ) {
459- var participantTeamId = 1 ;
460- var ev = new Event ( '$click' ) ;
461- $mdDialog . show . and . returnValue ( Promise . reject ( ) ) ;
462-
463- spyOn ( vm , 'startLoader' ) ;
464- spyOn ( utilities , 'sendRequest' ) ;
465-
466- vm . confirmDelete ( ev , participantTeamId ) ;
467-
468- setTimeout ( function ( ) {
469- expect ( vm . startLoader ) . not . toHaveBeenCalled ( ) ;
470- expect ( utilities . sendRequest ) . not . toHaveBeenCalled ( ) ;
471- done ( ) ;
472- } , 0 ) ;
473- } ) ;
474328 } ) ;
475329
476330 describe ( 'Unit tests for inviteOthers function' , function ( ) {
@@ -495,51 +349,6 @@ describe('Unit tests for teams controller', function () {
495349 vm . inviteOthers ( ev , participantTeamId ) ;
496350 expect ( $mdDialog . show ) . toHaveBeenCalledWith ( confirm ) ;
497351 } ) ;
498-
499- it ( 'should send invite and show success notification' , function ( done ) {
500- var participantTeamId = 1 ;
501- var ev = new Event ( '$click' ) ;
502- var email = 'test@email.com' ;
503- var message = 'Invitation sent!' ;
504- $mdDialog . show . and . returnValue ( Promise . resolve ( email ) ) ;
505- spyOn ( utilities , 'sendRequest' ) . and . callFake ( function ( params ) {
506- expect ( params . url ) . toContain ( '/invite' ) ;
507- expect ( params . method ) . toBe ( 'POST' ) ;
508- expect ( params . data . email ) . toBe ( email ) ;
509- params . callback . onSuccess ( { data : { message : message } } ) ;
510- expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "success" , message ) ;
511- done ( ) ;
512- } ) ;
513- spyOn ( $rootScope , 'notify' ) ;
514- vm . inviteOthers ( ev , participantTeamId ) ;
515- } ) ;
516-
517- it ( 'should send invite and show error notification on failure' , function ( done ) {
518- var participantTeamId = 1 ;
519- var ev = new Event ( '$click' ) ;
520- var email = 'test@email.com' ;
521- var error = 'Some error' ;
522- $mdDialog . show . and . returnValue ( Promise . resolve ( email ) ) ;
523- spyOn ( utilities , 'sendRequest' ) . and . callFake ( function ( params ) {
524- params . callback . onError ( { data : { error : error } } ) ;
525- expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "error" , error ) ;
526- done ( ) ;
527- } ) ;
528- spyOn ( $rootScope , 'notify' ) ;
529- vm . inviteOthers ( ev , participantTeamId ) ;
530- } ) ;
531-
532- it ( 'should do nothing if invite dialog is cancelled' , function ( done ) {
533- var participantTeamId = 1 ;
534- var ev = new Event ( '$click' ) ;
535- $mdDialog . show . and . returnValue ( Promise . reject ( ) ) ;
536- spyOn ( utilities , 'sendRequest' ) ;
537- vm . inviteOthers ( ev , participantTeamId ) ;
538- setTimeout ( function ( ) {
539- expect ( utilities . sendRequest ) . not . toHaveBeenCalled ( ) ;
540- done ( ) ;
541- } , 0 ) ;
542- } ) ;
543352 } ) ;
544353
545354 describe ( 'Unit tests for showMdDialog function `participants/participant_team/`' , function ( ) {
@@ -653,7 +462,7 @@ describe('Unit tests for teams controller', function () {
653462 success = false ;
654463 errorResponse = {
655464 team_name : 'team name error' ,
656- error : 'error'
465+ error : 'error'
657466 } ;
658467 vm . updateParticipantTeamData ( updateParticipantTeamDataForm ) ;
659468 expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "error" , errorResponse . team_name ) ;
@@ -663,7 +472,7 @@ describe('Unit tests for teams controller', function () {
663472 var updateParticipantTeamDataForm = true ;
664473 success = false ;
665474 errorResponse = {
666- error : 'error'
475+ error : 'error'
667476 } ;
668477 vm . updateParticipantTeamData ( updateParticipantTeamDataForm ) ;
669478 expect ( $rootScope . notify ) . toHaveBeenCalledWith ( "error" , errorResponse . error ) ;
@@ -675,4 +484,4 @@ describe('Unit tests for teams controller', function () {
675484 expect ( $mdDialog . hide ) . toHaveBeenCalled ( ) ;
676485 } ) ;
677486 } ) ;
678- } ) ;
487+ } ) ;
0 commit comments