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

Commit

Permalink
style(widgetsSpec): ws, unused variables, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Jan 6, 2012
1 parent cd9a7b9 commit acb4338
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions test/widgetsSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

describe('widget', function() {
describe('ng:switch', inject(function($rootScope, $compile) {
describe('ng:switch', function() {
it('should switch on value change', inject(function($rootScope, $compile) {
var element = $compile(
'<ng:switch on="select">' +
Expand All @@ -26,7 +26,7 @@ describe('widget', function() {
$rootScope.$apply();
expect(element.text()).toEqual('true:misko');
}));


it('should switch on switch-when-default', inject(function($rootScope, $compile) {
var element = $compile(
Expand All @@ -41,7 +41,7 @@ describe('widget', function() {
expect(element.text()).toEqual('one');
}));


it('should call change on switch', inject(function($rootScope, $compile) {
var element = $compile(
'<ng:switch on="url" change="name=\'works\'">' +
Expand All @@ -52,7 +52,7 @@ describe('widget', function() {
expect($rootScope.name).toEqual(undefined);
expect(element.text()).toEqual('works');
}));
}));
});


describe('ng:include', inject(function($rootScope, $compile) {
Expand Down Expand Up @@ -149,6 +149,7 @@ describe('widget', function() {
expect($rootScope.$$childHead).toBeFalsy();
}));


it('should do xhr request and cache it',
inject(function($rootScope, $httpBackend, $compile, $browser) {
var element = $compile('<ng:include src="url"></ng:include>')($rootScope);
Expand All @@ -170,6 +171,7 @@ describe('widget', function() {
dealoc($rootScope);
}));


it('should clear content when error during xhr request',
inject(function($httpBackend, $compile, $rootScope) {
var element = $compile('<ng:include src="url">content</ng:include>')($rootScope);
Expand All @@ -182,6 +184,7 @@ describe('widget', function() {
expect(element.text()).toBe('');
}));


it('should be async even if served from cache', inject(
putIntoCache('myUrl', 'my partial'),
function($rootScope, $compile, $browser) {
Expand All @@ -200,6 +203,7 @@ describe('widget', function() {
expect(element.text()).toBe('my partial');
}));


it('should discard pending xhr callbacks if a new template is requested before the current ' +
'finished loading', inject(function($rootScope, $compile, $httpBackend) {
var element = jqLite("<ng:include src='templateUrl'></ng:include>"),
Expand All @@ -226,7 +230,7 @@ describe('widget', function() {
}));


describe('a', inject(function($rootScope, $compile) {
describe('a', function() {
it('should prevent default action to be executed when href is empty',
inject(function($rootScope, $compile) {
var orgLocation = document.location.href,
Expand Down Expand Up @@ -261,10 +265,10 @@ describe('widget', function() {

expect(document.location.href).toEqual(orgLocation);
}));
}));
});


describe('@ng:repeat', inject(function($rootScope, $compile) {
describe('@ng:repeat', function() {
it('should ng:repeat over array', inject(function($rootScope, $compile) {
var element = $compile(
'<ul>' +
Expand Down Expand Up @@ -292,6 +296,7 @@ describe('widget', function() {
expect(element.text()).toEqual('brad;');
}));


it('should ng:repeat over object', inject(function($rootScope, $compile) {
var element = $compile(
'<ul>' +
Expand All @@ -302,6 +307,7 @@ describe('widget', function() {
expect(element.text()).toEqual('misko:swe;shyam:set;');
}));


it('should not ng:repeat over parent properties', inject(function($rootScope, $compile) {
var Class = function() {};
Class.prototype.abc = function() {};
Expand All @@ -317,6 +323,7 @@ describe('widget', function() {
expect(element.text()).toEqual('name:value;');
}));


it('should error on wrong parsing of ng:repeat', inject(function($rootScope, $compile, $log) {
expect(function() {
var element = $compile('<ul><li ng:repeat="i dont parse"></li></ul>')($rootScope);
Expand All @@ -325,6 +332,7 @@ describe('widget', function() {
$log.error.logs.shift();
}));


it('should expose iterator offset as $index when iterating over arrays',
inject(function($rootScope, $compile) {
var element = $compile(
Expand All @@ -336,6 +344,7 @@ describe('widget', function() {
expect(element.text()).toEqual('misko0|shyam1|frodo2|');
}));


it('should expose iterator offset as $index when iterating over objects',
inject(function($rootScope, $compile) {
var element = $compile(
Expand All @@ -347,6 +356,7 @@ describe('widget', function() {
expect(element.text()).toEqual('frodo:f0|misko:m1|shyam:s2|');
}));


it('should expose iterator position as $position when iterating over arrays',
inject(function($rootScope, $compile) {
var element = $compile(
Expand All @@ -367,6 +377,7 @@ describe('widget', function() {
expect(element.text()).toEqual('misko:first|shyam:last|');
}));


it('should expose iterator position as $position when iterating over objects',
inject(function($rootScope, $compile) {
var element = $compile(
Expand All @@ -384,6 +395,7 @@ describe('widget', function() {
expect(element.text()).toEqual('misko:m:first|shyam:s:last|');
}));


it('should ignore $ and $$ properties', inject(function($rootScope, $compile) {
var element = $compile('<ul><li ng:repeat="i in items">{{i}}|</li></ul>')($rootScope);
$rootScope.items = ['a', 'b', 'c'];
Expand All @@ -394,6 +406,7 @@ describe('widget', function() {
expect(element.text()).toEqual('a|b|c|');
}));


it('should repeat over nested arrays', inject(function($rootScope, $compile) {
var element = $compile(
'<ul>' +
Expand All @@ -407,6 +420,7 @@ describe('widget', function() {
expect(element.text()).toEqual('a|b|Xc|d|X');
}));


it('should ignore non-array element properties when iterating over an array',
inject(function($rootScope, $compile) {
var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
Expand All @@ -418,6 +432,7 @@ describe('widget', function() {
expect(element.text()).toBe('a|b|c|');
}));


it('should iterate over non-existent elements of a sparse array',
inject(function($rootScope, $compile) {
var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
Expand All @@ -429,6 +444,7 @@ describe('widget', function() {
expect(element.text()).toBe('a|b|||c||d|');
}));


it('should iterate over all kinds of types', inject(function($rootScope, $compile) {
var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);
$rootScope.array = ['a', 1, null, undefined, {}];
Expand Down Expand Up @@ -456,7 +472,8 @@ describe('widget', function() {
lis = element.find('li');
}));

it('should preserve the order of elements', inject(function($rootScope, $compile) {

it('should preserve the order of elements', inject(function($rootScope) {
$rootScope.items = [a, c, d];
$rootScope.$digest();
var newElements = element.find('li');
Expand All @@ -465,7 +482,8 @@ describe('widget', function() {
expect(newElements[2]).not.toEqual(lis[1]);
}));

it('should support duplicates', inject(function($rootScope, $compile) {

it('should support duplicates', inject(function($rootScope) {
$rootScope.items = [a, a, b, c];
$rootScope.$digest();
var newElements = element.find('li');
Expand All @@ -490,8 +508,9 @@ describe('widget', function() {
expect(newElements[3]).toEqual(lis[3]);
}));


it('should remove last item when one duplicate instance is removed',
inject(function($rootScope, $compile) {
inject(function($rootScope) {
$rootScope.items = [a, a, a];
$rootScope.$digest();
lis = element.find('li');
Expand All @@ -504,8 +523,9 @@ describe('widget', function() {
expect(newElements[1]).toEqual(lis[1]);
}));


it('should reverse items when the collection is reversed',
inject(function($rootScope, $compile) {
inject(function($rootScope) {
$rootScope.items = [a, b, c];
$rootScope.$digest();
lis = element.find('li');
Expand All @@ -519,7 +539,7 @@ describe('widget', function() {
expect(newElements[2]).toEqual(lis[0]);
}));
});
}));
});


describe('@ng:non-bindable', function() {
Expand Down Expand Up @@ -568,6 +588,7 @@ describe('widget', function() {
expect(element.text()).toEqual('angular is da best');
}));


it('should remove all content when location changes to an unknown route',
inject(function($rootScope, $compile, $location, $httpBackend, $route) {
$route.when('/foo', {template: 'myUrl1'});
Expand All @@ -583,6 +604,7 @@ describe('widget', function() {
expect($rootScope.$element.text()).toEqual('');
}));


it('should chain scopes and propagate evals to the child scope',
inject(function($rootScope, $compile, $location, $httpBackend, $route) {
$route.when('/foo', {template: 'myUrl1'});
Expand All @@ -599,6 +621,7 @@ describe('widget', function() {
expect($rootScope.$element.text()).toEqual('new parent');
}));


it('should be possible to nest ng:view in ng:include', inject(function() {
// TODO(vojta): refactor this test
var injector = angular.injector('ng', 'ngMock');
Expand All @@ -624,6 +647,7 @@ describe('widget', function() {
dealoc(myApp);
}));


it('should initialize view template after the view controller was initialized even when ' +
'templates were cached',
inject(function($rootScope, $compile, $location, $httpBackend, $route, $browser) {
Expand Down Expand Up @@ -662,6 +686,7 @@ describe('widget', function() {
expect($rootScope.log).toEqual(['parent', 'init', 'child']);
}));


it('should discard pending xhr callbacks if a new route is requested before the current ' +
'finished loading', inject(function($route, $rootScope, $location, $httpBackend) {
// this is a test for a bad race condition that affected feedback
Expand All @@ -682,6 +707,7 @@ describe('widget', function() {
expect($rootScope.$element.text()).toEqual('2');
}));


it('should clear the content when error during xhr request',
inject(function($route, $location, $rootScope, $httpBackend) {
$route.when('/foo', {controller: noop, template: 'myUrl1'});
Expand All @@ -696,6 +722,7 @@ describe('widget', function() {
expect($rootScope.$element.text()).toBe('');
}));


it('should be async even if served from cache',
inject(function($route, $rootScope, $location, $templateCache, $browser) {
$templateCache.put('myUrl1', [200, 'my partial', {}]);
Expand All @@ -717,7 +744,6 @@ describe('widget', function() {

describe('ng:pluralize', function() {


describe('deal with pluralized strings without offset', function() {
var element;
beforeEach(inject(function($rootScope, $compile) {
Expand All @@ -729,7 +755,8 @@ describe('widget', function() {
'</ng:pluralize>')($rootScope);
}));

it('should show single/plural strings', inject(function($rootScope, $compile) {

it('should show single/plural strings', inject(function($rootScope) {
$rootScope.email = 0;
$rootScope.$digest();
expect(element.text()).toBe('You have no new email');
Expand Down Expand Up @@ -768,8 +795,7 @@ describe('widget', function() {
}));


it('should show single/plural strings with mal-formed inputs',
inject(function($rootScope, $compile) {
it('should show single/plural strings with mal-formed inputs', inject(function($rootScope) {
$rootScope.email = '';
$rootScope.$digest();
expect(element.text()).toBe('');
Expand Down Expand Up @@ -845,4 +871,3 @@ describe('widget', function() {
});
});
});

0 comments on commit acb4338

Please sign in to comment.