Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit de82801

Browse files
author
Nick Litwin
committedFeb 4, 2016
Add tests for windows and ie changes
1 parent d91116e commit de82801

File tree

3 files changed

+237
-198
lines changed

3 files changed

+237
-198
lines changed
 

‎app/directives/tc-file-input/tc-file-input.directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import _ from 'lodash'
2828

2929
// Add extra checks for Windows zip file types
3030
var hasZip = _.some(fileTypes, _.matches('zip'))
31+
3132
if (hasZip) {
3233
fileTypes = angular.copy(fileTypes)
3334
fileTypes.push('x-zip', 'x-zip-compressed')
Lines changed: 113 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,186 @@
1+
import angular from 'angular'
2+
13
/* jshint -W117, -W030 */
24
describe('Topcoder File Input Directive', function() {
3-
var scope, element, isolateScope, fileInput;
5+
var scope, element, isolateScope, fileInput
46

57
beforeEach(function() {
6-
bard.appModule('topcoder');
7-
bard.inject(this, '$compile', '$rootScope');
8-
scope = $rootScope.$new();
8+
bard.appModule('topcoder')
9+
bard.inject(this, '$compile', '$rootScope', '$timeout')
10+
scope = $rootScope.$new()
911

1012
var html = '' +
1113
'<form>' +
1214
'<tc-file-input ' +
13-
'label-text="Preview Image"' +
14-
'field-id="DESIGN_COVER"' +
15+
'label-text="Submission"' +
16+
'field-id="SUBMISSION_ZIP"' +
1517
'button-text="Add File"' +
16-
'file-type="jpg,jpeg,png"' +
17-
'placeholder="Image file as .jpg or .png"' +
18+
'file-type="zip"' +
19+
'placeholder="Attach all visible files as a single .zip file"' +
1820
'mandatory="true"' +
1921
'set-file-reference="vm.setFileReference(file, fieldId)"' +
2022
'ng-model="vm.submissionForm.submissionZip"' +
2123
' />' +
22-
'</form>';
23-
var form = angular.element(html);
24-
element = form.find('tc-file-input');
25-
var formElement = $compile(form)(scope);
26-
scope.$digest();
24+
'</form>'
25+
var form = angular.element(html)
26+
element = form.find('tc-file-input')
27+
var formElement = $compile(form)(scope)
28+
scope.$digest()
2729

28-
isolateScope = element.isolateScope();
29-
});
30+
isolateScope = element.isolateScope()
31+
})
3032

3133
beforeEach(function() {
32-
fileInput = $(element).find('.none')[0];
33-
});
34+
fileInput = $(element).find('.none')[0]
35+
})
3436

3537
afterEach(function() {
36-
scope.$destroy();
37-
fileInput = undefined;
38-
});
38+
scope.$destroy()
39+
fileInput = undefined
40+
})
3941

40-
bard.verifyNoOutstandingHttpRequests();
42+
bard.verifyNoOutstandingHttpRequests()
4143

4244
describe('selectFile', function() {
4345
it('triggers a click on the file input', function() {
44-
var mockClick = sinon.spy(fileInput, 'click');
46+
var mockClick = sinon.spy(fileInput, 'click')
4547

46-
isolateScope.selectFile();
47-
scope.$digest();
48+
isolateScope.selectFile()
49+
scope.$digest()
4850

49-
expect(mockClick).calledOnce;
50-
});
51-
});
51+
expect(mockClick).calledOnce
52+
})
53+
})
5254

5355
describe('a change event on the file input', function() {
54-
var fileNameInput, fileList, mockSetFileReference;
56+
var fileNameInput, fileList, mockSetFileReference
5557

5658
beforeEach(function() {
57-
fileNameInput = $(element).find('input[type=text]')[0];
59+
fileNameInput = $(element).find('input[type=text]')[0]
5860
fileList = {
5961
0: {
60-
name: 'test.png',
62+
name: 'test.zip',
6163
size: 50,
62-
type: 'image/png'
64+
type: 'application/zip'
6365
},
6466
length: 1,
65-
item: function (index) { return file; }
66-
};
67+
item: function (index) { return file }
68+
}
6769

68-
mockSetFileReference = sinon.spy(isolateScope, 'setFileReference');
69-
});
70+
mockSetFileReference = sinon.spy(isolateScope, 'setFileReference')
71+
})
7072

