Skip to content

Commit fea47f7

Browse files
committed
Finished testing, removed old console logs
1 parent cb6305a commit fea47f7

File tree

2 files changed

+21
-318
lines changed

2 files changed

+21
-318
lines changed

src/ng/directive/ngId.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ function idDirective() {
1616
function ngIdWatchAction(newVal) {
1717
var newId = typeofId(newVal || []);
1818
if (!newId && !oldVal) {
19-
console.log('Removing id');
19+
// Remove id
2020
element.removeAttr('id');
2121
} else if (!newId && oldVal) {
22-
console.log('Setting to old id:', oldVal, typeof(oldVal));
22+
// Set id attribute to old value
2323
element.attr('id', oldVal);
2424
} else {
25-
console.log('Setting to newId:', newVal, typeof(newVal))
25+
// Set id attribute to new value
2626
element.attr('id', newId);
2727
}
2828
};

test/ng/directive/ngIdSpec.js

+18-315
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('ngId', function() {
9999
$rootScope.$digest();
100100
expect(element.attr('id') === 'existing').toBe(false);
101101

102-
// add extra class, change model and eval
102+
// add extra id, change model and eval
103103
element.attr('id', 'newId');
104104
$rootScope.dynId = 'B';
105105
$rootScope.$digest();
@@ -116,7 +116,7 @@ describe('ngId', function() {
116116
$rootScope.$digest();
117117
expect(element.attr('id') === 'A').toBe(true);
118118

119-
// add extra class, change model and eval
119+
// add extra id, change model and eval
120120
element.attr('id', 'newId');
121121
$rootScope.dynId= 'B';
122122
$rootScope.$digest();
@@ -126,327 +126,30 @@ describe('ngId', function() {
126126
}));
127127

128128
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);
129+
element = $compile('<div id="existing" ng-id="dynId"></div>')($rootScope);
130130
$rootScope.dynId = 'A';
131131
$rootScope.$digest();
132132
$rootScope.dynId = 'B';
133133
$rootScope.$digest();
134134
expect(element.attr('id') === 'B').toBe(true);
135135
}));
136136

