1- describe ( '<md-fab-speed-dial> directive' , function ( ) {
2-
3- beforeEach ( module ( 'material.components.fabSpeedDial' ) ) ;
1+ describe ( '<md-fab-speed-dial> directive' , function ( ) {
42
53 var pageScope , element , controller ;
4+ var $rootScope , $animate , $timeout ;
65
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+ } ) ) ;
1612
17- it ( 'applies a class for each direction' , inject ( function ( ) {
18- compileAndLink (
13+ it ( 'applies a class for each direction' , inject ( function ( ) {
14+ build (
1915 '<md-fab-speed-dial md-direction="{{direction}}"></md-fab-speed-dial>'
2016 ) ;
2117
@@ -32,8 +28,8 @@ describe('<md-fab-speed-dial> directive', function() {
3228 expect ( element . hasClass ( 'md-right' ) ) . toBe ( true ) ;
3329 } ) ) ;
3430
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 (
3733 '<md-fab-speed-dial><md-fab-trigger><button></button></md-fab-trigger></md-fab-speed-dial>'
3834 ) ;
3935
@@ -42,32 +38,46 @@ describe('<md-fab-speed-dial> directive', function() {
4238 expect ( controller . isOpen ) . toBe ( true ) ;
4339 } ) ) ;
4440
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 (
4743 '<md-fab-speed-dial><md-fab-actions><button></button></md-fab-actions></md-fab-speed-dial>'
4844 ) ;
4945
5046 element . find ( 'button' ) . triggerHandler ( 'focus' ) ;
5147 pageScope . $digest ( ) ;
48+
5249 expect ( controller . isOpen ) . toBe ( true ) ;
5350 } ) ) ;
5451
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>'
5863 ) ;
5964
6065 element . find ( 'button' ) . triggerHandler ( 'focus' ) ;
6166 pageScope . $digest ( ) ;
67+
6268 expect ( controller . isOpen ) . toBe ( true ) ;
6369
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' ) ;
6574 pageScope . $digest ( ) ;
75+
6676 expect ( controller . isOpen ) . toBe ( false ) ;
6777 } ) ) ;
6878
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 (
7181 '<md-fab-speed-dial md-open="isOpen"></md-fab-speed-dial>'
7282 ) ;
7383
@@ -83,8 +93,8 @@ describe('<md-fab-speed-dial> directive', function() {
8393 expect ( controller . isOpen ) . toBe ( false ) ;
8494 } ) ) ;
8595
86- it ( 'properly finishes the fling animation' , inject ( function ( mdFabSpeedDialFlingAnimation ) {
87- compileAndLink (
96+ it ( 'properly finishes the fling animation' , inject ( function ( mdFabSpeedDialFlingAnimation ) {
97+ build (
8898 '<md-fab-speed-dial md-open="isOpen" class="md-fling">' +
8999 ' <md-fab-trigger><button></button></md-fab-trigger>' +
90100 ' <md-fab-actions><button></button></md-fab-actions>' +
@@ -101,8 +111,8 @@ describe('<md-fab-speed-dial> directive', function() {
101111 expect ( removeDone ) . toHaveBeenCalled ( ) ;
102112 } ) ) ;
103113
104- it ( 'properly finishes the scale animation' , inject ( function ( mdFabSpeedDialScaleAnimation ) {
105- compileAndLink (
114+ it ( 'properly finishes the scale animation' , inject ( function ( mdFabSpeedDialScaleAnimation ) {
115+ build (
106116 '<md-fab-speed-dial md-open="isOpen" class="md-fling">' +
107117 ' <md-fab-trigger><button></button></md-fab-trigger>' +
108118 ' <md-fab-actions><button></button></md-fab-actions>' +
@@ -119,4 +129,14 @@ describe('<md-fab-speed-dial> directive', function() {
119129 expect ( removeDone ) . toHaveBeenCalled ( ) ;
120130 } ) ) ;
121131
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+
122142} ) ;
0 commit comments