7173
afterEach(function() {
72-
fileNameInput = undefined;
73-
fileList = undefined;
74-
mockSetFileReference = undefined;
75-
});
74+
fileNameInput = undefined
75+
fileList = undefined
76+
mockSetFileReference = undefined
77+
})
7678

7779
it('sets the value of the fileNameInput with the name of the file', function() {
7880
$(fileInput).triggerHandler({
7981
type: 'change',
8082
target: { files: fileList }
81-
});
83+
})
84+
85+
$timeout.flush()
8286

83-
expect(fileNameInput.value).to.equal('test.png');
84-
});
87+
expect(fileNameInput.value).to.equal('test.zip')
88+
})
8589

8690
describe('with a valid file', function() {
8791
beforeEach(function() {
8892
$(fileInput).triggerHandler({
8993
type: 'change',
9094
target: { files: fileList }
91-
});
92-
});
95+
})
96+
$timeout.flush()
97+
})
9398

9499
it('calls setFileReference', function() {
95-
expect(mockSetFileReference).calledOnce;
96-
});
100+
expect(mockSetFileReference).calledOnce
101+
})
97102

98103
it('has ng-valid-filesize class', function() {
99-
expect($(fileInput).hasClass('ng-valid-filesize')).to.be.true;
100-
});
104+
expect($(fileInput).hasClass('ng-valid-filesize')).to.be.true
105+
})
101106

102107
it('has ng-valid-required class', function() {
103-
expect($(fileInput).hasClass('ng-valid-required')).to.be.true;
104-
});
105-
});
108+
expect($(fileInput).hasClass('ng-valid-required')).to.be.true
109+
})
106110

107-
describe('with a file that\'s greater than 500MB', function() {
108-
beforeEach(function() {
109-
fileList[0].size = 500000001;
111+
it('works with Windows file type application/x-zip', function(){
112+
fileList[0].type = 'application/x-zip'
110113

111114
$(fileInput).triggerHandler({
112115
type: 'change',
113116
target: { files: fileList }
114-
});
115-
});
117+
})
116118

117-
it('does not call setFileReference', function() {
118-
expect(mockSetFileReference).not.calledOnce;
119-
});
119+
$timeout.flush()
120120

121-
it('has ng-touched and ng-invalid-filesize classes', function() {
122-
expect($(fileInput).hasClass('ng-invalid-filesize')).to.be.true;
123-
expect($(fileInput).hasClass('ng-touched')).to.be.true;
124-
});
125-
});
121+
expect(mockSetFileReference).called
122+
expect($(fileInput).hasClass('ng-valid-filesize')).to.be.true
123+
expect($(fileInput).hasClass('ng-valid-required')).to.be.true
124+
})
125+
126+
it('works with Windows file type application/x-zip-compressed', function(){
127+
fileList[0].type = 'application/x-zip-compressed'
128+
129+
$(fileInput).triggerHandler({
130+
type: 'change',
131+
target: { files: fileList }
132+
})
133+
134+
$timeout.flush()
135+
136+
expect(mockSetFileReference).called
137+
expect($(fileInput).hasClass('ng-valid-filesize')).to.be.true
138+
expect($(fileInput).hasClass('ng-valid-required')).to.be.true
139+
})
140+
})
126141

127142
describe('with a file type that\'s not in the list of fileTypes given to the directive', function() {
128143
beforeEach(function() {
129-
fileList[0].type = 'application/zip';
144+
fileList[0].type = 'image/png'
130145

131146
$(fileInput).triggerHandler({
132147
type: 'change',
133148
target: { files: fileList }
134-
});
135-
});
149+
})
150+
151+
$timeout.flush()
152+
})
136153

137154
it('does not call setFileReference', function() {
138-
expect(mockSetFileReference).not.calledOnce;
139-
});
155+
expect(mockSetFileReference).not.calledOnce
156+
})
140157