137-
// it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
138-
// element = $compile('<div ng-class="dynCls"></div>')($rootScope);
139-
// $rootScope.dynCls = [undefined, null];
140-
// $rootScope.$digest();
141-
// }));
142-
143-
144-
// it('should ngClass odd/even', inject(function($rootScope, $compile) {
145-
// element = $compile('<ul><li ng-repeat="i in [0,1]" class="existing" ng-class-odd="\'odd\'" ng-class-even="\'even\'"></li><ul>')($rootScope);
146-
// $rootScope.$digest();
147-
// var e1 = jqLite(element[0].childNodes[1]);
148-
// var e2 = jqLite(element[0].childNodes[3]);
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();
153-
// }));
154-
155-
156-
// it('should allow both ngClass and ngClassOdd/Even on the same element', inject(function($rootScope, $compile) {
157-
// element = $compile('<ul>' +
158-
// '<li ng-repeat="i in [0,1]" ng-class="\'plainClass\'" ' +
159-
// 'ng-class-odd="\'odd\'" ng-class-even="\'even\'"></li>' +
160-
// '<ul>')($rootScope);
161-
// $rootScope.$apply();
162-
// var e1 = jqLite(element[0].childNodes[1]);
163-
// var e2 = jqLite(element[0].childNodes[3]);
164-
165-
// expect(e1.hasClass('plainClass')).attr('id') === y();
166-
// expect(e1.hasClass('odd')).attr('id') === y();
167-
// expect(e1.hasClass('even')).toBeFalsy();
168-
// expect(e2.hasClass('plainClass')).attr('id') === y();
169-
// expect(e2.hasClass('even')).attr('id') === y();
170-
// expect(e2.hasClass('odd')).toBeFalsy();
171-
// }));
172-
173-
174-
// it("should allow ngClassOdd/Even on the same element with overlapping classes", inject(function($rootScope, $compile, $animate) {
175-
// var className;
176-
177-
// element = $compile('<ul><li ng-repeat="i in [0,1,2]" ng-class-odd="\'same odd\'" ng-class-even="\'same even\'"></li><ul>')($rootScope);
178-
// $rootScope.$digest();
179-
// var e1 = jqLite(element[0].childNodes[1]);
180-
// var e2 = jqLite(element[0].childNodes[5]);
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();
185-
// }));
186-
187-
// it('should allow both ngClass and ngClassOdd/Even with multiple classes', inject(function($rootScope, $compile) {
188-
// element = $compile('<ul>' +
189-
// '<li ng-repeat="i in [0,1]" ng-class="[\'A\', \'B\']" ' +
190-
// 'ng-class-odd="[\'C\', \'D\']" ng-class-even="[\'E\', \'F\']"></li>' +
191-
// '<ul>')($rootScope);
192-
// $rootScope.$apply();
193-
// var e1 = jqLite(element[0].childNodes[1]);
194-
// var e2 = jqLite(element[0].childNodes[3]);
195-
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();
200-
// expect(e1.hasClass('E')).toBeFalsy();
201-
// expect(e1.hasClass('F')).toBeFalsy();
202-
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();
207-
// expect(e2.hasClass('C')).toBeFalsy();
208-
// expect(e2.hasClass('D')).toBeFalsy();
209-
// }));
210-
211-
212-
// it('should reapply ngClass when interpolated class attribute changes', inject(function($rootScope, $compile) {
213-
// element = $compile('<div class="one {{cls}} three" ng-class="{four: four}"></div>')($rootScope);
214-
215-
// $rootScope.$apply(function() {
216-
// $rootScope.cls = "two";
217-
// $rootScope.four = true;
218-
// });
219-
// expect(element).toHaveClass('one');
220-
// expect(element).toHaveClass('two'); // interpolated
221-
// expect(element).toHaveClass('three');
222-
// expect(element).toHaveClass('four');
223-
224-
// $rootScope.$apply(function() {
225-
// $rootScope.cls = "too";
226-
// });
227-
// expect(element).toHaveClass('one');
228-
// expect(element).toHaveClass('too'); // interpolated
229-
// expect(element).toHaveClass('three');
230-
// expect(element).toHaveClass('four'); // should still be there
231-
// expect(element.hasClass('two')).toBeFalsy();
232-
233-
// $rootScope.$apply(function() {
234-
// $rootScope.cls = "to";
235-
// });
236-
// expect(element).toHaveClass('one');
237-
// expect(element).toHaveClass('to'); // interpolated
238-
// expect(element).toHaveClass('three');
239-
// expect(element).toHaveClass('four'); // should still be there
240-
// expect(element.hasClass('two')).toBeFalsy();
241-
// expect(element.hasClass('too')).toBeFalsy();
242-
// }));
243-
244-
245-
// it('should not mess up class value due to observing an interpolated class attribute', inject(function($rootScope, $compile) {
246-
// $rootScope.foo = true;
247-
// $rootScope.$watch("anything", function() {
248-
// $rootScope.foo = false;
249-
// });
250-
// element = $compile('<div ng-class="{foo:foo}"></div>')($rootScope);
251-
// $rootScope.$digest();
252-
// expect(element.hasClass('foo')).toBe(false);
253-
// }));
254-
255-
256-
// it('should update ngClassOdd/Even when model is changed by filtering', inject(function($rootScope, $compile) {
257-
// element = $compile('<ul>' +
258-
// '<li ng-repeat="i in items track by $index" ' +
259-
// 'ng-class-odd="\'odd\'" ng-class-even="\'even\'"></li>' +
260-
// '<ul>')($rootScope);
261-
// $rootScope.items = ['a','b','a'];
262-
// $rootScope.$digest();
263-
264-
// $rootScope.items = ['a','a'];
265-
// $rootScope.$digest();
266-
267-
// var e1 = jqLite(element[0].childNodes[1]);
268-
// var e2 = jqLite(element[0].childNodes[3]);
269-
270-
// expect(e1.hasClass('odd')).attr('id') === y();
271-
// expect(e1.hasClass('even')).toBeFalsy();
272-
273-
// expect(e2.hasClass('even')).attr('id') === y();
274-
// expect(e2.hasClass('odd')).toBeFalsy();
275-
// }));
276-
277-
278-
// it('should update ngClassOdd/Even when model is changed by sorting', inject(function($rootScope, $compile) {
279-
// element = $compile('<ul>' +
280-
// '<li ng-repeat="i in items" ' +
281-
// 'ng-class-odd="\'odd\'" ng-class-even="\'even\'">i</li>' +
282-
// '<ul>')($rootScope);
283-
// $rootScope.items = ['a','b'];
284-
// $rootScope.$digest();
285-
286-
// $rootScope.items = ['b','a'];
287-
// $rootScope.$digest();
137+
it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
138+
element = $compile('<div ng-id="dynId"></div>')($rootScope);
139+
$rootScope.dynId = [undefined, null];
140+
$rootScope.$digest();
141+
expect(element[0].id).toBeFalsy();
142+
}));
288143

