1
1
/* jshint -W117, -W030 */
2
2
describe ( 'Skill Picker Controller' , function ( ) {
3
3
var vm ;
4
- var toasterSvc , memberCertService , profileService ;
4
+ var toasterSvc , memberCertService , profileService , state ;
5
5
var mockProfile = mockData . getMockProfile ( ) ;
6
6
7
7
beforeEach ( function ( ) {
@@ -57,11 +57,16 @@ describe('Skill Picker Controller', function() {
57
57
default : $q . when ( true )
58
58
} ) ;
59
59
60
+ // mocked $state object
61
+ state = { go : sinon . spy ( ) } ;
62
+
60
63
var scope = $rootScope . $new ( ) ;
61
64
vm = $controller ( 'SkillPickerController' , {
62
65
$scope : scope ,
63
66
userProfile : mockProfile ,
64
- featuredSkills : [ ]
67
+ featuredSkills : [ ] ,
68
+ $state : state
69
+
65
70
} ) ;
66
71
$rootScope . $digest ( ) ;
67
72
} ) ;
@@ -129,6 +134,9 @@ describe('Skill Picker Controller', function() {
129
134
expect ( mockProfile . save ) . not . to . be . called ;
130
135
expect ( profileService . updateUserSkills ) . not . to . be . called ;
131
136
expect ( memberCertService . registerMember ) . not . to . be . called ;
137
+ // we should still go to dashboard if the function is called,
138
+ // call to the function is controlled by disabling the button
139
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
132
140
} ) ;
133
141
134
142
it ( 'should update tracks for the member ' , function ( ) {
@@ -139,6 +147,7 @@ describe('Skill Picker Controller', function() {
139
147
expect ( mockProfile . save ) . to . be . calledOnce ;
140
148
expect ( profileService . updateUserSkills ) . not . to . be . called ;
141
149
expect ( memberCertService . registerMember ) . not . to . be . called ;
150
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
142
151
} ) ;
143
152
144
153
it ( 'should show error popup for updating tracks ' , function ( ) {
@@ -156,6 +165,7 @@ describe('Skill Picker Controller', function() {
156
165
expect ( toasterSvc . pop ) . to . have . been . calledWith ( 'error' , "Whoops!" , sinon . match ( 'wrong' ) ) . calledOnce ;
157
166
expect ( profileService . updateUserSkills ) . not . to . be . called ;
158
167
expect ( memberCertService . registerMember ) . not . to . be . called ;
168
+ expect ( state . go ) . not . to . be . called ;
159
169
} ) ;
160
170
161
171
it ( 'should update skills for the member ' , function ( ) {
@@ -165,6 +175,7 @@ describe('Skill Picker Controller', function() {
165
175
expect ( mockProfile . save ) . not . to . be . called ;
166
176
expect ( profileService . updateUserSkills ) . to . be . calledOnce ;
167
177
expect ( memberCertService . registerMember ) . not . to . be . called ;
178
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
168
179
} ) ;
169
180
170
181
it ( 'should show error popup for error in updating skills ' , function ( ) {
@@ -175,6 +186,7 @@ describe('Skill Picker Controller', function() {
175
186
expect ( profileService . updateUserSkills ) . to . be . calledOnce ;
176
187
expect ( toasterSvc . pop ) . to . have . been . calledWith ( 'error' , "Whoops!" , sinon . match ( 'wrong' ) ) . calledOnce ;
177
188
expect ( memberCertService . registerMember ) . not . to . be . called ;
189
+ expect ( state . go ) . not . to . be . called ;
178
190
} ) ;
179
191
180
192
it ( 'should update communities for the member ' , function ( ) {
@@ -185,6 +197,7 @@ describe('Skill Picker Controller', function() {
185
197
expect ( mockProfile . save ) . not . to . be . called ;
186
198
expect ( profileService . updateUserSkills ) . not . to . be . called ;
187
199
expect ( memberCertService . registerMember ) . to . be . calledOnce ;
200
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
188
201
} ) ;
189
202
190
203
// we may need to update this test case when we want to call unregister endpoint
@@ -196,6 +209,9 @@ describe('Skill Picker Controller', function() {
196
209
expect ( mockProfile . save ) . not . to . be . called ;
197
210
expect ( profileService . updateUserSkills ) . not . to . be . called ;
198
211
expect ( memberCertService . registerMember ) . not . to . be . called ;
212
+ // we should still go to dashboard if the function is called,
213
+ // call to the function is controlled by disabling the button
214
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
199
215
} ) ;
200
216
201
217
it ( 'should NOT update communities for the member for enabled but non dirty community ' , function ( ) {
@@ -207,6 +223,9 @@ describe('Skill Picker Controller', function() {
207
223
expect ( mockProfile . save ) . not . to . be . called ;
208
224
expect ( profileService . updateUserSkills ) . not . to . be . called ;
209
225
expect ( memberCertService . registerMember ) . not . to . be . called ;
226
+ // we should still go to dashboard if the function is called,
227
+ // call to the function is controlled by disabling the button
228
+ expect ( state . go ) . to . have . been . calledWith ( 'dashboard' ) . calledOnce ;
210
229
} ) ;
211
230
212
231
it ( 'should show error popup for error in updating communities ' , function ( ) {
@@ -219,6 +238,7 @@ describe('Skill Picker Controller', function() {
219
238
expect ( profileService . updateUserSkills ) . not . to . be . called ;
220
239
expect ( memberCertService . registerMember ) . to . be . calledOnce ;
221
240
expect ( toasterSvc . pop ) . to . have . been . calledWith ( 'error' , "Whoops!" , sinon . match ( 'wrong' ) ) . calledOnce ;
241
+ expect ( state . go ) . not . to . be . called ;
222
242
} ) ;
223
243
224
244
} ) ;
0 commit comments