Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cb6305a

Browse files
committed
More testing.
1 parent 46a0a59 commit cb6305a

File tree

1 file changed

+78
-108
lines changed

1 file changed

+78
-108
lines changed

test/ng/directive/ngIdSpec.js

+78-108
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ describe('ngId', function() {
1010
it('should add new and remove old ids dynamically', inject(function($rootScope, $compile) {
1111
element = $compile('<div id="existing" ng-id="dynId"></div>')($rootScope);
1212

13-
expect(element.attr('id') === 'existing').toBe(true);
13+
expect(element.attr('id') === 'existing').toBeTruthy();
1414

1515
$rootScope.dynId = 'A';
1616
$rootScope.$digest();
17-
expect(element.attr('id') === 'existing').toBe(false);
18-
expect(element.attr('id') === 'A').toBe(true);
17+
expect(element.attr('id') === 'existing').toBeFalsy();
18+
expect(element.attr('id') === 'A').toBeTruthy();
1919

2020
$rootScope.dynId = 'B';
2121
$rootScope.$digest();
22-
expect(element.attr('id') === 'existing').toBe(false);
23-
expect(element.attr('id') === 'A').toBe(false);
24-
expect(element.attr('id') === 'B').toBe(true);
22+
expect(element.attr('id') === 'existing').toBeFalsy();
23+
expect(element.attr('id') === 'A').toBeFalsy();
24+
expect(element.attr('id') === 'B').toBeTruthy();
2525

2626
delete $rootScope.dynId;
2727
$rootScope.$digest();
28-
expect(element.attr('id') === 'existing').toBe(true);
29-
expect(element.attr('id') === 'A').toBe(false);
30-
expect(element.attr('id') === 'B').toBe(false);
28+
expect(element.attr('id') === 'existing').toBeTruthy();
29+
expect(element.attr('id') === 'A').toBeFalsy();
30+
expect(element.attr('id') === 'B').toBeFalsy();
3131
}));
3232

3333

3434
it('should support not support ids via an array', inject(function($rootScope, $compile) {
3535
element = $compile('<div id="existing" ng-id="[\'A\', \'B\']"></div>')($rootScope);
3636
$rootScope.$digest();
37-
expect(element.attr('id') === 'existing').toBe(true);
38-
expect(element.attr('id') === 'A').toBe(false);
39-
expect(element.attr('id') === 'B').toBe(false);
37+
expect(element.attr('id') === 'existing').toBeTruthy();
38+
expect(element.attr('id') === 'A').toBeFalsy();
39+
expect(element.attr('id') === 'B').toBeFalsy();
4040
}));
4141

4242

@@ -48,8 +48,8 @@ describe('ngId', function() {
4848
'</div>')($rootScope);
4949
$rootScope.conditionA = true;
5050
$rootScope.$digest();
51-
expect(element.attr('id') === 'existing').toBeFalsy;
52-
expect(element.attr('id') === 'A').toBeTruthy;
51+
expect(element.attr('id') === 'existing').toBeFalsy();
52+
expect(element.attr('id') === 'A').toBeTruthy();
5353
expect(element.attr('id') === 'B').toBeFalsy();
5454
expect(element.attr('id') === 'AnotB').toBeFalsy();
5555

@@ -84,85 +84,55 @@ describe('ngId', function() {
8484
}));
8585

8686

87-
// it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) {
88-
// element = $compile('<div class="existing" ng-class="\'A B\'"></div>')($rootScope);
89-
// $rootScope.$digest();
90-
// expect(element.hasClass('existing')).toBeTruthy();
91-
// expect(element.hasClass('A')).toBeTruthy();
92-
// expect(element.hasClass('B')).toBeTruthy();
93-
// }));
94-
95-
96-
// it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) {
97-
// element = $compile('<div class="existing" ng-class="dynClass"></div>')($rootScope);
98-
// $rootScope.dynClass = 'A';
99-
// $rootScope.$digest();
100-
// expect(element.hasClass('existing')).toBe(true);
101-
102-
// // add extra class, change model and eval
103-
// element.addClass('newClass');
104-
// $rootScope.dynClass = 'B';
105-
// $rootScope.$digest();
106-
107-
// expect(element.hasClass('existing')).toBe(true);
108-
// expect(element.hasClass('B')).toBe(true);
109-
// expect(element.hasClass('newClass')).toBe(true);
110-
// }));
111-
112-
113-
// it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) {
114-
// element = $compile('<div ng-class="dynClass"></div>')($rootScope);
115-
// $rootScope.dynClass = 'A';
116-
// $rootScope.$digest();
117-
// expect(element.hasClass('A')).toBe(true);
118-
119-
// // add extra class, change model and eval
120-
// element.addClass('newClass');
121-
// $rootScope.dynClass = 'B';
122-
// $rootScope.$digest();
123-
124-
// expect(element.hasClass('B')).toBe(true);
125-
// expect(element.hasClass('newClass')).toBe(true);
126-
// }));
87+
it('should return only the first word in a space delimited string', inject(function($rootScope, $compile) {
88+
element = $compile('<div id="existing" ng-id="\'A B\'"></div>')($rootScope);
89+
$rootScope.$digest();
90+
expect(element.attr('id') === 'existing').toBeFalsy();
91+
expect(element.attr('id') === 'A').toBeTruthy();
92+
expect(element.attr('id') === 'B').toBeFalsy();
93+
}));
12794

12895

129-
// it('should preserve other classes with similar name"', inject(function($rootScope, $compile) {
130-
// element = $compile('<div class="ui-panel ui-selected" ng-class="dynCls"></div>')($rootScope);
131-
// $rootScope.dynCls = 'panel';
132-
// $rootScope.$digest();
133-
// $rootScope.dynCls = 'foo';
134-
// $rootScope.$digest();
135-
// expect(element[0].className).toBe('ui-panel ui-selected ng-scope foo');
136-
// }));
96+
it('should replace id added post compilation with pre-existing ng-id value', inject(function($rootScope, $compile) {
97+
element = $compile('<div id="existing" ng-id="dynId"></div>')($rootScope);
98+
$rootScope.dynId = 'A';
99+
$rootScope.$digest();
100+
expect(element.attr('id') === 'existing').toBe(false);
137101

102+
// add extra class, change model and eval
103+
element.attr('id', 'newId');
104+
$rootScope.dynId = 'B';
105+
$rootScope.$digest();
138106

139-
// it('should not add duplicate classes', inject(function($rootScope, $compile) {
140-
// element = $compile('<div class="panel bar" ng-class="dynCls"></div>')($rootScope);
141-
// $rootScope.dynCls = 'panel';
142-
// $rootScope.$digest();
143-
// expect(element[0].className).toBe('panel bar ng-scope');
144-
// }));
107+
expect(element.attr('id') === 'existing').toBe(false);
108+
expect(element.attr('id') === 'B').toBe(true);
109+
expect(element.attr('id') === 'newid').toBe(false);
110+
}));
145111

146112

147-
// it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) {
148-
// element = $compile('<div class="panel bar" ng-class="dynCls"></div>')($rootScope);
149-
// $rootScope.dynCls = 'panel';
150-
// $rootScope.$digest();
151-
// $rootScope.dynCls = 'window';
152-
// $rootScope.$digest();
153-
// expect(element[0].className).toBe('bar ng-scope window');
154-
// }));
113+
it('should replace id added post compilation without pre-existing ids"', inject(function($rootScope, $compile) {
114+
element = $compile('<div ng-id="dynId"></div>')($rootScope);
115+
$rootScope.dynId = 'A';
116+
$rootScope.$digest();
117+
expect(element.attr('id') === 'A').toBe(true);
155118

119+
// add extra class, change model and eval
120+
element.attr('id', 'newId');
121+
$rootScope.dynId= 'B';
122+
$rootScope.$digest();
156123

157-
// it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) {
158-
// element = $compile('<div ng-class="dynCls"></div>')($rootScope);
159-
// $rootScope.dynCls = 'foo';
160-
// $rootScope.$digest();
161-
// element.addClass('foo');
162-
// $rootScope.dynCls = '';
163-
// $rootScope.$digest();
164-
// }));
124+
expect(element.attr('id') === 'B').toBe(true);
125+
expect(element.attr('id') === 'newid').toBe(false);
126+
}));
165127

128+
it('should remove ids even if it was specified via id attribute', inject(function($rootScope, $compile) {
129+
element = $compile('<div id="existing" ng-class="dynId"></div>')($rootScope);
130+
$rootScope.dynId = 'A';
131+
$rootScope.$digest();
132+
$rootScope.dynId = 'B';
133+
$rootScope.$digest();
134+
expect(element.attr('id') === 'B').toBe(true);
135+
}));
166136

167137
// it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
168138
// element = $compile('<div ng-class="dynCls"></div>')($rootScope);
@@ -176,10 +146,10 @@ describe('ngId', function() {
176146
// $rootScope.$digest();
177147
// var e1 = jqLite(element[0].childNodes[1]);
178148
// var e2 = jqLite(element[0].childNodes[3]);
179-
// expect(e1.hasClass('existing')).toBeTruthy();
180-
// expect(e1.hasClass('odd')).toBeTruthy();
181-
// expect(e2.hasClass('existing')).toBeTruthy();
182-
// expect(e2.hasClass('even')).toBeTruthy();
149+
// expect(e1.hasClass('existing')).attr('id') === y();
150+
// expect(e1.hasClass('odd')).attr('id') === y();
151+
// expect(e2.hasClass('existing')).attr('id') === y();
152+
// expect(e2.hasClass('even')).attr('id') === y();
183153
// }));
184154

185155

@@ -192,11 +162,11 @@ describe('ngId', function() {
192162
// var e1 = jqLite(element[0].childNodes[1]);
193163
// var e2 = jqLite(element[0].childNodes[3]);
194164

195-
// expect(e1.hasClass('plainClass')).toBeTruthy();
196-
// expect(e1.hasClass('odd')).toBeTruthy();
165+
// expect(e1.hasClass('plainClass')).attr('id') === y();
166+
// expect(e1.hasClass('odd')).attr('id') === y();
197167
// expect(e1.hasClass('even')).toBeFalsy();
198-
// expect(e2.hasClass('plainClass')).toBeTruthy();
199-
// expect(e2.hasClass('even')).toBeTruthy();
168+
// expect(e2.hasClass('plainClass')).attr('id') === y();
169+
// expect(e2.hasClass('even')).attr('id') === y();
200170
// expect(e2.hasClass('odd')).toBeFalsy();
201171
// }));
202172

@@ -208,10 +178,10 @@ describe('ngId', function() {
208178
// $rootScope.$digest();
209179
// var e1 = jqLite(element[0].childNodes[1]);
210180
// var e2 = jqLite(element[0].childNodes[5]);
211-
// expect(e1.hasClass('same')).toBeTruthy();
212-
// expect(e1.hasClass('odd')).toBeTruthy();
213-
// expect(e2.hasClass('same')).toBeTruthy();
214-
// expect(e2.hasClass('odd')).toBeTruthy();
181+
// expect(e1.hasClass('same')).attr('id') === y();
182+
// expect(e1.hasClass('odd')).attr('id') === y();
183+
// expect(e2.hasClass('same')).attr('id') === y();
184+
// expect(e2.hasClass('odd')).attr('id') === y();
215185
// }));
216186

217187
// it('should allow both ngClass and ngClassOdd/Even with multiple classes', inject(function($rootScope, $compile) {
@@ -223,17 +193,17 @@ describe('ngId', function() {
223193
// var e1 = jqLite(element[0].childNodes[1]);
224194
// var e2 = jqLite(element[0].childNodes[3]);
225195

226-
// expect(e1.hasClass('A')).toBeTruthy();
227-
// expect(e1.hasClass('B')).toBeTruthy();
228-
// expect(e1.hasClass('C')).toBeTruthy();
229-
// expect(e1.hasClass('D')).toBeTruthy();
196+
// expect(e1.hasClass('A')).attr('id') === y();
197+
// expect(e1.hasClass('B')).attr('id') === y();
198+
// expect(e1.hasClass('C')).attr('id') === y();
199+
// expect(e1.hasClass('D')).attr('id') === y();
230200
// expect(e1.hasClass('E')).toBeFalsy();
231201
// expect(e1.hasClass('F')).toBeFalsy();
232202

233-
// expect(e2.hasClass('A')).toBeTruthy();
234-
// expect(e2.hasClass('B')).toBeTruthy();
235-
// expect(e2.hasClass('E')).toBeTruthy();
236-
// expect(e2.hasClass('F')).toBeTruthy();
203+
// expect(e2.hasClass('A')).attr('id') === y();
204+
// expect(e2.hasClass('B')).attr('id') === y();
205+
// expect(e2.hasClass('E')).attr('id') === y();
206+
// expect(e2.hasClass('F')).attr('id') === y();
237207
// expect(e2.hasClass('C')).toBeFalsy();
238208
// expect(e2.hasClass('D')).toBeFalsy();
239209
// }));
@@ -297,10 +267,10 @@ describe('ngId', function() {
297267
// var e1 = jqLite(element[0].childNodes[1]);
298268
// var e2 = jqLite(element[0].childNodes[3]);
299269

300-
// expect(e1.hasClass('odd')).toBeTruthy();
270+
// expect(e1.hasClass('odd')).attr('id') === y();
301271
// expect(e1.hasClass('even')).toBeFalsy();
302272

303-
// expect(e2.hasClass('even')).toBeTruthy();
273+
// expect(e2.hasClass('even')).attr('id') === y();
304274
// expect(e2.hasClass('odd')).toBeFalsy();
305275
// }));
306276

@@ -319,10 +289,10 @@ describe('ngId', function() {
319289
// var e1 = jqLite(element[0].childNodes[1]);
320290
// var e2 = jqLite(element[0].childNodes[3]);
321291

322-
// expect(e1.hasClass('odd')).toBeTruthy();
292+
// expect(e1.hasClass('odd')).attr('id') === y();
323293
// expect(e1.hasClass('even')).toBeFalsy();
324294

325-
// expect(e2.hasClass('even')).toBeTruthy();
295+
// expect(e2.hasClass('even')).attr('id') === y();
326296
// expect(e2.hasClass('odd')).toBeFalsy();
327297
// }));
328298
});

0 commit comments

Comments
 (0)