@@ -735,4 +735,45 @@ $(function () {
735
735
done ( )
736
736
} ) . bootstrapModal ( 'show' )
737
737
} )
738
+
739
+ QUnit . test ( 'should enforce focus' , function ( assert ) {
740
+ assert . expect ( 4 )
741
+ var done = assert . async ( )
742
+
743
+ var $modal = $ ( [
744
+ '<div id="modal-test" data-show="false">' ,
745
+ ' <div class="modal-dialog">' ,
746
+ ' <div class="modal-content">' ,
747
+ ' <div class="modal-body" />' ,
748
+ ' </div>' ,
749
+ ' </div>' ,
750
+ '</div>'
751
+ ] . join ( '' ) )
752
+ . bootstrapModal ( )
753
+ . appendTo ( '#qunit-fixture' )
754
+
755
+ var modal = $modal . data ( 'bs.modal' )
756
+ var spy = sinon . spy ( modal , '_enforceFocus' )
757
+ var spyDocOff = sinon . spy ( $ ( document ) , 'off' )
758
+ var spyDocOn = sinon . spy ( $ ( document ) , 'on' )
759
+
760
+ $modal . one ( 'shown.bs.modal' , function ( ) {
761
+ assert . ok ( spy . called , '_enforceFocus called' )
762
+ assert . ok ( spyDocOff . withArgs ( 'focusin.bs.modal' ) )
763
+ assert . ok ( spyDocOn . withArgs ( 'focusin.bs.modal' ) )
764
+
765
+ var spyFocus = sinon . spy ( modal . _element , 'focus' )
766
+ var event = $ . Event ( 'focusin' , {
767
+ target : $ ( '#qunit-fixture' ) [ 0 ]
768
+ } )
769
+
770
+ $ ( document ) . one ( 'focusin' , function ( ) {
771
+ assert . ok ( spyFocus . called )
772
+ done ( )
773
+ } )
774
+
775
+ $ ( document ) . trigger ( event )
776
+ } )
777
+ . bootstrapModal ( 'show' )
778
+ } )
738
779
} )
0 commit comments