1
- describe ( '<md-fab-speed-dial> directive' , function ( ) {
2
-
3
- beforeEach ( module ( 'material.components.fabSpeedDial' ) ) ;
1
+ describe ( '<md-fab-speed-dial> directive' , function ( ) {
4
2
5
3
var pageScope , element , controller ;
4
+ var $rootScope , $animate , $timeout ;
6
5
7
- function compileAndLink ( template ) {
8
- inject ( function ( $compile , $rootScope ) {
9
- pageScope = $rootScope . $new ( ) ;
10
- element = $compile ( template ) ( pageScope ) ;
11
- controller = element . controller ( 'mdFabSpeedDial' ) ;
12
-
13
- pageScope . $apply ( ) ;
14
- } ) ;
15
- }
6
+ beforeEach ( module ( 'material.components.fabSpeedDial' ) ) ;
7
+ beforeEach ( inject ( function ( _$rootScope_ , _$animate_ , _$timeout_ ) {
8
+ $rootScope = _$rootScope_ ;
9
+ $animate = _$animate_ ;
10
+ $timeout = _$timeout_ ;
11
+ } ) ) ;
16
12
17
- it ( 'applies a class for each direction' , inject ( function ( ) {
18
- compileAndLink (
13
+ it ( 'applies a class for each direction' , inject ( function ( ) {
14
+ build (
19
15
'<md-fab-speed-dial md-direction="{{direction}}"></md-fab-speed-dial>'
20
16
) ;
21
17
@@ -32,8 +28,8 @@ describe('<md-fab-speed-dial> directive', function() {
32
28
expect ( element . hasClass ( 'md-right' ) ) . toBe ( true ) ;
33
29
} ) ) ;
34
30
35
- it ( 'opens when the trigger element is focused' , inject ( function ( ) {
36
- compileAndLink (
31
+ it ( 'opens when the trigger element is focused' , inject ( function ( ) {
32
+ build (
37
33
'<md-fab-speed-dial><md-fab-trigger><button></button></md-fab-trigger></md-fab-speed-dial>'
38
34
) ;
39
35
@@ -42,32 +38,46 @@ describe('<md-fab-speed-dial> directive', function() {
42
38
expect ( controller . isOpen ) . toBe ( true ) ;
43
39
} ) ) ;
44
40
45
- it ( 'opens when the speed dial elements are focused' , inject ( function ( ) {
46
- compileAndLink (
41
+ it ( 'opens when the speed dial elements are focused' , inject ( function ( ) {
42
+ build (
47
43
'<md-fab-speed-dial><md-fab-actions><button></button></md-fab-actions></md-fab-speed-dial>'
48
44
) ;
49
45
50
46
element . find ( 'button' ) . triggerHandler ( 'focus' ) ;
51
47
pageScope . $digest ( ) ;
48
+
52
49
expect ( controller . isOpen ) . toBe ( true ) ;
53
50
} ) ) ;
54
51
55
- it ( 'closes when the speed dial elements are blurred' , inject ( function ( ) {
56
- compileAndLink (
57
- '<md-fab-speed-dial><md-fab-actions><button></button></md-fab-actions></md-fab-speed-dial>'
52
+ it ( 'closes when the speed dial elements are blurred' , inject ( function ( ) {
53
+ build (
54
+ '<md-fab-speed-dial>' +
55
+ ' <md-fab-trigger>' +
56
+ ' <button>Show Actions</button>' +
57
+ ' </md-fab-trigger>' +
58
+ ' </md-fab-actions>' +
59
+ ' <md-fab-actions>' +
60
+ ' <button>Action 1</button>' +
61
+ ' </md-fab-actions>' +
62
+ '</md-fab-speed-dial>'
58
63
) ;
59
64
60
65
element . find ( 'button' ) . triggerHandler ( 'focus' ) ;
61
66
pageScope . $digest ( ) ;
67
+
62
68
expect ( controller . isOpen ) . toBe ( true ) ;
63
69
64
- element . find ( 'button' ) . triggerHandler ( 'blur' ) ;
70
+ var actionBtn = element . find ( 'md-fab-actions' ) . find ( 'button' ) ;
71
+ actionBtn . triggerHandler ( 'focus' ) ;
72
+ pageScope . $digest ( ) ;
73
+ actionBtn . triggerHandler ( 'blur' ) ;
65
74
pageScope . $digest ( ) ;
75
+
66
76
expect ( controller . isOpen ) . toBe ( false ) ;
67
77
} ) ) ;
68
78
69
- it ( 'allows programmatic opening through the md-open attribute' , inject ( function ( ) {
70
- compileAndLink (
79
+ it ( 'allows programmatic opening through the md-open attribute' , inject ( function ( ) {
80
+ build (
71
81
'<md-fab-speed-dial md-open="isOpen"></md-fab-speed-dial>'
72
82
) ;
73
83
@@ -83,8 +93,8 @@ describe('<md-fab-speed-dial> directive', function() {
83
93
expect ( controller . isOpen ) . toBe ( false ) ;
84
94
} ) ) ;
85
95
86
- it ( 'properly finishes the fling animation' , inject ( function ( mdFabSpeedDialFlingAnimation ) {
87
- compileAndLink (
96
+ it ( 'properly finishes the fling animation' , inject ( function ( mdFabSpeedDialFlingAnimation ) {
97
+ build (
88
98
'<md-fab-speed-dial md-open="isOpen" class="md-fling">' +
89
99
' <md-fab-trigger><button></button></md-fab-trigger>' +
90
100
' <md-fab-actions><button></button></md-fab-actions>' +
@@ -101,8 +111,8 @@ describe('<md-fab-speed-dial> directive', function() {
101
111
expect ( removeDone ) . toHaveBeenCalled ( ) ;
102
112
} ) ) ;
103
113
104
- it ( 'properly finishes the scale animation' , inject ( function ( mdFabSpeedDialScaleAnimation ) {
105
- compileAndLink (
114
+ it ( 'properly finishes the scale animation' , inject ( function ( mdFabSpeedDialScaleAnimation ) {
115
+ build (
106
116
'<md-fab-speed-dial md-open="isOpen" class="md-fling">' +
107
117
' <md-fab-trigger><button></button></md-fab-trigger>' +
108
118
' <md-fab-actions><button></button></md-fab-actions>' +
@@ -119,4 +129,14 @@ describe('<md-fab-speed-dial> directive', function() {
119
129
expect ( removeDone ) . toHaveBeenCalled ( ) ;
120
130
} ) ) ;
121
131
132
+ function build ( template ) {
133
+ inject ( function ( $compile ) {
134
+ pageScope = $rootScope . $new ( ) ;
135
+ element = $compile ( template ) ( pageScope ) ;
136
+ controller = element . controller ( 'mdFabSpeedDial' ) ;
137
+
138
+ pageScope . $apply ( ) ;
139
+ } ) ;
140
+ }
141
+
122
142
} ) ;
0 commit comments