|
1 | 1 | describe('bar directives', function() {
|
2 | 2 | beforeEach(module('ionic'));
|
3 | 3 |
|
4 |
| - ['ion-header-bar'].forEach(function(tpl) { |
5 |
| - describe('tapScrollToTop ' + tpl, function() { |
6 |
| - function setup(attrs) { |
7 |
| - var el; |
8 |
| - inject(function($compile, $rootScope) { |
9 |
| - el = angular.element('<' + tpl + ' ' + (attrs||'') + '>'); |
10 |
| - var container = angular.element('<ion-content>').append(el); |
11 |
| - ionic.requestAnimationFrame = function(cb) { cb(); }; |
12 |
| - $compile(container)($rootScope.$new()); |
13 |
| - container.controller('$ionicScroll').scrollTop = jasmine.createSpy('scrollTop'); |
14 |
| - $rootScope.$apply(); |
15 |
| - }); |
16 |
| - return el; |
17 |
| - } |
18 |
| - it('should not listen for tap if attr.noTapScroll', function() { |
19 |
| - spyOn(ionic, 'on'); |
20 |
| - setup('no-tap-scroll="true"'); |
21 |
| - expect(ionic.on).not.toHaveBeenCalledWith('tap'); |
22 |
| - }); |
23 |
| - |
24 |
| - it('should listen for tap, unlisten on destroy', function() { |
25 |
| - var callback; |
26 |
| - spyOn(ionic, 'on').andCallFake(function(name, cb) { |
27 |
| - callback = cb; |
28 |
| - }); |
29 |
| - spyOn(ionic, 'off'); |
30 |
| - var el = setup(); |
31 |
| - expect(ionic.on.mostRecentCall.args[0]).toBe('tap'); |
32 |
| - expect(ionic.off).not.toHaveBeenCalled(); |
33 |
| - el.scope().$destroy(); |
34 |
| - expect(ionic.off.mostRecentCall.args[0]).toBe('tap'); |
35 |
| - expect(ionic.off.mostRecentCall.args[1]).toBe(callback); |
36 |
| - expect(ionic.off.mostRecentCall.args[2]).toBe(el[0]); |
37 |
| - }); |
38 |
| - ['input','textarea','select'].forEach(function(tag) { |
39 |
| - it('should ignore tap if it\'s in a ' + tag, function() { |
40 |
| - var el = setup(); |
41 |
| - spyOn(ionic.DomUtil, 'rectContains'); |
42 |
| - var child = angular.element('<' + tag + '>'); |
43 |
| - el.append(child); |
44 |
| - ionic.trigger('tap', { target: child[0] }, true, true); |
45 |
| - expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled(); |
46 |
| - }); |
47 |
| - }); |
48 |
| - it('should ignore tap if it\'s in a [contenteditable]', function() { |
49 |
| - var el = setup(); |
50 |
| - spyOn(ionic.DomUtil, 'rectContains'); |
51 |
| - var child = angular.element('<div contenteditable>'); |
52 |
| - el.append(child); |
53 |
| - ionic.trigger('tap', [{ target: child[0] }], true, true); |
54 |
| - expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled(); |
55 |
| - }); |
56 |
| - it('should ignore tap if it\'s in a .button', function() { |
57 |
| - var el = setup(); |
58 |
| - spyOn(ionic.DomUtil, 'rectContains'); |
59 |
| - var child = angular.element('<div class="button">'); |
60 |
| - el.append(child); |
61 |
| - ionic.trigger('tap', { target: child[0] }, true, true); |
62 |
| - expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled(); |
63 |
| - }); |
64 |
| - it('should scrollTop if tap is inside headerBar', function() { |
65 |
| - var el = setup(); |
66 |
| - spyOn(ionic.DomUtil, 'rectContains').andCallFake(function() { |
67 |
| - return true; |
68 |
| - }); |
69 |
| - ionic.trigger('tap', { target: el[0], touches: [{pageX:0,pageY:0}] }); |
70 |
| - expect(el.controller('$ionicScroll').scrollTop).toHaveBeenCalledWith(true); |
71 |
| - }); |
72 |
| - it('should not scrollTop if tap isnt inside headerBar', function() { |
73 |
| - var el = setup(); |
74 |
| - spyOn(ionic.DomUtil, 'rectContains').andCallFake(function() { |
75 |
| - return false; |
76 |
| - }); |
77 |
| - ionic.trigger('tap', { target: el[0], touches: [{pageX:0,pageY:0}] }); |
78 |
| - expect(el.controller('$ionicScroll').scrollTop).not.toHaveBeenCalled(); |
79 |
| - }); |
80 |
| - }); |
81 |
| - }); |
82 |
| - |
83 | 4 | angular.forEach([{
|
84 | 5 | tag: 'ion-header-bar',
|
85 | 6 | className: 'bar bar-header'
|
|
0 commit comments