diff --git a/app/specs.html b/app/specs.html
index eb19c8329..07ae65a8d 100644
--- a/app/specs.html
+++ b/app/specs.html
@@ -70,6 +70,8 @@
+
+
@@ -270,7 +272,6 @@
-
@@ -281,13 +282,14 @@
+
-
+
@@ -296,9 +298,9 @@
-
+
@@ -312,8 +314,8 @@
-
+
diff --git a/app/submissions/submissions.spec.js b/app/submissions/submissions.spec.js
index 983dd7669..d37f5fce4 100644
--- a/app/submissions/submissions.spec.js
+++ b/app/submissions/submissions.spec.js
@@ -1,7 +1,6 @@
/* jshint -W117, -W030 */
describe('Submissions Controller', function() {
- var controller;
- var vm;
+ var controller, vm;
var mockChallenge = {
challenge: {
@@ -28,4 +27,10 @@ describe('Submissions Controller', function() {
it('should exist', function() {
expect(vm).to.exist;
});
+
+ it('should have properties on vm from the routes resolve', function() {
+ expect(vm.challengeTitle).to.equal(mockChallenge.challenge.name);
+ expect(vm.challengeId).to.equal(30049240);
+ expect(vm.track).to.equal(mockChallenge.challenge.track.toLowerCase());
+ });
});
diff --git a/app/submissions/submit-file/submit-file.controller.js b/app/submissions/submit-file/submit-file.controller.js
index cfb8606bd..4eaf1c356 100644
--- a/app/submissions/submit-file/submit-file.controller.js
+++ b/app/submissions/submit-file/submit-file.controller.js
@@ -99,17 +99,20 @@
fileObject.mediaType = file.type;
}
- // If user picks a new file, replace the that file's fileObject with a new one
- // Or add it the list if it's not there
- if (vm.submissionsBody.data.files.length) {
- vm.submissionsBody.data.files.some(function(file, i, filesArray) {
- if (file.type === fileObject.type) {
- file = fileObject;
- } else if (filesArray.length === i + 1) {
- filesArray.push(fileObject);
- }
- });
- } else {
+ // If user changes a file input's file, update the file details
+ var isFound = vm.submissionsBody.data.files.reduce(function(isFound, file, i, filesArray) {
+ if (isFound) { return true; }
+
+ if (file.type === fileObject.type) {
+ filesArray[i] = fileObject;
+ return true;
+ }
+
+ return false;
+ }, false);
+
+ // Add new files to the list
+ if (!isFound) {
vm.submissionsBody.data.files.push(fileObject);
}
}
diff --git a/app/submissions/submit-file/submit-file.spec.js b/app/submissions/submit-file/submit-file.spec.js
index d24961aca..acff67737 100644
--- a/app/submissions/submit-file/submit-file.spec.js
+++ b/app/submissions/submit-file/submit-file.spec.js
@@ -1,8 +1,6 @@
/* jshint -W117, -W030 */
describe('Submit File Controller', function() {
- var controller;
- var vm;
- var scope;
+ var controller, vm, scope;
var mockChallenge = {
challenge: {
@@ -12,7 +10,7 @@ describe('Submit File Controller', function() {
}
};
- userService = {
+ var userService = {
getUserIdentity: function() {
return {
userId: 123456
@@ -20,6 +18,10 @@ describe('Submit File Controller', function() {
}
};
+ var submissionsService = {
+ getPresignedURL: function() {}
+ };
+
beforeEach(function() {
bard.appModule('tc.submissions');
bard.inject(this, '$controller', '$rootScope');
@@ -33,7 +35,8 @@ describe('Submit File Controller', function() {
controller = $controller('SubmitFileController', {
$scope: scope,
UserService: userService,
- challengeToSubmitTo: mockChallenge
+ challengeToSubmitTo: mockChallenge,
+ SubmissionsService: submissionsService
});
vm = controller;
});
@@ -42,9 +45,235 @@ describe('Submit File Controller', function() {
expect(vm).to.exist;
});
- describe('updateProgress ', function() {
- it('should update PREPARE phase end ', function() {
-
+ describe('setRankTo1', function() {
+ it('returns 1 if the input is blank', function() {
+ expect(vm.setRankTo1('')).to.equal(1);
+ });
+
+ it('returns the input value if not blank', function() {
+ var inputText = 'sample input text';
+ var result = vm.setRankTo1(inputText);
+
+ expect(result).to.equal(inputText);
+ });
+ });
+
+
+ describe('setFileReference', function() {
+ var file, fieldId;
+
+ beforeEach(function() {
+ file = {
+ name: 'Dashboard 2.png',
+ size: 575548,
+ type: 'image/png'
+ };
+ fieldId = 'DESIGN_COVER';
+
+ vm.setFileReference(file, fieldId);
+ scope.$digest();
+ });
+
+ afterEach(function() {
+ file = undefined;
+ fieldId = undefined;
+ });
+
+ it('adds a file object to the submissions body', function() {
+ expect(vm.submissionsBody.data.files).to.have.length(1);
+ });
+
+ it('replaces a file object with a new one if it has the same fieldId', function() {
+ expect(vm.submissionsBody.data.files).to.have.length(1);
+
+ var newFile = {
+ name: 'different_image.png',
+ size: 4321,
+ type: 'image/png'
+ };
+
+ vm.setFileReference(newFile, fieldId);
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.files).to.have.length(1);
+ expect(vm.submissionsBody.data.files[0].name).to.equal('different_image.png');
+ });
+
+ it('sets the correct mediaTypes on the fileObject', function() {
+ expect(vm.submissionsBody.data.files[0].mediaType).to.equal('image/png');
+
+ var newFile = {
+ name: 'submission.zip',
+ size: 43121,
+ type: 'application/zip'
+ };
+ var newFieldId = 'SUBMISSION_ZIP';
+
+ vm.setFileReference(newFile, newFieldId);
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.files[1].mediaType).to.equal('application/octet-stream');
+
+ var newFile2 = {
+ name: 'source.zip',
+ size: 2314,
+ type: 'application/zip'
+ };
+ var newFieldId2 = 'SOURCE_ZIP';
+
+ vm.setFileReference(newFile2, newFieldId2);
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.files[2].mediaType).to.equal('application/octet-stream');
+ });
+ });
+
+ describe('uploadSubmission', function() {
+ it('adds comments to the submissions body', function() {
+ vm.comments = 'test comments';
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.submitterComments).to.equal('test comments');
+ });
+
+ it('adds the rank to the submissions body', function() {
+ vm.submissionForm.submitterRank = 3;
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.submitterRank).to.equal(3);
+ });
+
+ it('calls the submission service', function() {
+ var mockAPICall = sinon.spy(submissionsService, 'getPresignedURL');
+
+ vm.uploadSubmission();
+ scope.$digest();
+
+ expect(mockAPICall).calledOnce;
+ });
+
+ describe('processes the stockart and', function() {
+ it('returns an empty array if no stockart given', function() {
+ vm.formStockarts = [];
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.stockArts).to.deep.equal([]);
+ });
+
+ it('removes the required properties and id from each stockart', function() {
+ vm.formStockarts = [
+ {
+ id: 0,
+ description: 'first stockart',
+ sourceUrl: 'url.com',
+ fileNumber: '123',
+ isPhotoDescriptionRequired: false,
+ isPhotoURLRequired: false,
+ isFileNumberRequired: false
+ },
+ {
+ id: 1,
+ description: 'second stockart',
+ sourceUrl: 'url2.com',
+ fileNumber: '234',
+ isPhotoDescriptionRequired: false,
+ isPhotoURLRequired: false,
+ isFileNumberRequired: false
+ }
+ ];
+ var processedStockart = [
+ {
+ description: 'first stockart',
+ sourceUrl: 'url.com',
+ fileNumber: '123',
+ },
+ {
+ description: 'second stockart',
+ sourceUrl: 'url2.com',
+ fileNumber: '234',
+ }
+ ];
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+ expect(vm.submissionsBody.data.stockArts).to.deep.equal(processedStockart);
+
+ });
+ });
+ describe('processes the fonts and', function() {
+ it('returns an empty array if no fonts given', function() {
+ vm.formFonts = [];
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+
+ expect(vm.submissionsBody.data.fonts).to.deep.equal([]);
+ });
+
+ it('removes the required properties and id from each font', function() {
+ vm.formFonts = [
+ {
+ id: 0,
+ source: 'STUDIO_STANDARD_FONTS_LIST',
+ name: 'my font',
+ isFontUrlRequired: false,
+ isFontUrlDisabled: true,
+ isFontNameRequired: false,
+ isFontNameDisabled: true,
+ isFontSourceRequired: false
+ },
+ {
+ id: 1,
+ source: 'FONTS_DOT_COM',
+ name: 'my other font',
+ sourceUrl: 'fontsource.com',
+ isFontUrlRequired: false,
+ isFontUrlDisabled: true,
+ isFontNameRequired: false,
+ isFontNameDisabled: true,
+ isFontSourceRequired: false
+ }
+ ];
+ var processedFonts = [
+ {
+ source: 'STUDIO_STANDARD_FONTS_LIST',
+ name: 'my font',
+ },
+ {
+ source: 'FONTS_DOT_COM',
+ name: 'my other font',
+ sourceUrl: 'fontsource.com',
+ }
+ ];
+ scope.$digest();
+
+ vm.uploadSubmission();
+ scope.$digest();
+ expect(vm.submissionsBody.data.fonts).to.deep.equal(processedFonts);
+ });
+ });
+ });
+
+ describe('cancelRetry', function() {
+ it('sets showProgress to false', function() {
+ vm.showProgress = true;
+ scope.$digest();
+ expect(vm.showProgress).to.be.true;
+
+ vm.cancelRetry();
+ scope.$digest();
+ expect(vm.showProgress).to.be.false;
});
});
});