1
1
/* jshint -W117, -W030 */
2
2
describe ( 'Submit File Controller' , function ( ) {
3
- var controller ;
4
- var vm ;
5
- var scope ;
3
+ var controller , vm , scope ;
6
4
7
5
var mockChallenge = {
8
6
challenge : {
@@ -12,14 +10,18 @@ describe('Submit File Controller', function() {
12
10
}
13
11
} ;
14
12
15
- userService = {
13
+ var userService = {
16
14
getUserIdentity : function ( ) {
17
15
return {
18
16
userId : 123456
19
17
} ;
20
18
}
21
19
} ;
22
20
21
+ var submissionsService = {
22
+ getPresignedURL : function ( ) { }
23
+ } ;
24
+
23
25
beforeEach ( function ( ) {
24
26
bard . appModule ( 'tc.submissions' ) ;
25
27
bard . inject ( this , '$controller' , '$rootScope' ) ;
@@ -33,7 +35,8 @@ describe('Submit File Controller', function() {
33
35
controller = $controller ( 'SubmitFileController' , {
34
36
$scope : scope ,
35
37
UserService : userService ,
36
- challengeToSubmitTo : mockChallenge
38
+ challengeToSubmitTo : mockChallenge ,
39
+ SubmissionsService : submissionsService
37
40
} ) ;
38
41
vm = controller ;
39
42
} ) ;
@@ -42,9 +45,235 @@ describe('Submit File Controller', function() {
42
45
expect ( vm ) . to . exist ;
43
46
} ) ;
44
47
45
- describe ( 'updateProgress ' , function ( ) {
46
- it ( 'should update PREPARE phase end ' , function ( ) {
47
-
48
+ describe ( 'setRankTo1' , function ( ) {
49
+ it ( 'returns 1 if the input is blank' , function ( ) {
50
+ expect ( vm . setRankTo1 ( '' ) ) . to . equal ( 1 ) ;
51
+ } ) ;
52
+
53
+ it ( 'returns the input value if not blank' , function ( ) {
54
+ var inputText = 'sample input text' ;
55
+ var result = vm . setRankTo1 ( inputText ) ;
56
+
57
+ expect ( result ) . to . equal ( inputText ) ;
58
+ } ) ;
59
+ } ) ;
60
+
61
+
62
+ describe ( 'setFileReference' , function ( ) {
63
+ var file , fieldId ;
64
+
65
+ beforeEach ( function ( ) {
66
+ file = {
67
+ name : 'Dashboard 2.png' ,
68
+ size : 575548 ,
69
+ type : 'image/png'
70
+ } ;
71
+ fieldId = 'DESIGN_COVER' ;
72
+
73
+ vm . setFileReference ( file , fieldId ) ;
74
+ scope . $digest ( ) ;
75
+ } ) ;
76
+
77
+ afterEach ( function ( ) {
78
+ file = undefined ;
79
+ fieldId = undefined ;
80
+ } ) ;
81
+
82
+ it ( 'adds a file object to the submissions body' , function ( ) {
83
+ expect ( vm . submissionsBody . data . files ) . to . have . length ( 1 ) ;
84
+ } ) ;
85
+
86
+ it ( 'replaces a file object with a new one if it has the same fieldId' , function ( ) {
87
+ expect ( vm . submissionsBody . data . files ) . to . have . length ( 1 ) ;
88
+
89
+ var newFile = {
90
+ name : 'different_image.png' ,
91
+ size : 4321 ,
92
+ type : 'image/png'
93
+ } ;
94
+
95
+ vm . setFileReference ( newFile , fieldId ) ;
96
+ scope . $digest ( ) ;
97
+
98
+ expect ( vm . submissionsBody . data . files ) . to . have . length ( 1 ) ;
99
+ expect ( vm . submissionsBody . data . files [ 0 ] . name ) . to . equal ( 'different_image.png' ) ;
100
+ } ) ;
101
+
102
+ it ( 'sets the correct mediaTypes on the fileObject' , function ( ) {
103
+ expect ( vm . submissionsBody . data . files [ 0 ] . mediaType ) . to . equal ( 'image/png' ) ;
104
+
105
+ var newFile = {
106
+ name : 'submission.zip' ,
107
+ size : 43121 ,
108
+ type : 'application/zip'
109
+ } ;
110
+ var newFieldId = 'SUBMISSION_ZIP' ;
111
+
112
+ vm . setFileReference ( newFile , newFieldId ) ;
113
+ scope . $digest ( ) ;
114
+
115
+ expect ( vm . submissionsBody . data . files [ 1 ] . mediaType ) . to . equal ( 'application/octet-stream' ) ;
116
+
117
+ var newFile2 = {
118
+ name : 'source.zip' ,
119
+ size : 2314 ,
120
+ type : 'application/zip'
121
+ } ;
122
+ var newFieldId2 = 'SOURCE_ZIP' ;
123
+
124
+ vm . setFileReference ( newFile2 , newFieldId2 ) ;
125
+ scope . $digest ( ) ;
126
+
127
+ expect ( vm . submissionsBody . data . files [ 2 ] . mediaType ) . to . equal ( 'application/octet-stream' ) ;
128
+ } ) ;
129
+ } ) ;
130
+
131
+ describe ( 'uploadSubmission' , function ( ) {
132
+ it ( 'adds comments to the submissions body' , function ( ) {
133
+ vm . comments = 'test comments' ;
134
+ scope . $digest ( ) ;
135
+
136
+ vm . uploadSubmission ( ) ;
137
+ scope . $digest ( ) ;
138
+
139
+ expect ( vm . submissionsBody . data . submitterComments ) . to . equal ( 'test comments' ) ;
140
+ } ) ;
141
+
142
+ it ( 'adds the rank to the submissions body' , function ( ) {
143
+ vm . submissionForm . submitterRank = 3 ;
144
+ scope . $digest ( ) ;
145
+
146
+ vm . uploadSubmission ( ) ;
147
+ scope . $digest ( ) ;
148
+
149
+ expect ( vm . submissionsBody . data . submitterRank ) . to . equal ( 3 ) ;
150
+ } ) ;
151
+
152
+ it ( 'calls the submission service' , function ( ) {
153
+ var mockAPICall = sinon . spy ( submissionsService , 'getPresignedURL' ) ;
154
+
155
+ vm . uploadSubmission ( ) ;
156
+ scope . $digest ( ) ;
157
+
158
+ expect ( mockAPICall ) . calledOnce ;
159
+ } ) ;
160
+
161
+ describe ( 'processes the stockart and' , function ( ) {
162
+ it ( 'returns an empty array if no stockart given' , function ( ) {
163
+ vm . formStockarts = [ ] ;
164
+ scope . $digest ( ) ;
165
+
166
+ vm . uploadSubmission ( ) ;
167
+ scope . $digest ( ) ;
168
+
169
+ expect ( vm . submissionsBody . data . stockArts ) . to . deep . equal ( [ ] ) ;
170
+ } ) ;
171
+
172
+ it ( 'removes the required properties and id from each stockart' , function ( ) {
173
+ vm . formStockarts = [
174
+ {
175
+ id : 0 ,
176
+ description : 'first stockart' ,
177
+ sourceUrl : 'url.com' ,
178
+ fileNumber : '123' ,
179
+ isPhotoDescriptionRequired : false ,
180
+ isPhotoURLRequired : false ,
181
+ isFileNumberRequired : false
182
+ } ,
183
+ {
184
+ id : 1 ,
185
+ description : 'second stockart' ,
186
+ sourceUrl : 'url2.com' ,
187
+ fileNumber : '234' ,
188
+ isPhotoDescriptionRequired : false ,
189
+ isPhotoURLRequired : false ,
190
+ isFileNumberRequired : false
191
+ }
192
+ ] ;
193
+ var processedStockart = [
194
+ {
195
+ description : 'first stockart' ,
196
+ sourceUrl : 'url.com' ,
197
+ fileNumber : '123' ,
198
+ } ,
199
+ {
200
+ description : 'second stockart' ,
201
+ sourceUrl : 'url2.com' ,
202
+ fileNumber : '234' ,
203
+ }
204
+ ] ;
205
+ scope . $digest ( ) ;
206
+
207
+ vm . uploadSubmission ( ) ;
208
+ scope . $digest ( ) ;
209
+ expect ( vm . submissionsBody . data . stockArts ) . to . deep . equal ( processedStockart ) ;
210
+
211
+ } ) ;
212
+ } ) ;
213
+ describe ( 'processes the fonts and' , function ( ) {
214
+ it ( 'returns an empty array if no fonts given' , function ( ) {
215
+ vm . formFonts = [ ] ;
216
+ scope . $digest ( ) ;
217
+
218
+ vm . uploadSubmission ( ) ;
219
+ scope . $digest ( ) ;
220
+
221
+ expect ( vm . submissionsBody . data . fonts ) . to . deep . equal ( [ ] ) ;
222
+ } ) ;
223
+
224
+ it ( 'removes the required properties and id from each font' , function ( ) {
225
+ vm . formFonts = [
226
+ {
227
+ id : 0 ,
228
+ source : 'STUDIO_STANDARD_FONTS_LIST' ,
229
+ name : 'my font' ,
230
+ isFontUrlRequired : false ,
231
+ isFontUrlDisabled : true ,
232
+ isFontNameRequired : false ,
233
+ isFontNameDisabled : true ,
234
+ isFontSourceRequired : false
235
+ } ,
236
+ {
237
+ id : 1 ,
238
+ source : 'FONTS_DOT_COM' ,
239
+ name : 'my other font' ,
240
+ sourceUrl : 'fontsource.com' ,
241
+ isFontUrlRequired : false ,
242
+ isFontUrlDisabled : true ,
243
+ isFontNameRequired : false ,
244
+ isFontNameDisabled : true ,
245
+ isFontSourceRequired : false
246
+ }
247
+ ] ;
248
+ var processedFonts = [
249
+ {
250
+ source : 'STUDIO_STANDARD_FONTS_LIST' ,
251
+ name : 'my font' ,
252
+ } ,
253
+ {
254
+ source : 'FONTS_DOT_COM' ,
255
+ name : 'my other font' ,
256
+ sourceUrl : 'fontsource.com' ,
257
+ }
258
+ ] ;
259
+ scope . $digest ( ) ;
260
+
261
+ vm . uploadSubmission ( ) ;
262
+ scope . $digest ( ) ;
263
+ expect ( vm . submissionsBody . data . fonts ) . to . deep . equal ( processedFonts ) ;
264
+ } ) ;
265
+ } ) ;
266
+ } ) ;
267
+
268
+ describe ( 'cancelRetry' , function ( ) {
269
+ it ( 'sets showProgress to false' , function ( ) {
270
+ vm . showProgress = true ;
271
+ scope . $digest ( ) ;
272
+ expect ( vm . showProgress ) . to . be . true ;
273
+
274
+ vm . cancelRetry ( ) ;
275
+ scope . $digest ( ) ;
276
+ expect ( vm . showProgress ) . to . be . false ;
48
277
} ) ;
49
278
} ) ;
50
279
} ) ;
0 commit comments