|
1 | 1 | /* jshint -W117, -W030 */
|
2 | 2 | describe('Topcoder Form Stockart Directive', function() {
|
3 |
| - var scope; |
4 |
| - |
5 |
| - // USE AS TEMPLATE FOR DIRECTIVES |
| 3 | + var scope, element, isolateScope; |
6 | 4 |
|
7 | 5 | beforeEach(function() {
|
8 |
| - bard.appModule('tcUIComponents'); |
| 6 | + bard.appModule('topcoder'); |
9 | 7 | bard.inject(this, '$compile', '$rootScope');
|
| 8 | + scope = $rootScope.$new(); |
| 9 | + |
| 10 | + var form = angular.element('<form><tc-form-stockart /></form>'); |
| 11 | + element = form.find('tc-form-stockart'); |
| 12 | + var formElement = $compile(form)(scope); |
| 13 | + scope.$digest(); |
| 14 | + |
| 15 | + isolateScope = element.isolateScope(); |
10 | 16 | });
|
11 | 17 |
|
12 | 18 | bard.verifyNoOutstandingHttpRequests();
|
13 | 19 |
|
14 |
| - xdescribe('', function() { |
15 |
| - beforeEach(function() {}); |
| 20 | + it('starts with empty stockart data', function() { |
| 21 | + defaultFormStockart = isolateScope.formStockarts[0]; |
| 22 | + |
| 23 | + expect(defaultFormStockart.id).to.equal(0); |
| 24 | + expect(defaultFormStockart.description).to.equal(''); |
| 25 | + expect(defaultFormStockart.sourceUrl).to.equal(''); |
| 26 | + expect(defaultFormStockart.fileNumber).to.equal(''); |
| 27 | + expect(defaultFormStockart.isPhotoDescriptionRequired).to.equal(false); |
| 28 | + expect(defaultFormStockart.isPhotoURLRequired).to.equal(false); |
| 29 | + expect(defaultFormStockart.isFileNumberRequired).to.equal(false); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('createAdditionalStockartFieldset', function() { |
| 33 | + it('creates a new fieldset', function() { |
| 34 | + expect(Object.keys(isolateScope.formStockarts).length).to.equal(1); |
| 35 | + |
| 36 | + isolateScope.createAdditionalStockartFieldset(); |
| 37 | + scope.$digest(); |
| 38 | + |
| 39 | + expect(Object.keys(isolateScope.formStockarts).length).to.equal(2); |
| 40 | + }); |
| 41 | + |
| 42 | + it('adds an incremented id to the new fieldset', function() { |
| 43 | + var id = isolateScope.formStockarts[0].id; |
| 44 | + |
| 45 | + isolateScope.createAdditionalStockartFieldset(); |
| 46 | + scope.$digest(); |
| 47 | + |
| 48 | + expect(isolateScope.formStockarts[1]).to.exist; |
| 49 | + expect(isolateScope.formStockarts[1].id).to.equal(id + 1); |
| 50 | + }); |
| 51 | + }) |
| 52 | + |
| 53 | + describe('deleteStockartFieldset', function() { |
| 54 | + it('deletes the selected stockart fieldset', function() { |
| 55 | + isolateScope.createAdditionalStockartFieldset(); |
| 56 | + scope.$digest(); |
| 57 | + |
| 58 | + expect(Object.keys(isolateScope.formStockarts).length).to.equal(2); |
| 59 | + |
| 60 | + isolateScope.deleteStockartFieldset(1); |
| 61 | + scope.$digest(); |
| 62 | + |
| 63 | + expect(Object.keys(isolateScope.formStockarts).length).to.equal(1); |
| 64 | + }); |
| 65 | + |
| 66 | + it('resets the stockart fieldset when it\'s the only one', function() { |
| 67 | + var stockart = isolateScope.formStockarts[0]; |
| 68 | + |
| 69 | + expect(stockart.description).to.equal(''); |
| 70 | + |
| 71 | + stockart.description = 'a funny cat picture'; |
| 72 | + scope.$digest(); |
| 73 | + |
| 74 | + expect(stockart.description).to.equal('a funny cat picture'); |
| 75 | + |
| 76 | + isolateScope.deleteStockartFieldset(0); |
| 77 | + scope.$digest(); |
| 78 | + |
| 79 | + expect(isolateScope.formStockarts[0].description).to.equal(''); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('isButtonDisabled', function() { |
| 84 | + var button; |
| 85 | + |
| 86 | + beforeEach(function() { |
| 87 | + button = $(element).find('.fieldset__button')[0]; |
| 88 | + }); |
| 89 | + |
| 90 | + afterEach(function() { |
| 91 | + button = undefined; |
| 92 | + }); |
| 93 | + |
| 94 | + it('disables the button when no fields are filled out', function() { |
| 95 | + expect(button.disabled).to.be.true; |
| 96 | + }); |
| 97 | + |
| 98 | + it('disables the button when 1 field is filled out', function() { |
| 99 | + isolateScope.formStockarts[0].description = 'test description'; |
| 100 | + scope.$digest(); |
| 101 | + |
| 102 | + expect(button.disabled).to.be.true; |
| 103 | + }); |
| 104 | + |
| 105 | + it('disables the button when 2 fields are filled out', function() { |
| 106 | + isolateScope.formStockarts[0].description = 'test description'; |
| 107 | + isolateScope.formStockarts[0].sourceUrl = 'url'; |
| 108 | + scope.$digest(); |
| 109 | + |
| 110 | + expect(button.disabled).to.be.true; |
| 111 | + }); |
| 112 | + |
| 113 | + it('enables the button when all fields are filled out', function() { |
| 114 | + isolateScope.formStockarts[0].description = 'test description'; |
| 115 | + isolateScope.formStockarts[0].sourceUrl = 'url'; |
| 116 | + isolateScope.formStockarts[0].fileNumber = '123'; |
| 117 | + scope.$digest(); |
| 118 | + |
| 119 | + expect(button.disabled).to.be.false; |
| 120 | + }); |
| 121 | + |
| 122 | + it('disables the button when any field in any fieldset is empty', function() { |
| 123 | + expect(button.disabled).to.be.true; |
| 124 | + |
| 125 | + // Fill out first fieldset |
| 126 | + isolateScope.formStockarts[0].description = 'test description'; |
| 127 | + isolateScope.formStockarts[0].sourceUrl = 'url.com'; |
| 128 | + isolateScope.formStockarts[0].fileNumber = '123'; |
| 129 | + scope.$digest(); |
| 130 | + |
| 131 | + expect(button.disabled).to.be.false; |
| 132 | + |
| 133 | + isolateScope.createAdditionalStockartFieldset(); |
| 134 | + scope.$digest(); |
| 135 | + |
| 136 | + expect(button.disabled).to.be.true; |
| 137 | + |
| 138 | + // Fill out second fieldset |
| 139 | + isolateScope.formStockarts[1].description = 'test description2'; |
| 140 | + isolateScope.formStockarts[1].sourceUrl = 'url2.com'; |
| 141 | + isolateScope.formStockarts[1].fileNumber = '1232'; |
| 142 | + scope.$digest(); |
| 143 | + |
| 144 | + expect(button.disabled).to.be.false; |
| 145 | + |
| 146 | + // Empty a field in the first fieldset |
| 147 | + isolateScope.formStockarts[0].fileNumber = ''; |
| 148 | + scope.$digest(); |
| 149 | + |
| 150 | + expect(button.disabled).to.be.true; |
| 151 | + }); |
| 152 | + }) |
| 153 | + |
| 154 | + describe('showMandatoryMessage', function() { |
| 155 | + describe('sets the stockart required properties to false when all fields are', function() { |
| 156 | + var stockart; |
| 157 | + |
| 158 | + beforeEach(function() { |
| 159 | + stockart = isolateScope.formStockarts[0]; |
| 160 | + stockart.description = 'test description'; |
| 161 | + stockart.sourceUrl = 'url.com'; |
| 162 | + stockart.fileNumber = '123'; |
| 163 | + scope.$digest(); |
| 164 | + }); |
| 165 | + |
| 166 | + afterEach(function() { |
| 167 | + stockart = undefined; |
| 168 | + }); |
| 169 | + |
| 170 | + it('filled out', function() { |
| 171 | + expect(stockart.isPhotoDescriptionRequired).to.be.false; |
| 172 | + expect(stockart.isPhotoURLRequired).to.be.false; |
| 173 | + expect(stockart.isFileNumberRequired).to.be.false; |
| 174 | + }); |
| 175 | + |
| 176 | + it('empty', function() { |
| 177 | + // Reset stockart fields |
| 178 | + stockart.description = ''; |
| 179 | + stockart.sourceUrl = ''; |
| 180 | + stockart.fileNumber = ''; |
| 181 | + scope.$digest(); |
| 182 | + |
| 183 | + expect(stockart.isPhotoDescriptionRequired).to.be.false; |
| 184 | + expect(stockart.isPhotoURLRequired).to.be.false; |
| 185 | + expect(stockart.isFileNumberRequired).to.be.false; |
| 186 | + }); |
| 187 | + }); |
| 188 | + |
| 189 | + |
| 190 | + describe('sets the stockart required properties to false when all fields are', function() { |
| 191 | + var stockart; |
| 192 | + |
| 193 | + beforeEach(function() { |
| 194 | + stockart = isolateScope.formStockarts[0]; |
| 195 | + stockart.description = 'test description'; |
| 196 | + stockart.sourceUrl = 'url.com'; |
| 197 | + stockart.fileNumber = '123'; |
| 198 | + scope.$digest(); |
| 199 | + }); |
| 200 | + |
| 201 | + afterEach(function() { |
| 202 | + stockart = undefined; |
| 203 | + }); |
| 204 | + |
| 205 | + it('sets the stockart required properties to true if any field is blank', function() { |
| 206 | + // Reset stockart fields |
| 207 | + stockart.description = ''; |
| 208 | + scope.$digest(); |
16 | 209 |
|
17 |
| - it('', function() {}); |
| 210 | + expect(stockart.isPhotoDescriptionRequired).to.be.true; |
| 211 | + expect(stockart.isPhotoURLRequired).to.be.true; |
| 212 | + expect(stockart.isFileNumberRequired).to.be.true; |
| 213 | + }); |
| 214 | + }); |
18 | 215 | });
|
19 | 216 | });
|
0 commit comments