141158
it('has ng-touched and ng-invalid-required classes', function() {
142-
expect($(fileInput).hasClass('ng-invalid-required')).to.be.true;
143-
expect($(fileInput).hasClass('ng-touched')).to.be.true;
144-
});
145-
});
159+
expect($(fileInput).hasClass('ng-invalid-required')).to.be.true
160+
expect($(fileInput).hasClass('ng-touched')).to.be.true
161+
})
162+
})
163+
164+
describe('with a file that\'s greater than 500MB', function() {
165+
beforeEach(function() {
166+
fileList[0].size = 500000001
167+
168+
$(fileInput).triggerHandler({
169+
type: 'change',
170+
target: { files: fileList }
171+
})
172+
173+
$timeout.flush()
174+
})
146175

147-
});
148-
});
176+
it('does not call setFileReference', function() {
177+
expect(mockSetFileReference).not.calledOnce
178+
})
179+
180+
it('has ng-touched and ng-invalid-filesize classes', function() {
181+
expect($(fileInput).hasClass('ng-invalid-filesize')).to.be.true
182+
expect($(fileInput).hasClass('ng-touched')).to.be.true
183+
})
184+
})
185+
})
186+
})
Lines changed: 123 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
/* jshint -W117, -W030 */
22
describe('Submit Design Files Controller', function() {
3-
var controller, vm, scope;
3+
var controller, vm, scope
44

55
var mockChallenge = {
66
challenge: {
77
name: 'Challenge Name',
88
track: 'DESIGN',
99
id: 30049240
1010
}
11-
};
11+
}
1212

1313
var userService = {
1414
getUserIdentity: function() {
1515
return {
1616
userId: 123456
17-
};
17+
}
1818
}
19-
};
19+
}
2020

2121
var submissionsService = {
2222
getPresignedURL: function() {}
23-
};
23+
}
2424

2525
var mockWindow = {
2626
location: {
27-
reload: function(val) { return val; }
27+
reload: function(val) { return val }
2828
}
29-
};
29+
}
3030

3131
beforeEach(function() {
32-
bard.appModule('tc.submissions');
33-
bard.inject(this, '$controller', '$rootScope');
32+
bard.appModule('tc.submissions')
33+
bard.inject(this, '$controller', '$rootScope')
3434

35-
scope = $rootScope.$new();
36-
});
35+
scope = $rootScope.$new()
36+
})
3737

38-
bard.verifyNoOutstandingHttpRequests();
38+
bard.verifyNoOutstandingHttpRequests()
3939

4040
beforeEach(function() {
4141
controller = $controller('SubmitDesignFilesController', {
@@ -44,13 +44,13 @@ describe('Submit Design Files Controller', function() {
4444
challengeToSubmitTo: mockChallenge,
4545
SubmissionsService: submissionsService,
4646
$window: mockWindow
47-
});
48-
vm = controller;
49-
});
47+
})
48+
vm = controller
49+
})
5050

5151
it('exists', function() {
52-
expect(vm).to.exist;
53-
});
52+
expect(vm).to.exist
53+
})
5454

5555
it('sets the right track for the method', function() {
5656
controller = $controller('SubmitDesignFilesController', {
@@ -65,136 +65,136 @@ describe('Submit Design Files Controller', function() {
6565
},
6666
SubmissionsService: submissionsService,
6767
$window: mockWindow
68-
});
69-
vm = controller;
70-
scope.$digest();
68+
})
69+
vm = controller
70+
scope.$digest()
7171

72-
expect(vm.submissionsBody.data.method).to.equal('DEVELOP_CHALLENGE_ZIP_FILE');
73-
});
72+
expect(vm.submissionsBody.data.method).to.equal('DEVELOP_CHALLENGE_ZIP_FILE')
73+
})
7474

7575
describe('setRankTo1', function() {
7676
it('returns 1 if the input is blank', function() {
77-
expect(vm.setRankTo1('')).to.equal(1);
78-
});
77+
expect(vm.setRankTo1('')).to.equal(1)
78+
})
7979

8080
it('returns the input value if not blank', function() {
81-
var inputText = 'sample input text';
82-
var result = vm.setRankTo1(inputText);
81+
var inputText = 'sample input text'
82+
var result = vm.setRankTo1(inputText)
8383

84-
expect(result).to.equal(inputText);
85-
});
86-
});
84+
expect(result).to.equal(inputText)
85+
})
86+
})
8787

8888

8989
describe('setFileReference', function() {
90-
var file, fieldId;
90+
var file, fieldId
9191

9292
beforeEach(function() {
9393
file = {
9494
name: 'Dashboard 2.png',
9595
size: 575548,
9696
type: 'image/png'
97-
};
98-
fieldId = 'DESIGN_COVER';
97+
}
98+
fieldId = 'DESIGN_COVER'
9999

100-
vm.setFileReference(file, fieldId);
101-
scope.$digest();
102-
});
100+
vm.setFileReference(file, fieldId)
101+
scope.$digest()
102+
})
103103

104104
afterEach(function() {
105-
file = undefined;
106-
fieldId = undefined;
107-
});
105+
file = undefined
106+
fieldId = undefined
107+
})
108108

