diff --git a/app/directives/tc-form-fonts/tc-form-fonts.directive.js b/app/directives/tc-form-fonts/tc-form-fonts.directive.js index 2b08d47fd..9b097a24e 100644 --- a/app/directives/tc-form-fonts/tc-form-fonts.directive.js +++ b/app/directives/tc-form-fonts/tc-form-fonts.directive.js @@ -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) { diff --git a/app/directives/tc-form-fonts/tc-form-fonts.spec.js b/app/directives/tc-form-fonts/tc-form-fonts.spec.js index 5c17c2df7..8f0c5de95 100644 --- a/app/directives/tc-form-fonts/tc-form-fonts.spec.js +++ b/app/directives/tc-form-fonts/tc-form-fonts.spec.js @@ -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('
'); + 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; + }); }); }); diff --git a/app/directives/tc-form-stockart/tc-form-stockart.directive.js b/app/directives/tc-form-stockart/tc-form-stockart.directive.js index c5c3fca12..c2ae46bdb 100644 --- a/app/directives/tc-form-stockart/tc-form-stockart.directive.js +++ b/app/directives/tc-form-stockart/tc-form-stockart.directive.js @@ -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() { diff --git a/app/directives/tc-form-stockart/tc-form-stockart.spec.js b/app/directives/tc-form-stockart/tc-form-stockart.spec.js index fe821738a..ccdf6d1c6 100644 --- a/app/directives/tc-form-stockart/tc-form-stockart.spec.js +++ b/app/directives/tc-form-stockart/tc-form-stockart.spec.js @@ -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(''); + 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; + }); + }); }); }); diff --git a/app/directives/tc-input/tc-input.spec.js b/app/directives/tc-input/tc-input.spec.js index 83a80e6a7..56e369efe 100644 --- a/app/directives/tc-input/tc-input.spec.js +++ b/app/directives/tc-input/tc-input.spec.js @@ -1,6 +1,6 @@ /* jshint -W117, -W030 */ describe('Topcoder Input Directive', function() { - var scope, element, controller; + var scope, element; beforeEach(function() { bard.appModule('topcoder'); diff --git a/app/filters/filters.spec.js b/app/filters/filters.spec.js index fc6a6d662..b3e2c9fc9 100644 --- a/app/filters/filters.spec.js +++ b/app/filters/filters.spec.js @@ -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'); }); }); diff --git a/app/index.jade b/app/index.jade index c9ac97625..5354bf8a4 100644 --- a/app/index.jade +++ b/app/index.jade @@ -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') diff --git a/app/specs.html b/app/specs.html index caf9389a9..1c1199ee6 100644 --- a/app/specs.html +++ b/app/specs.html @@ -44,6 +44,7 @@