289-
// var e1 = jqLite(element[0].childNodes[1]);
290-
// var e2 = jqLite(element[0].childNodes[3]);
144+
it('should reinstate the original id if the specified id evaluates to false', inject(function($rootScope, $compile) {
145+
element = $compile('<div id="existing" ng-id="dynId"></div>')($rootScope);
146+
$rootScope.dynId = 'A';
147+
$rootScope.$digest();
148+
expect(element.attr('id') === 'A').toBeTruthy();
291149

292-
// expect(e1.hasClass('odd')).attr('id') === y();
293-
// expect(e1.hasClass('even')).toBeFalsy();
150+
$rootScope.dynId = false;
151+
$rootScope.$digest();
152+
expect(element.attr('id') === 'existing').toBeTruthy();
153+
}))
294154

295-
// expect(e2.hasClass('even')).attr('id') === y();
296-
// expect(e2.hasClass('odd')).toBeFalsy();
297-
// }));
298155
});
299-
300-
// describe('ngClass animations', function() {
301-
// var body, element, $rootElement;
302-
303-
// it("should avoid calling addClass accidentally when removeClass is going on", function() {
304-
// module('ngAnimateMock');
305-
// inject(function($compile, $rootScope, $animate, $timeout) {
306-
// var element = angular.element('<div ng-class="val"></div>');
307-
// var body = jqLite(document.body);
308-
// body.append(element);
309-
// $compile(element)($rootScope);
310-
311-
// expect($animate.queue.length).toBe(0);
312-
313-
// $rootScope.val = 'one';
314-
// $rootScope.$digest();
315-
// expect($animate.queue.shift().event).toBe('addClass');
316-
// expect($animate.queue.length).toBe(0);
317-
318-
// $rootScope.val = '';
319-
// $rootScope.$digest();
320-
// expect($animate.queue.shift().event).toBe('removeClass'); //only removeClass is called
321-
// expect($animate.queue.length).toBe(0);
322-
323-
// $rootScope.val = 'one';
324-
// $rootScope.$digest();
325-
// expect($animate.queue.shift().event).toBe('addClass');
326-
// expect($animate.queue.length).toBe(0);
327-
328-
// $rootScope.val = 'two';
329-
// $rootScope.$digest();
330-
// expect($animate.queue.shift().event).toBe('setClass');
331-
// expect($animate.queue.length).toBe(0);
332-
// });
333-
// });
334-
335-
// it("should consider the ngClass expression evaluation before performing an animation", function() {
336-
337-
// //mocks are not used since the enter delegation method is called before addClass and
338-
// //it makes it impossible to test to see that addClass is called first
339-
// module('ngAnimate');
340-
// module('ngAnimateMock');
341-
342-
// var digestQueue = [];
343-
// module(function($animateProvider) {
344-
// $animateProvider.register('.crazy', function() {
345-
// return {
346-
// enter : function(element, done) {
347-
// element.data('state', 'crazy-enter');
348-
// done();
349-
// }
350-
// };
351-
// });
352-
353-
// return function($rootScope) {
354-
// var before = $rootScope.$$postDigest;
355-
// $rootScope.$$postDigest = function() {
356-
// var args = arguments;
357-
// digestQueue.push(function() {
358-
// before.apply($rootScope, args);
359-
// });
360-
// };
361-
// };
362-
// });
363-
// inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $document) {
364-
365-
// // Enable animations by triggering the first item in the postDigest queue
366-
// digestQueue.shift()();
367-
368-
// // wait for the 2nd animation bootstrap digest to pass
369-
// $rootScope.$digest();
370-
// digestQueue.shift()();
371-
372-
// $rootScope.val = 'crazy';
373-
// var element = angular.element('<div ng-class="val"></div>');
374-
// jqLite($document[0].body).append($rootElement);
375-
376-
// $compile(element)($rootScope);
377-
378-
// var enterComplete = false;
379-
// $animate.enter(element, $rootElement, null, function() {
380-
// enterComplete = true;
381-
// });
382-
383-
// //jquery doesn't compare both elements properly so let's use the nodes
384-
// expect(element.parent()[0]).toEqual($rootElement[0]);
385-
// expect(element.hasClass('crazy')).toBe(false);
386-
// expect(enterComplete).toBe(false);
387-
388-
// expect(digestQueue.length).toBe(1);
389-
// $rootScope.$digest();
390-
391-
// $timeout.flush();
392-
393-
// expect(element.hasClass('crazy')).toBe(true);
394-
// expect(enterComplete).toBe(false);
395-
396-
// digestQueue.shift()(); //enter
397-
// expect(digestQueue.length).toBe(0);
398-
399-
// //we don't normally need this, but since the timing between digests
400-
// //is spaced-out then it is required so that the original digestion
401-
// //is kicked into gear
402-
// $rootScope.$digest();
403-
// $animate.triggerCallbacks();
404-
405-
// expect(element.data('state')).toBe('crazy-enter');
406-
// expect(enterComplete).toBe(true);
407-
// });
408-
// });
409-
410-
// it("should not remove classes if they're going to be added back right after", function() {
411-
// module('ngAnimateMock');
412-
413-
// inject(function($rootScope, $compile, $animate) {
414-
// var className;
415-
416-
// $rootScope.one = true;
417-
// $rootScope.two = true;
418-
// $rootScope.three = true;
419-
420-
// var element = angular.element('<div ng-class="{one:one, two:two, three:three}"></div>');
421-
// $compile(element)($rootScope);
422-
// $rootScope.$digest();
423-
424-
// //this fires twice due to the class observer firing
425-
// var item = $animate.queue.shift();
426-
// expect(item.event).toBe('addClass');
427-
// expect(item.args[1]).toBe('one two three');
428-
429-
// expect($animate.queue.length).toBe(0);
430-
431-
// $rootScope.three = false;
432-
// $rootScope.$digest();
433-
434-
// item = $animate.queue.shift();
435-
// expect(item.event).toBe('removeClass');
436-
// expect(item.args[1]).toBe('three');
437-
438-
// expect($animate.queue.length).toBe(0);
439-
440-
// $rootScope.two = false;
441-
// $rootScope.three = true;
442-
// $rootScope.$digest();
443-
444-
// item = $animate.queue.shift();
445-
// expect(item.event).toBe('setClass');
446-
// expect(item.args[1]).toBe('three');
447-
// expect(item.args[2]).toBe('two');
448-
449-
// expect($animate.queue.length).toBe(0);
450-
// });
451-
// });
452-
// });

0 commit comments

Comments
 (0)