109109
it('adds a file object to the submissions body', function() {
110-
expect(vm.submissionsBody.data.files).to.have.length(1);
111-
});
110+
expect(vm.submissionsBody.data.files).to.have.length(1)
111+
})
112112

113113
it('replaces a file object with a new one if it has the same fieldId', function() {
114-
expect(vm.submissionsBody.data.files).to.have.length(1);
114+
expect(vm.submissionsBody.data.files).to.have.length(1)
115115

116116
var newFile = {
117117
name: 'different_image.png',
118118
size: 4321,
119119
type: 'image/png'
120-
};
120+
}
121121

122-
vm.setFileReference(newFile, fieldId);
123-
scope.$digest();
122+
vm.setFileReference(newFile, fieldId)
123+
scope.$digest()
124124

125-
expect(vm.submissionsBody.data.files).to.have.length(1);
126-
expect(vm.submissionsBody.data.files[0].name).to.equal('different_image.png');
127-
});
125+
expect(vm.submissionsBody.data.files).to.have.length(1)
126+
expect(vm.submissionsBody.data.files[0].name).to.equal('different_image.png')
127+
})
128128

129129
it('sets the correct mediaTypes on the fileObject', function() {
130-
expect(vm.submissionsBody.data.files[0].mediaType).to.equal('image/png');
130+
expect(vm.submissionsBody.data.files[0].mediaType).to.equal('image/png')
131131

132132
var newFile = {
133133
name: 'submission.zip',
134134
size: 43121,
135135
type: 'application/zip'
136-
};
137-
var newFieldId = 'SUBMISSION_ZIP';
136+
}
137+
var newFieldId = 'SUBMISSION_ZIP'
138138

139-
vm.setFileReference(newFile, newFieldId);
140-
scope.$digest();
139+
vm.setFileReference(newFile, newFieldId)
140+
scope.$digest()
141141

142-
expect(vm.submissionsBody.data.files[1].mediaType).to.equal('application/octet-stream');
142+
expect(vm.submissionsBody.data.files[1].mediaType).to.equal('application/octet-stream')
143143

144144
var newFile2 = {
145145
name: 'source.zip',
146146
size: 2314,
147147
type: 'application/zip'
148-
};
149-
var newFieldId2 = 'SOURCE_ZIP';
148+
}
149+
var newFieldId2 = 'SOURCE_ZIP'
150150

151-
vm.setFileReference(newFile2, newFieldId2);
152-
scope.$digest();
151+
vm.setFileReference(newFile2, newFieldId2)
152+
scope.$digest()
153153

154-
expect(vm.submissionsBody.data.files[2].mediaType).to.equal('application/octet-stream');
155-
});
156-
});
154+
expect(vm.submissionsBody.data.files[2].mediaType).to.equal('application/octet-stream')
155+
})
156+
})
157157

158158
describe('uploadSubmission', function() {
159159
it('adds comments to the submissions body', function() {
160-
vm.comments = 'test comments';
161-
scope.$digest();
160+
vm.comments = 'test comments'
161+
scope.$digest()
162162

163-
vm.uploadSubmission();
164-
scope.$digest();
163+
vm.uploadSubmission()
164+
scope.$digest()
165165

166-
expect(vm.submissionsBody.data.submitterComments).to.equal('test comments');
167-
});
166+
expect(vm.submissionsBody.data.submitterComments).to.equal('test comments')
167+
})
168168

169169
it('adds the rank to the submissions body', function() {
170-
vm.submissionForm.submitterRank = 3;
171-
scope.$digest();
170+
vm.submissionForm.submitterRank = 3
171+
scope.$digest()
172172

173-
vm.uploadSubmission();
174-
scope.$digest();
173+
vm.uploadSubmission()
174+
scope.$digest()
175175

176-
expect(vm.submissionsBody.data.submitterRank).to.equal(3);
177-
});
176+
expect(vm.submissionsBody.data.submitterRank).to.equal(3)
177+
})
178178

179179
it('calls the submission service', function() {
180-
var mockAPICall = sinon.spy(submissionsService, 'getPresignedURL');
180+
var mockAPICall = sinon.spy(submissionsService, 'getPresignedURL')
181181

182-
vm.uploadSubmission();
183-
scope.$digest();
182+
vm.uploadSubmission()
183+
scope.$digest()
184184

185-
expect(mockAPICall).calledOnce;
186-
});
185+
expect(mockAPICall).calledOnce
186+
})
187187

