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

Commit 6b4dbde

Browse files
committed
Merge pull request #664 from appirio-tech/SUP-2964-tc-font-stockart-tests
Sup 2964 tc font stockart tests
2 parents b6640a7 + ec599bd commit 6b4dbde

File tree

9 files changed

+450
-49
lines changed

9 files changed

+450
-49
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
isFontSourceRequired: false
4343
};
4444

45+
// Initialize font form data
46+
$scope.formFonts = { 0: _.assign({id: 0}, angular.copy(emptyFont)) };
47+
4548
$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
4649

4750
$scope.selectFont = function(newFont) {
Lines changed: 216 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,228 @@
11
/* jshint -W117, -W030 */
22
describe('Topcoder Form Fonts Directive', function() {
3-
var scope;
4-
5-
// USE AS TEMPLATE FOR DIRECTIVES
3+
var scope, element, isolateScope;
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 form = angular.element('<form><tc-form-fonts /></form>');
11+
element = form.find('tc-form-fonts');
12+
var formElement = $compile(form)(scope);
13+
scope.$digest();
14+
15+
isolateScope = element.isolateScope();
1016
});
1117

1218
bard.verifyNoOutstandingHttpRequests();
1319

14-
xdescribe('', function() {
15-
beforeEach(function() {});
20+
describe('is initialized with', function() {
21+
it('empty font data', function() {
22+
defaultFormFont = isolateScope.formFonts[0];
23+
24+
expect(defaultFormFont.id).to.equal(0);
25+
expect(defaultFormFont.source).to.equal('');
26+
expect(defaultFormFont.name).to.equal('');
27+
expect(defaultFormFont.sourceUrl).to.equal('');
28+
expect(defaultFormFont.isFontUrlRequired).to.be.false;
29+
expect(defaultFormFont.isFontUrlDisabled).to.be.true;
30+
expect(defaultFormFont.isFontNameRequired).to.be.false;
31+
expect(defaultFormFont.isFontNameDisabled).to.be.true;
32+
expect(defaultFormFont.isFontSourceRequired).to.be.false;
33+
});
34+
35+
it('a font list', function() {
36+
var fontList = isolateScope.fontList0;
37+
38+
expect(fontList).to.be.an.array;
39+
expect(fontList).to.have.length.of.at.least(1);
40+
});
41+
42+
it('a regular expression', function() {
43+
expect(isolateScope.urlRegEx).to.be.an.instanceof(RegExp);
44+
});
45+
});
46+
47+
describe('selectFont', function() {
48+
var newFont, targetedFont;
49+
50+
beforeEach(function() {
51+
newFont = {
52+
id: 0,
53+
value: 'FONTS_DOT_COM'
54+
};
55+
56+
targetedFont = isolateScope.formFonts[0];
57+
});
58+
59+
afterEach(function() {
60+
newFont = undefined;
61+
targetedFont = undefined;
62+
});
63+
64+
it('updates the targeted font source with the new value', function() {
65+
expect(targetedFont.source).to.equal('');
66+
67+
isolateScope.selectFont(newFont);
68+
scope.$digest();
69+
70+
expect(targetedFont.source).to.equal('FONTS_DOT_COM');
71+
});
72+
73+
it('sets disabled properties to false', function() {
74+
expect(targetedFont.isFontNameDisabled).to.be.true;
75+
expect(targetedFont.isFontUrlDisabled).to.be.true;
76+
77+
isolateScope.selectFont(newFont);
78+
scope.$digest();
79+
80+
expect(targetedFont.isFontNameDisabled).to.be.false;
81+
expect(targetedFont.isFontUrlDisabled).to.be.false;
82+
});
83+
84+
it('sets required properties to true', function() {
85+
expect(targetedFont.isFontNameRequired).to.be.false;
86+
expect(targetedFont.isFontUrlRequired).to.be.false;
87+
88+
isolateScope.selectFont(newFont);
89+
scope.$digest();
90+
91+
expect(targetedFont.isFontNameRequired).to.be.true;
92+
expect(targetedFont.isFontUrlRequired).to.be.true;
93+
});
94+
95+
it('sets isFontNameRequired to true and isFontUrlRequired to false when STUDIO_STANDARD_FONTS_LIST is selected', function() {
96+
expect(targetedFont.isFontNameRequired).to.be.false;
97+
expect(targetedFont.isFontUrlRequired).to.be.false;
98+
99+
isolateScope.selectFont({id: 0, value: 'STUDIO_STANDARD_FONTS_LIST'});
100+
scope.$digest();
101+
102+
expect(targetedFont.isFontNameRequired).to.be.true;
103+
expect(targetedFont.isFontUrlRequired).to.be.false;
104+
});
105+
});
106+
107+
describe('createAdditionalFontFieldset', function() {
108+
it('creates a new fieldset', function() {
109+
expect(Object.keys(isolateScope.formFonts).length).to.equal(1);
110+
111+
isolateScope.createAdditionalFontFieldset();
112+
scope.$digest();
113+
114+
expect(Object.keys(isolateScope.formFonts).length).to.equal(2);
115+
});
116+
117+
it('adds an incremented id to the new fieldset', function() {
118+
var id = isolateScope.formFonts[0].id;
119+
120+
isolateScope.createAdditionalFontFieldset();
121+
scope.$digest();
122+
123+
expect(isolateScope.formFonts[1]).to.exist;
124+
expect(isolateScope.formFonts[1].id).to.equal(id + 1);
125+
});
126+
});
127+
128+
describe('deleteFontFieldset', function() {
129+
it('deletes the selected font fieldset', function() {
130+
isolateScope.createAdditionalFontFieldset();
131+
scope.$digest();
132+
133+
expect(Object.keys(isolateScope.formFonts).length).to.equal(2);
134+
135+
isolateScope.deleteFontFieldset(1);
136+
scope.$digest();
137+
138+
expect(Object.keys(isolateScope.formFonts).length).to.equal(1);
139+
});
140+
141+
it('resets the font fieldset when it\'s the only one', function() {
142+
var font = isolateScope.formFonts[0];
143+
144+
expect(font.source).to.equal('');
145+
146+
font.source = 'dropdown selection';
147+
scope.$digest();
148+
149+
expect(font.source).to.equal('dropdown selection');
150+
151+
isolateScope.deleteFontFieldset(0);
152+
scope.$digest();
153+
154+
expect(isolateScope.formFonts[0].source).to.equal('');
155+
});
156+
});
157+
158+
describe('isButtonDisabled', function() {
159+
var button;
160+
161+
beforeEach(function() {
162+
button = $(element).find('.fieldset__button')[0];
163+
});
164+
165+
afterEach(function() {
166+
button = undefined;
167+
});
168+
169+
it('disables the button when no fields are filled out', function() {
170+
expect(button.disabled).to.be.true;
171+
});
172+
173+
it('disables the button when 1 field is filled out', function() {
174+
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
175+
scope.$digest();
176+
177+
expect(button.disabled).to.be.true;
178+
});
179+
180+
it('disables the button when 2 fields are filled out', function() {
181+
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
182+
isolateScope.formFonts[0].sourceUrl = 'url.com';
183+
scope.$digest();
184+
185+
expect(button.disabled).to.be.true;
186+
});
187+
188+
it('enables the button when all fields are filled out', function() {
189+
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
190+
isolateScope.formFonts[0].name = 'name';
191+
isolateScope.formFonts[0].sourceUrl = 'url.com';
192+
scope.$digest();
193+
194+
expect(button.disabled).to.be.false;
195+
});
196+
197+
it('disables the button when any field in any fieldset is empty', function() {
198+
expect(button.disabled).to.be.true;
199+
200+
// Fill out first fieldset
201+
isolateScope.formFonts[0].source = 'FONTS_DOT_COM';
202+
isolateScope.formFonts[0].name = 'name';
203+
isolateScope.formFonts[0].sourceUrl = 'url.com';
204+
scope.$digest();
205+
206+
expect(button.disabled).to.be.false;
207+
208+
isolateScope.createAdditionalFontFieldset();
209+
scope.$digest();
210+
211+
expect(button.disabled).to.be.true;
212+
213+
// Fill out second fieldset
214+
isolateScope.formFonts[1].source = 'FONTS_DOT_COM2';
215+
isolateScope.formFonts[1].name = 'name';
216+
isolateScope.formFonts[1].sourceUrl = 'url2.com';
217+
scope.$digest();
218+
219+
expect(button.disabled).to.be.false;
220+
221+
// Empty a field in the first fieldset
222+
isolateScope.formFonts[0].name = '';
223+
scope.$digest();
16224

17-
it('', function() {});
225+
expect(button.disabled).to.be.true;
226+
});
18227
});
19228
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
isFileNumberRequired: false
2727
};
2828

29+
// Initialize stockart form data
30+
$scope.formStockarts = { 0: _.assign({id: 0}, angular.copy(emptyStockart)) };
31+
2932
$scope.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/);
3033

3134
$scope.createAdditionalStockartFieldset = function() {

0 commit comments

Comments
 (0)