diff options
| author | Vojta Jina | 2012-01-06 19:19:31 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-01-07 00:18:22 -0800 |
| commit | 5c197660638b8f4f603ed087bedf88cb1c980832 (patch) | |
| tree | 00da63f40b3b3d7213fb4fe799c5cf7b7f9e52b0 /test/widgetsSpec.js | |
| parent | f2119c752425661e0ef4c772f14a3b6755b44525 (diff) | |
| download | angular.js-5c197660638b8f4f603ed087bedf88cb1c980832.tar.bz2 | |
feat(ng:include): enable/disable scrolling through autoscroll attribute
Diffstat (limited to 'test/widgetsSpec.js')
| -rw-r--r-- | test/widgetsSpec.js | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 633ec0e0..e8ff4b27 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -55,7 +55,7 @@ describe('widget', function() { }); - describe('ng:include', inject(function($rootScope, $compile) { + describe('ng:include', function() { function putIntoCache(url, content) { return function($templateCache) { @@ -227,9 +227,74 @@ describe('widget', function() { expect(log.join('; ')).toEqual('url2; url2'); // it's here twice because we go through at // least two digest cycles })); - })); + describe('autoscoll', function() { + var autoScrollSpy; + + function spyOnAutoScroll() { + return function($provide) { + autoScrollSpy = jasmine.createSpy('$autoScroll'); + $provide.value('$autoScroll', autoScrollSpy); + }; + } + + function compileAndLink(tpl) { + return function($compile, $rootScope) { + $compile(tpl)($rootScope); + }; + } + + function changeTplAndValueTo(template, value) { + return function($rootScope, $browser) { + $rootScope.$apply(function() { + $rootScope.tpl = template; + $rootScope.value = value; + }); + $browser.defer.flush(); + }; + } + + beforeEach(inject( + spyOnAutoScroll(), + putIntoCache('template.html', 'CONTENT'), + putIntoCache('another.html', 'CONTENT'))); + + + it('should call $autoScroll if autoscroll attribute is present', inject( + compileAndLink('<ng:include src="tpl" autoscroll></ng:include>'), + changeTplAndValueTo('template.html'), function() { + expect(autoScrollSpy).toHaveBeenCalledOnce(); + })); + + + it('should call $autoScroll if autoscroll evaluates to true', inject( + compileAndLink('<ng:include src="tpl" autoscroll="value"></ng:include>'), + changeTplAndValueTo('template.html', true), + changeTplAndValueTo('another.html', 'some-string'), + changeTplAndValueTo('template.html', 100), function() { + expect(autoScrollSpy).toHaveBeenCalled(); + expect(autoScrollSpy.callCount).toBe(3); + })); + + + it('should not call $autoScroll if autoscroll attribute is not present', inject( + compileAndLink('<ng:include src="tpl"></ng:include>'), + changeTplAndValueTo('template.html'), function() { + expect(autoScrollSpy).not.toHaveBeenCalled(); + })); + + + it('should not call $autoScroll if autoscroll evaluates to false', inject( + compileAndLink('<ng:include src="tpl" autoscroll="value"></ng:include>'), + changeTplAndValueTo('template.html', false), + changeTplAndValueTo('template.html', undefined), + changeTplAndValueTo('template.html', null), function() { + expect(autoScrollSpy).not.toHaveBeenCalled(); + })); + }); + }); + describe('a', function() { it('should prevent default action to be executed when href is empty', inject(function($rootScope, $compile) { |
