@@ -6,9 +6,23 @@ describe('$uibModal', function () {
6
6
beforeEach ( module ( 'ui.bootstrap.modal' ) ) ;
7
7
beforeEach ( module ( 'uib/template/modal/backdrop.html' ) ) ;
8
8
beforeEach ( module ( 'uib/template/modal/window.html' ) ) ;
9
- beforeEach ( module ( function ( _$controllerProvider_ , _$uibModalProvider_ ) {
9
+ beforeEach ( module ( function ( _$controllerProvider_ , _$uibModalProvider_ , $compileProvider ) {
10
10
$controllerProvider = _$controllerProvider_ ;
11
11
$uibModalProvider = _$uibModalProvider_ ;
12
+ $compileProvider . directive ( 'parentDirective' , function ( ) {
13
+ return {
14
+ controller : function ( ) {
15
+ this . text = 'foo' ;
16
+ }
17
+ } ;
18
+ } ) . directive ( 'childDirective' , function ( ) {
19
+ return {
20
+ require : '^parentDirective' ,
21
+ link : function ( scope , elem , attrs , ctrl ) {
22
+ scope . text = ctrl . text ;
23
+ }
24
+ } ;
25
+ } ) ;
12
26
} ) ) ;
13
27
14
28
beforeEach ( inject ( function ( _$animate_ , _$rootScope_ , _$document_ , _$compile_ , _$templateCache_ , _$timeout_ , _$q_ , _$uibModal_ , _$uibModalStack_ ) {
@@ -144,10 +158,12 @@ describe('$uibModal', function () {
144
158
element . trigger ( e ) ;
145
159
}
146
160
147
- function open ( modalOptions ) {
161
+ function open ( modalOptions , noFlush ) {
148
162
var modal = $uibModal . open ( modalOptions ) ;
149
163
$rootScope . $digest ( ) ;
150
- $timeout . flush ( 0 ) ;
164
+ if ( ! noFlush ) {
165
+ $animate . flush ( ) ;
166
+ }
151
167
return modal ;
152
168
}
153
169
@@ -376,9 +392,8 @@ describe('$uibModal', function () {
376
392
377
393
it ( 'should expose a promise linked to the templateUrl / resolve promises and reject it if needed' , function ( ) {
378
394
var modal = open ( { template : '<div>Content</div>' , resolve : {
379
- ok : function ( ) { return $q . reject ( 'ko' ) ; }
380
- } }
381
- ) ;
395
+ ok : function ( ) { return $q . reject ( 'ko' ) ; }
396
+ } } , true ) ;
382
397
expect ( modal . opened ) . toBeRejectedWith ( 'ko' ) ;
383
398
} ) ;
384
399
@@ -633,10 +648,11 @@ describe('$uibModal', function () {
633
648
value : function ( ) {
634
649
return $timeout ( function ( ) { return 'Promise' ; } , 100 ) ;
635
650
}
636
- } ) ) ;
651
+ } ) , true ) ;
637
652
expect ( $document ) . toHaveModalsOpen ( 0 ) ;
638
653
639
654
$timeout . flush ( ) ;
655
+ $animate . flush ( ) ;
640
656
expect ( $document ) . toHaveModalOpenWithContent ( 'Promise' , 'div' ) ;
641
657
} ) ;
642
658
@@ -647,7 +663,7 @@ describe('$uibModal', function () {
647
663
value : function ( ) {
648
664
return deferred . promise ;
649
665
}
650
- } ) ) ;
666
+ } ) , true ) ;
651
667
expect ( $document ) . toHaveModalsOpen ( 0 ) ;
652
668
653
669
deferred . reject ( 'error in test' ) ;
@@ -858,6 +874,8 @@ describe('$uibModal', function () {
858
874
expect ( $document . find ( 'section' ) . children ( 'div.modal' ) . length ) . toBe ( 0 ) ;
859
875
open ( { template : '<div>Content</div>' , appendTo : element } ) ;
860
876
expect ( $document . find ( 'section' ) . children ( 'div.modal' ) . length ) . toBe ( 1 ) ;
877
+
878
+ element . remove ( ) ;
861
879
} ) ;
862
880
863
881
it ( 'should throw error if appendTo element is not found' , function ( ) {
@@ -874,6 +892,17 @@ describe('$uibModal', function () {
874
892
dismiss ( modal ) ;
875
893
expect ( $document ) . toHaveModalsOpen ( 0 ) ;
876
894
} ) ;
895
+
896
+ it ( 'should allow requiring parent directive from appendTo target' , function ( ) {
897
+ var element = $compile ( '<section parent-directive>Some content</section>' ) ( $rootScope ) ;
898
+ angular . element ( document . body ) . append ( element ) ;
899
+
900
+ open ( { template : '<div child-directive>{{text}}</div>' , appendTo : element } ) ;
901
+ $animate . flush ( ) ;
902
+ expect ( $document . find ( '[child-directive]' ) . text ( ) ) . toBe ( 'foo' ) ;
903
+
904
+ element . remove ( ) ;
905
+ } ) ;
877
906
} ) ;
878
907
879
908
describe ( 'openedClass' , function ( ) {
@@ -1008,7 +1037,7 @@ describe('$uibModal', function () {
1008
1037
expect ( $document ) . toHaveModalsOpen ( 2 ) ;
1009
1038
} ) ;
1010
1039
1011
- it ( 'multiple modals should not interfere with default options' , function ( ) {
1040
+ it ( 'should not interfere with default options' , function ( ) {
1012
1041
var modal1 = open ( { template : '<div>Modal1</div>' , backdrop : false } ) ;
1013
1042
var modal2 = open ( { template : '<div>Modal2</div>' } ) ;
1014
1043
$rootScope . $digest ( ) ;
@@ -1084,7 +1113,7 @@ describe('$uibModal', function () {
1084
1113
} else {
1085
1114
expected += i ;
1086
1115
}
1087
- ds [ x ] = { index :i , deferred :$q . defer ( ) , reject :reject } ;
1116
+ ds [ x ] = { index : i , deferred : $q . defer ( ) , reject : reject } ;
1088
1117
1089
1118
var scope = $rootScope . $new ( ) ;
1090
1119
scope . index = i ;
@@ -1094,17 +1123,17 @@ describe('$uibModal', function () {
1094
1123
resolve : {
1095
1124
x : function ( ) { return ds [ x ] . deferred . promise ; }
1096
1125
}
1097
- } ) . opened . then ( function ( ) {
1126
+ } , true ) . opened . then ( function ( ) {
1098
1127
expect ( $uibModalStack . getTop ( ) . value . modalScope . index ) . toEqual ( i ) ;
1099
1128
actual += i ;
1100
1129
} ) ;
1101
1130
} ) ;
1102
1131
1103
1132
angular . forEach ( ds , function ( d , i ) {
1104
1133
if ( d . reject ) {
1105
- d . deferred . reject ( 'rejected:' + d . index ) ;
1134
+ d . deferred . reject ( 'rejected:' + d . index ) ;
1106
1135
} else {
1107
- d . deferred . resolve ( 'resolved:' + d . index ) ;
1136
+ d . deferred . resolve ( 'resolved:' + d . index ) ;
1108
1137
}
1109
1138
$rootScope . $digest ( ) ;
1110
1139
} ) ;
@@ -1138,13 +1167,39 @@ describe('$uibModal', function () {
1138
1167
_permute ( 0 ) ;
1139
1168
}
1140
1169
1141
- permute ( 2 , function ( a ) { test ( a ) ; } ) ;
1142
- permute ( 2 , function ( a ) { test ( a . map ( function ( x , i ) { return { reject :x } ; } ) ) ; } ) ;
1143
- permute ( 2 , function ( a ) { test ( a . map ( function ( x , i ) { return i === 0 ? { reject :x } : x ; } ) ) ; } ) ;
1144
- permute ( 3 , function ( a ) { test ( a ) ; } ) ;
1145
- permute ( 3 , function ( a ) { test ( a . map ( function ( x , i ) { return { reject :x } ; } ) ) ; } ) ;
1146
- permute ( 3 , function ( a ) { test ( a . map ( function ( x , i ) { return i === 0 ? { reject :x } : x ; } ) ) ; } ) ;
1147
- permute ( 3 , function ( a ) { test ( a . map ( function ( x , i ) { return i === 1 ? { reject :x } : x ; } ) ) ; } ) ;
1170
+ permute ( 2 , function ( a ) {
1171
+ test ( a ) ;
1172
+ } ) ;
1173
+ permute ( 2 , function ( a ) {
1174
+ test ( a . map ( function ( x , i ) {
1175
+ return { reject :x } ;
1176
+ } ) ) ;
1177
+ } ) ;
1178
+ permute ( 2 , function ( a ) {
1179
+ test ( a . map ( function ( x , i ) {
1180
+ return i === 0 ? { reject : x } : x ;
1181
+ } ) ) ;
1182
+ } ) ;
1183
+ permute ( 3 , function ( a ) {
1184
+ test ( a ) ;
1185
+ } ) ;
1186
+ permute ( 3 , function ( a ) {
1187
+ test ( a . map ( function ( x , i ) {
1188
+ return { reject : x } ;
1189
+ } ) ) ;
1190
+ } ) ;
1191
+ permute ( 3 , function ( a ) {
1192
+ test ( a . map ( function ( x , i ) {
1193
+ return i === 0 ? { reject : x } : x ;
1194
+ } ) ) ;
1195
+ } ) ;
1196
+ permute ( 3 , function ( a ) {
1197
+ test ( a . map ( function ( x , i ) {
1198
+ return i === 1 ? { reject : x } : x ;
1199
+ } ) ) ;
1200
+ } ) ;
1201
+
1202
+ $animate . flush ( ) ;
1148
1203
} ) ;
1149
1204
1150
1205
it ( 'should have top class only on top window' , function ( ) {
@@ -1213,6 +1268,7 @@ describe('$uibModal', function () {
1213
1268
var called ;
1214
1269
1215
1270
called = false ;
1271
+
1216
1272
close ( open ( {
1217
1273
template : '<div>content</div>' ,
1218
1274
controller : function ( $scope ) {
0 commit comments