188188
describe('processes the stockart and', function() {
189189
it('returns an empty array if no stockart given', function() {
190-
vm.formStockarts = [];
191-
scope.$digest();
190+
vm.formStockarts = []
191+
scope.$digest()
192192

193-
vm.uploadSubmission();
194-
scope.$digest();
193+
vm.uploadSubmission()
194+
scope.$digest()
195195

196-
expect(vm.submissionsBody.data.stockArts).to.deep.equal([]);
197-
});
196+
expect(vm.submissionsBody.data.stockArts).to.deep.equal([])
197+
})
198198

199199
it('removes the required properties and id from each stockart', function() {
200200
vm.formStockarts = [
@@ -216,7 +216,7 @@ describe('Submit Design Files Controller', function() {
216216
isPhotoURLRequired: false,
217217
isFileNumberRequired: false
218218
}
219-
];
219+
]
220220
var processedStockart = [
221221
{
222222
description: 'first stockart',
@@ -228,25 +228,25 @@ describe('Submit Design Files Controller', function() {
228228
sourceUrl: 'url2.com',
229229
fileNumber: '234',
230230
}
231-
];
232-
scope.$digest();
231+
]
232+
scope.$digest()
233233

234-
vm.uploadSubmission();
235-
scope.$digest();
236-
expect(vm.submissionsBody.data.stockArts).to.deep.equal(processedStockart);
234+
vm.uploadSubmission()
235+
scope.$digest()
236+
expect(vm.submissionsBody.data.stockArts).to.deep.equal(processedStockart)
237237

238-
});
239-
});
238+
})
239+
})
240240
describe('processes the fonts and', function() {
241241
it('returns an empty array if no fonts given', function() {
242-
vm.formFonts = [];
243-
scope.$digest();
242+
vm.formFonts = []
243+
scope.$digest()
244244

245-
vm.uploadSubmission();
246-
scope.$digest();
245+
vm.uploadSubmission()
246+
scope.$digest()
247247

248-
expect(vm.submissionsBody.data.fonts).to.deep.equal([]);
249-
});
248+
expect(vm.submissionsBody.data.fonts).to.deep.equal([])
249+
})
250250

251251
it('removes the required properties and id from each font', function() {
252252
vm.formFonts = [
@@ -271,7 +271,7 @@ describe('Submit Design Files Controller', function() {
271271
isFontNameDisabled: true,
272272
isFontSourceRequired: false
273273
}
274-
];
274+
]
275275
var processedFonts = [
276276
{
277277
source: 'STUDIO_STANDARD_FONTS_LIST',
@@ -282,37 +282,37 @@ describe('Submit Design Files Controller', function() {
282282
name: 'my other font',
283283
sourceUrl: 'fontsource.com',
284284
}
285-
];
286-
scope.$digest();
285+
]
286+
scope.$digest()
287287

288-
vm.uploadSubmission();
289-
scope.$digest();
290-
expect(vm.submissionsBody.data.fonts).to.deep.equal(processedFonts);
291-
});
292-
});
293-
});
288+
vm.uploadSubmission()
289+
scope.$digest()
290+
expect(vm.submissionsBody.data.fonts).to.deep.equal(processedFonts)
291+
})
292+
})
293+
})
294294

295295
describe('refreshPage', function() {
296296
it('reloads the page', function() {
297-
var mockRefresh = sinon.spy(mockWindow.location, 'reload');
297+
var mockRefresh = sinon.spy(mockWindow.location, 'reload')
298298

299-
vm.refreshPage();
300-
scope.$digest();
299+
vm.refreshPage()
300+
scope.$digest()
301301

302-
expect(mockRefresh).calledWith(true);
303-
expect(mockRefresh).calledOnce;
304-
});
305-
});
302+
expect(mockRefresh).calledWith(true)
303+
expect(mockRefresh).calledOnce
304+
})
305+
})
306306

307307
describe('cancelRetry', function() {
308308
it('sets showProgress to false', function() {
309-
vm.showProgress = true;
310-
scope.$digest();
311-
expect(vm.showProgress).to.be.true;
312-
313-
vm.cancelRetry();
314-
scope.$digest();
315-
expect(vm.showProgress).to.be.false;
316-
});
317-
});
318-
});
309+
vm.showProgress = true
310+
scope.$digest()
311+
expect(vm.showProgress).to.be.true
312+
313+
vm.cancelRetry()
314+
scope.$digest()
315+
expect(vm.showProgress).to.be.false
316+
})
317+
})
318+
})

0 commit comments

Comments
 (0)
This repository has been archived.