forked from angular-ui/bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtooltip-template.spec.js
84 lines (62 loc) · 2.1 KB
/
tooltip-template.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
describe('tooltip template', function() {
var elm,
elmBody,
scope,
elmScope,
tooltipScope;
// load the popover code
beforeEach(module('ui.bootstrap.tooltip'));
// load the template
beforeEach(module('template/tooltip/tooltip-template-popup.html'));
beforeEach(inject(function($templateCache) {
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]);
}));
beforeEach(inject(function($rootScope, $compile) {
elmBody = angular.element(
'<div><span uib-tooltip-template="templateUrl">Selector Text</span></div>'
);
scope = $rootScope;
$compile(elmBody)(scope);
scope.templateUrl = 'myUrl';
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;
}));
function trigger(element, evt) {
evt = new Event(evt);
element[0].dispatchEvent(evt);
element.scope().$$childTail.$digest();
}
it('should open on mouseenter', inject(function() {
trigger(elm, 'mouseenter');
expect(tooltipScope.isOpen).toBe(true);
expect(elmBody.children().length).toBe(2);
}));
it('should not open on mouseenter if templateUrl is empty', inject(function() {
scope.templateUrl = null;
scope.$digest();
trigger(elm, 'mouseenter');
expect(tooltipScope.isOpen).toBe(false);
expect(elmBody.children().length).toBe(1);
}));
it('should show updated text', inject(function() {
scope.myTemplateText = 'some text';
trigger(elm, 'mouseenter');
expect(tooltipScope.isOpen).toBe(true);
scope.$digest();
expect(elmBody.children().eq(1).text().trim()).toBe('some text');
scope.myTemplateText = 'new text';
scope.$digest();
expect(elmBody.children().eq(1).text().trim()).toBe('new text');
}));
it('should hide tooltip when template becomes empty', inject(function($timeout) {
trigger(elm, 'mouseenter');
expect(tooltipScope.isOpen).toBe(true);
scope.templateUrl = '';
scope.$digest();
expect(tooltipScope.isOpen).toBe(false);
$timeout.flush();
expect(elmBody.children().length).toBe(1);
}));
});