Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 10a8504

Browse files
author
Jenkins Continuous Integration Server
committed
Merge commit '1cc0149451c1a0011063fb202744869664ca5da4' into HEAD
2 parents 26ee43d + 1cc0149 commit 10a8504

File tree

13 files changed

+792
-42
lines changed

13 files changed

+792
-42
lines changed

app/directives/badges/badge-tooltip.spec.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ describe('Badge Tooltip Directive', function() {
66
var spotlightChallenge = mockData.getMockSpotlightChallenges()[0];
77

88
beforeEach(function() {
9-
bard.appModule('tcUIComponents');
9+
bard.appModule('topcoder');
1010
bard.inject(this, '$compile', '$rootScope');
1111
scope = $rootScope.$new();
1212
});
1313

1414
bard.verifyNoOutstandingHttpRequests();
1515

16-
xdescribe('Badge Tooltip', function() {
16+
describe('Badge Tooltip', function() {
1717
var tooltip;
1818

1919
beforeEach(function() {
@@ -89,5 +89,18 @@ describe('Badge Tooltip Directive', function() {
8989
expect(dataDiv).not.to.null;
9090
expect(dataDiv.hasClass('ng-hide')).to.equal(true);
9191
});
92+
93+
it('should trigger mouseenter handler ', function() {
94+
tooltip.trigger('mouseenter');
95+
var tooltipElement = tooltip.children(0);
96+
expect(tooltipElement.css('z-index')).to.equal('2000');
97+
expect(tooltip.isolateScope().hide).to.equal(false);
98+
});
99+
100+
it('should trigger mouseleave handler ', function() {
101+
tooltip.trigger('mouseleave');
102+
tooltipElement = tooltip.children(0);
103+
expect(tooltip.isolateScope().hide).to.equal(true);
104+
});
92105
});
93106
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
var fileInput = $(element[0]).find('.none');
2929
var fileNameInput = $(element[0]).find('input[type=text]');
3030

31-
fileInput.bind('change', function() {
32-
var file = fileInput[0].files[0];
31+
fileInput.bind('change', function(event) {
32+
var file = event.target.files[0];
3333

3434
// About 1 in 20 times, the file is undefined (must be race condition)
3535
// Return early in this case so no errors are thrown
Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,148 @@
11
/* jshint -W117, -W030 */
22
describe('Topcoder File Input Directive', function() {
3-
var scope;
4-
5-
// USE AS TEMPLATE FOR DIRECTIVES
3+
var scope, element, isolateScope, fileInput;
64

75
beforeEach(function() {
8-
bard.appModule('tcUIComponents');
6+
bard.appModule('topcoder');
97
bard.inject(this, '$compile', '$rootScope');
8+
scope = $rootScope.$new();
9+
10+
var html = '' +
11+
'<form>' +
12+
'<tc-file-input ' +
13+
'label-text="Preview Image"' +
14+
'field-id="DESIGN_COVER"' +
15+
'button-text="Add File"' +
16+
'file-type="jpg,jpeg,png"' +
17+
'placeholder="Image file as .jpg or .png"' +
18+
'mandatory="true"' +
19+
'set-file-reference="vm.setFileReference(file, fieldId)"' +
20+
'ng-model="vm.submissionForm.submissionZip"' +
21+
' />' +
22+
'</form>';
23+
var form = angular.element(html);
24+
element = form.find('tc-file-input');
25+
var formElement = $compile(form)(scope);
26+
scope.$digest();
27+
28+
isolateScope = element.isolateScope();
29+
});
30+
31+
beforeEach(function() {
32+
fileInput = $(element).find('.none')[0];
33+
});
34+
35+
afterEach(function() {
36+
scope.$destroy();
37+
fileInput = undefined;
1038
});
1139

1240
bard.verifyNoOutstandingHttpRequests();
1341

14-
xdescribe('', function() {
15-
beforeEach(function() {});
42+
describe('selectFile', function() {
43+
it('triggers a click on the file input', function() {
44+
var mockClick = sinon.spy(fileInput, 'click');
45+
46+
isolateScope.selectFile();
47+
scope.$digest();
48+
49+
expect(mockClick).calledOnce;
50+
});
51+
});
52+
53+
describe('a change event on the file input', function() {
54+
var fileNameInput, fileList, mockSetFileReference;
55+
56+
beforeEach(function() {
57+
fileNameInput = $(element).find('input[type=text]')[0];
58+
fileList = {
59+
0: {
60+
name: 'test.png',
61+
size: 50,
62+
type: 'image/png'
63+
},
64+
length: 1,
65+
item: function (index) { return file; }
66+
};
67+
68+
mockSetFileReference = sinon.spy(isolateScope, 'setFileReference');
69+
});
70+
71+
afterEach(function() {
72+
fileNameInput = undefined;
73+
fileList = undefined;
74+
mockSetFileReference = undefined;
75+
});
76+
77+
it('sets the value of the fileNameInput with the name of the file', function() {
78+
$(fileInput).triggerHandler({
79+
type: 'change',
80+
target: { files: fileList }
81+
});
82+
83+
expect(fileNameInput.value).to.equal('test.png');
84+
});
85+
86+
describe('with a valid file', function() {
87+
beforeEach(function() {
88+
$(fileInput).triggerHandler({
89+
type: 'change',
90+
target: { files: fileList }
91+
});
92+
});
93+
94+
it('calls setFileReference', function() {
95+
expect(mockSetFileReference).calledOnce;
96+
});
97+
98+
it('has ng-valid-filesize class', function() {
99+
expect($(fileInput).hasClass('ng-valid-filesize')).to.be.true;
100+
});
101+
102+
it('has ng-valid-required class', function() {
103+
expect($(fileInput).hasClass('ng-valid-required')).to.be.true;
104+
});
105+
});
106+
107+
describe('with a file that\'s greater than 500MB', function() {
108+
beforeEach(function() {
109+
fileList[0].size = 500000001;
110+
111+
$(fileInput).triggerHandler({
112+
type: 'change',
113+
target: { files: fileList }
114+
});
115+
});
116+
117+
it('does not call setFileReference', function() {
118+
expect(mockSetFileReference).not.calledOnce;
119+
});
120+
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+
});
126+
127+
describe('with a file type that\'s not in the list of fileTypes given to the directive', function() {
128+
beforeEach(function() {
129+
fileList[0].type = 'application/zip';
130+
131+
$(fileInput).triggerHandler({
132+
type: 'change',
133+
target: { files: fileList }
134+
});
135+
});
136+
137+
it('does not call setFileReference', function() {
138+
expect(mockSetFileReference).not.calledOnce;
139+
});
140+
141+
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+
});
16146

17-
it('', function() {});
18147
});
19148
});

app/directives/tc-form-fonts/tc-form-fonts.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ describe('Topcoder Form Fonts Directive', function() {
1515
isolateScope = element.isolateScope();
1616
});
1717

18+
afterEach(function() {
19+
scope.$destroy();
20+
});
21+
1822
bard.verifyNoOutstandingHttpRequests();
1923

2024
describe('is initialized with', function() {

app/directives/tc-form-stockart/tc-form-stockart.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ describe('Topcoder Form Stockart Directive', function() {
1515
isolateScope = element.isolateScope();
1616
});
1717

18+
afterEach(function() {
19+
scope.$destroy();
20+
});
21+
1822
bard.verifyNoOutstandingHttpRequests();
1923

2024
describe('is initialized with', function() {

app/directives/tc-input/tc-input.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ describe('Topcoder Input Directive', function() {
1111
scope.$digest();
1212
});
1313

14+
afterEach(function() {
15+
scope.$destroy();
16+
});
17+
1418
bard.verifyNoOutstandingHttpRequests();
1519

1620
it('should set inputType to text if no inputType given', function() {

app/filters/npad.filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
if(inputStr.length >= n)
1515
return inputStr
16-
var zeros = "0".repeat(n);
16+
var zeros = new Array( n + 1 ).join("0");
1717
return (zeros + inputStr).slice(-1 * n)
1818
};
1919
}

app/services/helpers.service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
answer: '' + q.answer
157157
};
158158

159-
if (q.comment.length > 0) {
159+
if (q.comment && q.comment.length > 0) {
160160
reviewItem.comments = [
161161
{
162162
content: '' + q.comment,
@@ -234,7 +234,7 @@
234234
});
235235
// now loop over all keys and replace with compiled value
236236
Object.keys(compiledMap).forEach(function(k) {
237-
template = template.replace(k, compiledMap[k])
237+
template = template.replace(k, (compiledMap[k] ? compiledMap[k] : ''));
238238
});
239239
}
240240
return template;
@@ -298,8 +298,8 @@
298298
}
299299

300300
function setupLoginEventMetrics (usernameOrEmail) {
301-
if (_kmq) {
302-
_kmq.push(['identify', usernameOrEmail ]);
301+
if ($window._kmq) {
302+
$window._kmq.push(['identify', usernameOrEmail ]);
303303
}
304304
}
305305

0 commit comments

Comments
 (0)