1
1
describe ( '<md-select>' , function ( ) {
2
- var attachedElements = [ ] ;
2
+ var attachedElements = [ ] ,
3
+ body ;
3
4
4
5
beforeEach ( module ( 'material.components.input' ) ) ;
5
6
beforeEach ( module ( 'material.components.select' ) ) ;
6
7
8
+ beforeEach ( inject ( function ( $document ) {
9
+ body = $document [ 0 ] . body ;
10
+ } ) ) ;
11
+
12
+ afterEach ( inject ( function ( $document ) {
13
+ var body = $document [ 0 ] . body ;
14
+ var children = body . querySelectorAll ( '.md-select-menu-container' ) ;
15
+ for ( var i = 0 ; i < children . length ; i ++ ) {
16
+ angular . element ( children [ i ] ) . remove ( ) ;
17
+ }
18
+ } ) ) ;
19
+
7
20
afterEach ( inject ( function ( $document ) {
8
21
attachedElements . forEach ( function ( element ) {
9
22
element . remove ( ) ;
@@ -39,7 +52,7 @@ describe('<md-select>', function() {
39
52
var select = setupSelect ( 'ng-model="val", md-container-class="test"' ) . find ( 'md-select' ) ;
40
53
openSelect ( select ) ;
41
54
42
- var container = select [ 0 ] . querySelector ( '.md-select-menu-container' ) ;
55
+ var container = body . querySelector ( '.md-select-menu-container' ) ;
43
56
expect ( container ) . toBeTruthy ( ) ;
44
57
expect ( container . classList . contains ( 'test' ) ) . toBe ( true ) ;
45
58
} ) ) ;
@@ -720,7 +733,7 @@ describe('<md-select>', function() {
720
733
openSelect ( el ) ;
721
734
expect ( el . attr ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
722
735
723
- var selectMenu = el . find ( 'md-select-menu' ) ;
736
+ var selectMenu = $document . find ( 'md-select-menu' ) ;
724
737
pressKey ( selectMenu , 27 ) ;
725
738
waitForSelectClose ( ) ;
726
739
@@ -793,7 +806,7 @@ describe('<md-select>', function() {
793
806
var el = setupSelect ( 'ng-model="someVal"' , [ 1 , 2 , 3 ] ) . find ( 'md-select' ) ;
794
807
openSelect ( el ) ;
795
808
expectSelectOpen ( el ) ;
796
- var selectMenu = angular . element ( el . find ( 'md-select-menu' ) ) ;
809
+ var selectMenu = $document . find ( 'md-select-menu' ) ;
797
810
expect ( selectMenu . length ) . toBe ( 1 ) ;
798
811
pressKey ( selectMenu , 27 ) ;
799
812
waitForSelectClose ( ) ;
@@ -906,8 +919,8 @@ describe('<md-select>', function() {
906
919
function clickOption ( select , index ) {
907
920
inject ( function ( $rootScope , $document ) {
908
921
expectSelectOpen ( select ) ;
909
- var openMenu = select . find ( 'md-select-menu' ) ;
910
- var opt = angular . element ( select . find ( 'md-option' ) [ index ] ) . find ( 'div' ) [ 0 ] ;
922
+ var openMenu = $document . find ( 'md-select-menu' ) ;
923
+ var opt = angular . element ( openMenu . find ( 'md-option' ) [ index ] ) . find ( 'div' ) [ 0 ] ;
911
924
912
925
if ( ! opt ) throw Error ( 'Could not find option at index: ' + index ) ;
913
926
var target = angular . element ( opt ) ;
@@ -925,14 +938,16 @@ describe('<md-select>', function() {
925
938
926
939
function expectSelectClosed ( element ) {
927
940
element = angular . element ( element ) ;
928
- var menu = angular . element ( element [ 0 ] . querySelector ( '.md-select-menu-container' ) ) ;
929
- expect ( menu . hasClass ( 'md-active' ) ) . toBe ( false ) ;
930
- expect ( menu . attr ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
941
+ var menu = angular . element ( body . querySelector ( '.md-select-menu-container' ) ) ;
942
+ if ( menu . length ) {
943
+ expect ( menu . hasClass ( 'md-active' ) ) . toBe ( false ) ;
944
+ expect ( menu . attr ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
945
+ }
931
946
}
932
947
933
948
function expectSelectOpen ( element ) {
934
949
element = angular . element ( element ) ;
935
- var menu = angular . element ( element [ 0 ] . querySelector ( '.md-select-menu-container' ) ) ;
950
+ var menu = angular . element ( body . querySelector ( '.md-select-menu-container' ) ) ;
936
951
expect ( menu . hasClass ( 'md-active' ) ) . toBe ( true ) ;
937
952
expect ( menu . attr ( 'aria-hidden' ) ) . toBe ( 'false' ) ;
938
953
}
0 commit comments