@@ -213,12 +213,16 @@ describe('$uibModal', function () {
213
213
element . trigger ( e ) ;
214
214
}
215
215
216
- function open ( modalOptions , noFlush ) {
216
+ function open ( modalOptions , noFlush , noDigest ) {
217
217
var modal = $uibModal . open ( modalOptions ) ;
218
- $rootScope . $digest ( ) ;
219
- if ( ! noFlush ) {
220
- $animate . flush ( ) ;
218
+
219
+ if ( ! noDigest ) {
220
+ $rootScope . $digest ( ) ;
221
+ if ( ! noFlush ) {
222
+ $animate . flush ( ) ;
223
+ }
221
224
}
225
+
222
226
return modal ;
223
227
}
224
228
@@ -261,6 +265,46 @@ describe('$uibModal', function () {
261
265
expect ( $document ) . not . toHaveBackdrop ( ) ;
262
266
} ) ;
263
267
268
+ it ( 'should compile modal before inserting into DOM' , function ( ) {
269
+ var topModal ;
270
+ var modalInstance = {
271
+ result : $q . defer ( ) ,
272
+ opened : $q . defer ( ) ,
273
+ closed : $q . defer ( ) ,
274
+ rendered : $q . defer ( ) ,
275
+ close : function ( result ) {
276
+ return $uibModalStack . close ( modalInstance , result ) ;
277
+ } ,
278
+ dismiss : function ( reason ) {
279
+ return $uibModalStack . dismiss ( modalInstance , reason ) ;
280
+ }
281
+ } ;
282
+ var expectedText = 'test' ;
283
+
284
+ $uibModalStack . open ( modalInstance , {
285
+ appendTo : angular . element ( document . body ) ,
286
+ scope : $rootScope . $new ( ) ,
287
+ deferred : modalInstance . result ,
288
+ renderDeferred : modalInstance . rendered ,
289
+ closedDeferred : modalInstance . closed ,
290
+ content : '<div id="test">{{\'' + expectedText + '\'}}</div>'
291
+ } ) ;
292
+
293
+ topModal = $uibModalStack . getTop ( ) ;
294
+
295
+ expect ( topModal . value . modalDomEl . find ( '#test' ) . length ) . toEqual ( 0 ) ;
296
+ expect ( angular . element ( '#test' ) . length ) . toEqual ( 0 ) ;
297
+
298
+ $rootScope . $digest ( ) ;
299
+
300
+ expect ( topModal . value . modalDomEl . find ( '#test' ) . text ( ) ) . toEqual ( expectedText ) ;
301
+ expect ( angular . element ( '#test' ) . text ( ) ) . toEqual ( expectedText ) ;
302
+
303
+ $animate . flush ( ) ;
304
+
305
+ close ( modalInstance , 'closing in test' , true ) ;
306
+ } ) ;
307
+
264
308
it ( 'should not throw an exception on a second dismiss' , function ( ) {
265
309
var modal = open ( { template : '<div>Content</div>' } ) ;
266
310
@@ -364,7 +408,6 @@ describe('$uibModal', function () {
364
408
expect ( document . activeElement . tagName ) . toBe ( 'A' ) ;
365
409
366
410
var modal = open ( { template : '<div>Content<button>inside modal</button></div>' } ) ;
367
- $animate . flush ( ) ;
368
411
$rootScope . $digest ( ) ;
369
412
expect ( document . activeElement . tagName ) . toBe ( 'DIV' ) ;
370
413
expect ( $document ) . toHaveModalsOpen ( 1 ) ;
@@ -389,7 +432,6 @@ describe('$uibModal', function () {
389
432
expect ( document . activeElement . tagName ) . toBe ( 'A' ) ;
390
433
391
434
var modal = open ( { template : '<div>Content</div>' } ) ;
392
- $animate . flush ( ) ;
393
435
$rootScope . $digest ( ) ;
394
436
expect ( document . activeElement . tagName ) . toBe ( 'DIV' ) ;
395
437
expect ( $document ) . toHaveModalsOpen ( 1 ) ;
@@ -468,7 +510,6 @@ describe('$uibModal', function () {
468
510
it ( 'should focus on the element that has autofocus attribute when the modal is open/reopen and the animations have finished' , function ( ) {
469
511
function openAndCloseModalWithAutofocusElement ( ) {
470
512
var modal = open ( { template : '<div><input type="text" id="auto-focus-element" autofocus></div>' } ) ;
471
- $animate . flush ( ) ;
472
513
$rootScope . $digest ( ) ;
473
514
expect ( angular . element ( '#auto-focus-element' ) ) . toHaveFocus ( ) ;
474
515
@@ -485,7 +526,6 @@ describe('$uibModal', function () {
485
526
function openAndCloseModalWithAutofocusElement ( ) {
486
527
487
528
var modal = open ( { template : '<div><input type="text" id="auto-focus-element" autofocus><input type="text" id="pre-focus-element" focus-me></div>' } ) ;
488
- $animate . flush ( ) ;
489
529
$rootScope . $digest ( ) ;
490
530
expect ( angular . element ( '#auto-focus-element' ) ) . not . toHaveFocus ( ) ;
491
531
expect ( angular . element ( '#pre-focus-element' ) ) . toHaveFocus ( ) ;
@@ -501,11 +541,11 @@ describe('$uibModal', function () {
501
541
502
542
it ( 'should wait until the in animation is finished before attempting to focus the modal or autofocus element' , function ( ) {
503
543
function openAndCloseModalWithAutofocusElement ( ) {
504
- var modal = open ( { template : '<div><input type="text" id="auto-focus-element" autofocus></div>' } ) ;
544
+ var modal = open ( { template : '<div><input type="text" id="auto-focus-element" autofocus></div>' } , true , true ) ;
505
545
expect ( angular . element ( '#auto-focus-element' ) ) . not . toHaveFocus ( ) ;
506
546
507
- $animate . flush ( ) ;
508
547
$rootScope . $digest ( ) ;
548
+ $animate . flush ( ) ;
509
549
510
550
expect ( angular . element ( '#auto-focus-element' ) ) . toHaveFocus ( ) ;
511
551
@@ -521,11 +561,11 @@ describe('$uibModal', function () {
521
561
element . focus ( ) ;
522
562
expect ( document . activeElement . tagName ) . toBe ( 'A' ) ;
523
563
524
- var modal = open ( { template : '<div><input type="text"></div>' } ) ;
564
+ var modal = open ( { template : '<div><input type="text"></div>' } , true , true ) ;
525
565
expect ( document . activeElement . tagName ) . toBe ( 'A' ) ;
526
566
527
- $animate . flush ( ) ;
528
567
$rootScope . $digest ( ) ;
568
+ $animate . flush ( ) ;
529
569
530
570
expect ( document . activeElement . tagName ) . toBe ( 'DIV' ) ;
531
571
@@ -788,7 +828,6 @@ describe('$uibModal', function () {
788
828
expect ( $document ) . toHaveModalsOpen ( 0 ) ;
789
829
790
830
$timeout . flush ( ) ;
791
- $animate . flush ( ) ;
792
831
expect ( $document ) . toHaveModalOpenWithContent ( 'Promise' , 'div' ) ;
793
832
} ) ;
794
833
@@ -886,14 +925,12 @@ describe('$uibModal', function () {
886
925
887
926
it ( 'should contain backdrop in classes on each modal opening' , function ( ) {
888
927
var modal = open ( { template : '<div>With backdrop</div>' } ) ;
889
- $animate . flush ( ) ;
890
928
var backdropEl = $document . find ( 'body > div.modal-backdrop' ) ;
891
929
expect ( backdropEl ) . toHaveClass ( 'in' ) ;
892
930
893
931
dismiss ( modal ) ;
894
932
895
933
modal = open ( { template : '<div>With backdrop</div>' } ) ;
896
- $animate . flush ( ) ;
897
934
backdropEl = $document . find ( 'body > div.modal-backdrop' ) ;
898
935
expect ( backdropEl ) . toHaveClass ( 'in' ) ;
899
936
@@ -1031,7 +1068,6 @@ describe('$uibModal', function () {
1031
1068
angular . element ( document . body ) . append ( element ) ;
1032
1069
1033
1070
open ( { template : '<div child-directive>{{text}}</div>' , appendTo : element } ) ;
1034
- $animate . flush ( ) ;
1035
1071
expect ( $document . find ( '[child-directive]' ) . text ( ) ) . toBe ( 'foo' ) ;
1036
1072
1037
1073
element . remove ( ) ;
@@ -1050,8 +1086,6 @@ describe('$uibModal', function () {
1050
1086
template : '<div>dummy modal</div>'
1051
1087
} ) ;
1052
1088
1053
- $animate . flush ( ) ;
1054
-
1055
1089
expect ( body ) . toHaveClass ( 'modal-open' ) ;
1056
1090
} ) ;
1057
1091
@@ -1061,8 +1095,6 @@ describe('$uibModal', function () {
1061
1095
openedClass : 'foo'
1062
1096
} ) ;
1063
1097
1064
- $animate . flush ( ) ;
1065
-
1066
1098
expect ( body ) . toHaveClass ( 'foo' ) ;
1067
1099
expect ( body ) . not . toHaveClass ( 'modal-open' ) ;
1068
1100
} ) ;
@@ -1073,8 +1105,6 @@ describe('$uibModal', function () {
1073
1105
openedClass : 'foo'
1074
1106
} ) ;
1075
1107
1076
- $animate . flush ( ) ;
1077
-
1078
1108
expect ( body ) . toHaveClass ( 'foo' ) ;
1079
1109
1080
1110
close ( modal ) ;
@@ -1088,8 +1118,6 @@ describe('$uibModal', function () {
1088
1118
openedClass : 'foo'
1089
1119
} ) ;
1090
1120
1091
- $animate . flush ( ) ;
1092
-
1093
1121
expect ( body ) . toHaveClass ( 'foo' ) ;
1094
1122
expect ( body ) . not . toHaveClass ( 'modal-open' ) ;
1095
1123
@@ -1098,8 +1126,6 @@ describe('$uibModal', function () {
1098
1126
openedClass : 'bar'
1099
1127
} ) ;
1100
1128
1101
- $animate . flush ( ) ;
1102
-
1103
1129
expect ( body ) . toHaveClass ( 'foo' ) ;
1104
1130
expect ( body ) . toHaveClass ( 'bar' ) ;
1105
1131
expect ( body ) . not . toHaveClass ( 'modal-open' ) ;
@@ -1109,8 +1135,6 @@ describe('$uibModal', function () {
1109
1135
openedClass : 'foo'
1110
1136
} ) ;
1111
1137
1112
- $animate . flush ( ) ;
1113
-
1114
1138
expect ( body ) . toHaveClass ( 'foo' ) ;
1115
1139
expect ( body ) . toHaveClass ( 'bar' ) ;
1116
1140
expect ( body ) . not . toHaveClass ( 'modal-open' ) ;
@@ -1232,11 +1256,9 @@ describe('$uibModal', function () {
1232
1256
expect ( body ) . not . toHaveClass ( 'modal-open' ) ;
1233
1257
1234
1258
var modal1 = open ( { template : '<div>Content1</div>' } ) ;
1235
- $animate . flush ( ) ;
1236
1259
expect ( body ) . toHaveClass ( 'modal-open' ) ;
1237
1260
1238
1261
var modal2 = open ( { template : '<div>Content1</div>' } ) ;
1239
- $animate . flush ( ) ;
1240
1262
expect ( body ) . toHaveClass ( 'modal-open' ) ;
1241
1263
1242
1264
dismiss ( modal1 ) ;
@@ -1254,14 +1276,12 @@ describe('$uibModal', function () {
1254
1276
expect ( document . activeElement . tagName ) . toBe ( 'A' ) ;
1255
1277
1256
1278
var modal1 = open ( { template : '<div>Modal1<button id="focus">inside modal1</button></div>' } ) ;
1257
- $animate . flush ( ) ;
1258
1279
$rootScope . $digest ( ) ;
1259
1280
document . getElementById ( 'focus' ) . focus ( ) ;
1260
1281
expect ( document . activeElement . tagName ) . toBe ( 'BUTTON' ) ;
1261
1282
expect ( $document ) . toHaveModalsOpen ( 1 ) ;
1262
1283
1263
1284
var modal2 = open ( { template : '<div>Modal2</div>' } ) ;
1264
- $animate . flush ( ) ;
1265
1285
$rootScope . $digest ( ) ;
1266
1286
expect ( document . activeElement . tagName ) . toBe ( 'DIV' ) ;
1267
1287
expect ( $document ) . toHaveModalsOpen ( 2 ) ;
0 commit comments