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

Sup 2964 tc font stockart tests #664

Merged
merged 2 commits into from
Jan 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/directives/tc-form-fonts/tc-form-fonts.directive.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@
isFontSourceRequired: false
};

// Initialize font form data
$scope.formFonts = { 0: _.assign({id: 0}, angular.copy(emptyFont)) };

$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);

$scope.selectFont = function(newFont) {
223 changes: 216 additions & 7 deletions app/directives/tc-form-fonts/tc-form-fonts.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,228 @@
/* jshint -W117, -W030 */
describe('Topcoder Form Fonts Directive', function() {
var scope;

// USE AS TEMPLATE FOR DIRECTIVES
var scope, element, isolateScope;

beforeEach(function() {
bard.appModule('tcUIComponents');
bard.appModule('topcoder');
bard.inject(this, '$compile', '$rootScope');
scope = $rootScope.$new();

var form = angular.element('<form><tc-form-fonts /></form>');
element = form.find('tc-form-fonts');
var formElement = $compile(form)(scope);
scope.$digest();

isolateScope = element.isolateScope();
});

bard.verifyNoOutstandingHttpRequests();

xdescribe('', function() {
beforeEach(function() {});
describe('is initialized with', function() {
it('empty font data', function() {
defaultFormFont = isolateScope.formFonts[0];

expect(defaultFormFont.id).to.equal(0);
expect(defaultFormFont.source).to.equal('');
expect(defaultFormFont.name).to.equal('');
expect(defaultFormFont.sourceUrl).to.equal('');
expect(defaultFormFont.isFontUrlRequired).to.be.false;
expect(defaultFormFont.isFontUrlDisabled).to.be.true;
expect(defaultFormFont.isFontNameRequired).to.be.false;
expect(defaultFormFont.isFontNameDisabled).to.be.true;
expect(defaultFormFont.isFontSourceRequired).to.be.false;
});

it('a font list', function() {
var fontList = isolateScope.fontList0;

expect(fontList).to.be.an.array;
expect(fontList).to.have.length.of.at.least(1);
});

it('a regular expression', function() {
expect(isolateScope.urlRegEx).to.be.an.instanceof(RegExp);
});
});

describe('selectFont', function() {
var newFont, targetedFont;

beforeEach(function() {
newFont = {
id: 0,
value: 'FONTS_DOT_COM'
};

targetedFont = isolateScope.formFonts[0];
});

afterEach(function() {
newFont = undefined;
targetedFont = undefined;
});

it('updates the targeted font source with the new value', function() {
expect(targetedFont.source).to.equal('');

isolateScope.selectFont(newFont);
scope.$digest();

expect(targetedFont.source).to.equal('FONTS_DOT_COM');
});

it('sets disabled properties to false', function() {
expect(targetedFont.isFontNameDisabled).to.be.true;
expect(targetedFont.isFontUrlDisabled).to.be.true;

isolateScope.selectFont(newFont);
scope.$digest();

expect(targetedFont.isFontNameDisabled).to.be.false;
expect(targetedFont.isFontUrlDisabled).to.be.false;
});

it('sets required properties to true', function() {
expect(targetedFont.isFontNameRequired).to.be.false;
expect(targetedFont.isFontUrlRequired).to.be.false;

isolateScope.selectFont(newFont);
scope.$digest();

expect(targetedFont.isFontNameRequired).to.be.true;
expect(targetedFont.isFontUrlRequired).to.be.true;
});

it('sets isFontNameRequired to true and isFontUrlRequired to false when STUDIO_STANDARD_FONTS_LIST is selected', function() {
expect(targetedFont.isFontNameRequired).to.be.false;
expect(targetedFont.isFontUrlRequired).to.be.false;

isolateScope.selectFont({id: 0, value: 'STUDIO_STANDARD_FONTS_LIST'});
scope.$digest();

expect(targetedFont.isFontNameRequired).to.be.true;
expect(targetedFont.isFontUrlRequired).to.be.false;
});
});

describe('createAdditionalFontFieldset', function() {
it('creates a new fieldset', function() {
expect(Object.keys(isolateScope.formFonts).length).to.equal(1);

isolateScope.createAdditionalFontFieldset();
scope.$digest();

expect(Object.keys(isolateScope.formFonts).length).to.equal(2);
});

it('adds an incremented id to the new fieldset', function() {
var id = isolateScope.formFonts[0].id;

isolateScope.createAdditionalFontFieldset();
scope.$digest();

expect(isolateScope.formFonts[1]).to.exist;
expect(isolateScope.formFonts[1].id).to.equal(id + 1);
});
});

describe('deleteFontFieldset', function() {
it('deletes the selected font fieldset', function() {
isolateScope.createAdditionalFontFieldset();
scope.$digest();

expect(Object.keys(isolateScope.formFonts).length).to.equal(2);

isolateScope.deleteFontFieldset(1);
scope.$digest();

expect(Object.keys(isolateScope.formFonts).length).to.equal(1);
});

it('resets the font fieldset when it\'s the only one', function() {
var font = isolateScope.formFonts[0];

expect(font.source).to.equal('');

font.source = 'dropdown selection';
scope.$digest();

expect(font.source).to.equal('dropdown selection');

isolateScope.deleteFontFieldset(0);
scope.$digest();

expect(isolateScope.formFonts[0].source).to.equal('');
});
});

describe('isButtonDisabled', function() {
var button;

beforeEach(function() {
button = $(element).find('.fieldset__button')[0];
});

afterEach(function() {
button = undefined;
});

it('disables the button when no fields are filled out', function() {
expect(button.disabled).to.be.true;
});

it('disables the button when 1 field is filled out', function() {
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
scope.$digest();

expect(button.disabled).to.be.true;
});

it('disables the button when 2 fields are filled out', function() {
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
isolateScope.formFonts[0].sourceUrl = 'url.com';
scope.$digest();

expect(button.disabled).to.be.true;
});

it('enables the button when all fields are filled out', function() {
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
isolateScope.formFonts[0].name = 'name';
isolateScope.formFonts[0].sourceUrl = 'url.com';
scope.$digest();

expect(button.disabled).to.be.false;
});

it('disables the button when any field in any fieldset is empty', function() {
expect(button.disabled).to.be.true;

// Fill out first fieldset
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
isolateScope.formFonts[0].name = 'name';
isolateScope.formFonts[0].sourceUrl = 'url.com';
scope.$digest();

expect(button.disabled).to.be.false;

isolateScope.createAdditionalFontFieldset();
scope.$digest();

expect(button.disabled).to.be.true;

// Fill out second fieldset
isolateScope.formFonts[1].source = 'FONTS_DOT_COM2';
isolateScope.formFonts[1].name = 'name';
isolateScope.formFonts[1].sourceUrl = 'url2.com';
scope.$digest();

expect(button.disabled).to.be.false;

// Empty a field in the first fieldset
isolateScope.formFonts[0].name = '';
scope.$digest();

it('', function() {});
expect(button.disabled).to.be.true;
});
});
});
3 changes: 3 additions & 0 deletions app/directives/tc-form-stockart/tc-form-stockart.directive.js
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@
isFileNumberRequired: false
};

// Initialize stockart form data
$scope.formStockarts = { 0: _.assign({id: 0}, angular.copy(emptyStockart)) };

$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);

$scope.createAdditionalStockartFieldset = function() {
217 changes: 210 additions & 7 deletions app/directives/tc-form-stockart/tc-form-stockart.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,222 @@
/* jshint -W117, -W030 */
describe('Topcoder Form Stockart Directive', function() {
var scope;

// USE AS TEMPLATE FOR DIRECTIVES
var scope, element, isolateScope;

beforeEach(function() {
bard.appModule('tcUIComponents');
bard.appModule('topcoder');
bard.inject(this, '$compile', '$rootScope');
scope = $rootScope.$new();

var form = angular.element('<form><tc-form-stockart /></form>');
element = form.find('tc-form-stockart');
var formElement = $compile(form)(scope);
scope.$digest();

isolateScope = element.isolateScope();
});

bard.verifyNoOutstandingHttpRequests();

xdescribe('', function() {
beforeEach(function() {});
describe('is initialized with', function() {
it('empty stockart data', function() {
var initialStockart = isolateScope.formStockarts[0];

expect(initialStockart.id).to.equal(0);
expect(initialStockart.description).to.equal('');
expect(initialStockart.sourceUrl).to.equal('');
expect(initialStockart.fileNumber).to.equal('');
expect(initialStockart.isPhotoDescriptionRequired).to.equal(false);
expect(initialStockart.isPhotoURLRequired).to.equal(false);
expect(initialStockart.isFileNumberRequired).to.equal(false);
});

it('a regular expression', function() {
expect(isolateScope.urlRegEx).to.be.an.instanceof(RegExp);
});
});

describe('createAdditionalStockartFieldset', function() {
it('creates a new fieldset', function() {
expect(Object.keys(isolateScope.formStockarts).length).to.equal(1);

isolateScope.createAdditionalStockartFieldset();
scope.$digest();

expect(Object.keys(isolateScope.formStockarts).length).to.equal(2);
});

it('adds an incremented id to the new fieldset', function() {
var id = isolateScope.formStockarts[0].id;

isolateScope.createAdditionalStockartFieldset();
scope.$digest();

expect(isolateScope.formStockarts[1]).to.exist;
expect(isolateScope.formStockarts[1].id).to.equal(id + 1);
});
})

describe('deleteStockartFieldset', function() {
it('deletes the selected stockart fieldset', function() {
isolateScope.createAdditionalStockartFieldset();
scope.$digest();

expect(Object.keys(isolateScope.formStockarts).length).to.equal(2);

isolateScope.deleteStockartFieldset(1);
scope.$digest();

expect(Object.keys(isolateScope.formStockarts).length).to.equal(1);
});

it('resets the stockart fieldset when it\'s the only one', function() {
var stockart = isolateScope.formStockarts[0];

expect(stockart.description).to.equal('');

stockart.description = 'a funny cat picture';
scope.$digest();

expect(stockart.description).to.equal('a funny cat picture');

isolateScope.deleteStockartFieldset(0);
scope.$digest();

expect(isolateScope.formStockarts[0].description).to.equal('');
});
});

describe('isButtonDisabled', function() {
var button;

beforeEach(function() {
button = $(element).find('.fieldset__button')[0];
});

afterEach(function() {
button = undefined;
});

it('disables the button when no fields are filled out', function() {
expect(button.disabled).to.be.true;
});

it('disables the button when 1 field is filled out', function() {
isolateScope.formStockarts[0].description = 'test description';
scope.$digest();

expect(button.disabled).to.be.true;
});

it('disables the button when 2 fields are filled out', function() {
isolateScope.formStockarts[0].description = 'test description';
isolateScope.formStockarts[0].sourceUrl = 'url';
scope.$digest();

expect(button.disabled).to.be.true;
});

it('enables the button when all fields are filled out', function() {
isolateScope.formStockarts[0].description = 'test description';
isolateScope.formStockarts[0].sourceUrl = 'url';
isolateScope.formStockarts[0].fileNumber = '123';
scope.$digest();

expect(button.disabled).to.be.false;
});

it('disables the button when any field in any fieldset is empty', function() {
expect(button.disabled).to.be.true;

// Fill out first fieldset
isolateScope.formStockarts[0].description = 'test description';
isolateScope.formStockarts[0].sourceUrl = 'url.com';
isolateScope.formStockarts[0].fileNumber = '123';
scope.$digest();

expect(button.disabled).to.be.false;

isolateScope.createAdditionalStockartFieldset();
scope.$digest();

expect(button.disabled).to.be.true;

// Fill out second fieldset
isolateScope.formStockarts[1].description = 'test description2';
isolateScope.formStockarts[1].sourceUrl = 'url2.com';
isolateScope.formStockarts[1].fileNumber = '1232';
scope.$digest();

expect(button.disabled).to.be.false;

// Empty a field in the first fieldset
isolateScope.formStockarts[0].fileNumber = '';
scope.$digest();

expect(button.disabled).to.be.true;
});
});

describe('showMandatoryMessage', function() {
describe('sets the stockart required properties to false when all fields are', function() {
var stockart;

beforeEach(function() {
stockart = isolateScope.formStockarts[0];
stockart.description = 'test description';
stockart.sourceUrl = 'url.com';
stockart.fileNumber = '123';
scope.$digest();
});

afterEach(function() {
stockart = undefined;
});

it('filled out', function() {
expect(stockart.isPhotoDescriptionRequired).to.be.false;
expect(stockart.isPhotoURLRequired).to.be.false;
expect(stockart.isFileNumberRequired).to.be.false;
});

it('empty', function() {
// Reset stockart fields
stockart.description = '';
stockart.sourceUrl = '';
stockart.fileNumber = '';
scope.$digest();

expect(stockart.isPhotoDescriptionRequired).to.be.false;
expect(stockart.isPhotoURLRequired).to.be.false;
expect(stockart.isFileNumberRequired).to.be.false;
});
});


describe('sets the stockart required properties to false when all fields are', function() {
var stockart;

beforeEach(function() {
stockart = isolateScope.formStockarts[0];
stockart.description = 'test description';
stockart.sourceUrl = 'url.com';
stockart.fileNumber = '123';
scope.$digest();
});

afterEach(function() {
stockart = undefined;
});

it('sets the stockart required properties to true if any field is blank', function() {
// Reset stockart fields
stockart.description = '';
scope.$digest();

it('', function() {});
expect(stockart.isPhotoDescriptionRequired).to.be.true;
expect(stockart.isPhotoURLRequired).to.be.true;
expect(stockart.isFileNumberRequired).to.be.true;
});
});
});
});
2 changes: 1 addition & 1 deletion app/directives/tc-input/tc-input.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* jshint -W117, -W030 */
describe('Topcoder Input Directive', function() {
var scope, element, controller;
var scope, element;

beforeEach(function() {
bard.appModule('topcoder');
1 change: 0 additions & 1 deletion app/filters/filters.spec.js
Original file line number Diff line number Diff line change
@@ -131,7 +131,6 @@ describe('filters', function() {
expect(ternaryFilter(true, 1, 2)).to.be.equal(1);
expect(ternaryFilter(false, 1, 2)).to.be.equal(2);
expect(ternaryFilter(0, 1, 2)).to.be.equal(2);
console.log(jstz.determine().name());
expect(ternaryFilter(true, 'm', 'n')).to.be.equal('m');
});
});
2 changes: 0 additions & 2 deletions app/index.jade
Original file line number Diff line number Diff line change
@@ -156,8 +156,6 @@ html
script(src='../bower_components/react/react.js')
script(src='../bower_components/react/react-dom.js')
script(src='../bower_components/classnames/index.js')
script(src='../bower_components/classnames/bind.js')
script(src='../bower_components/classnames/dedupe.js')
script(src='../bower_components/react-input-autosize/dist/react-input-autosize.min.js')
script(src='../bower_components/react-select/dist/react-select.min.js')
script(src='../bower_components/ngReact/ngReact.js')
7 changes: 3 additions & 4 deletions app/specs.html
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ <h1><a href="specs.html">Spec Runner</a></h1>
</script>

<!-- bower:js -->
<script src="../bower_components/zepto/zepto.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/a0-angular-storage/dist/angular-storage.js"></script>
<script src="../bower_components/angucomplete-alt/angucomplete-alt.js"></script>
@@ -69,8 +70,6 @@ <h1><a href="specs.html">Spec Runner</a></h1>
<script src="../bower_components/react/react.js"></script>
<script src="../bower_components/react/react-dom.js"></script>
<script src="../bower_components/classnames/index.js"></script>
<script src="../bower_components/classnames/bind.js"></script>
<script src="../bower_components/classnames/dedupe.js"></script>
<script src="../bower_components/react-input-autosize/dist/react-input-autosize.min.js"></script>
<script src="../bower_components/react-select/dist/react-select.min.js"></script>
<script src="../bower_components/ngReact/ngReact.js"></script>
@@ -268,8 +267,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
<script src="/app/topcoder.interceptors.spec.js"></script>
<script src="/app/filters/filters.spec.js"></script>
<script src="/app/my-challenges/my-challenges.spec.js"></script>
<script src="/app/my-srms/my-srms.spec.js"></script>
<script src="/app/my-dashboard/my-dashboard.spec.js"></script>
<script src="/app/my-srms/my-srms.spec.js"></script>
<script src="/app/profile/profile.controller.spec.js"></script>
<script src="/app/services/authToken.service.spec.js"></script>
<script src="/app/services/challenge.service.spec.js"></script>
@@ -285,8 +284,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
<script src="/app/skill-picker/skill-picker.spec.js"></script>
<script src="/app/submissions/submissions.spec.js"></script>
<script src="/app/account/login/login.spec.js"></script>
<script src="/app/account/logout/logout.controller.spec.js"></script>
<script src="/app/account/register/register.spec.js"></script>
<script src="/app/account/logout/logout.controller.spec.js"></script>
<script src="/app/account/reset-password/reset-password.spec.js"></script>
<script src="/app/blocks/exception/exception-handler.provider.spec.js"></script>
<script src="/app/directives/badges/badge-tooltip.spec.js"></script>
41 changes: 14 additions & 27 deletions app/submissions/submit-file/submit-file.controller.js
Original file line number Diff line number Diff line change
@@ -19,30 +19,8 @@
vm.finishing = false;
vm.showProgress = false;
vm.errorInUpload = false;
vm.formFonts = {
0: {
id: 0,
source: '',
name: '',
sourceUrl: '',
isFontUrlRequired: false,
isFontUrlDisabled: true,
isFontNameRequired: false,
isFontNameDisabled: true,
isFontSourceRequired: false
}
};
vm.formStockarts = {
0: {
id: 1,
description: '',
sourceUrl: '',
fileNumber: '',
isPhotoDescriptionRequired: false,
isPhotoURLRequired: false,
isFileNumberRequired: false
}
};
vm.formFonts = {};
vm.formStockarts = {};
vm.submissionForm = {
files: [],

@@ -148,10 +126,18 @@
vm.submissionsBody.data.submitterRank = vm.submissionForm.submitterRank;

// Process stock art
var processedStockarts = _.map(vm.formStockarts, function(formStockart) {
var processedStockarts = _.reduce(vm.formStockarts, function(compiledStockarts, formStockart) {
if (formStockart.description) {
delete formStockart.id;
return formStockart;
});
delete formStockart.isPhotoDescriptionRequired;
delete formStockart.isPhotoURLRequired;
delete formStockart.isFileNumberRequired;

compiledStockarts.push(formStockart);
}

return compiledStockarts;
}, []);

vm.submissionsBody.data.stockArts = processedStockarts;

@@ -164,6 +150,7 @@
delete formFont.isFontNameRequired;
delete formFont.isFontNameDisabled;
delete formFont.isFontSourceRequired;

compiledFonts.push(formFont);
}