@@ -37,6 +37,17 @@ describe('ui-select tests', function() {
37
37
} ) ;
38
38
39
39
beforeEach ( module ( 'ngSanitize' , 'ui.select' , 'wrapperDirective' ) ) ;
40
+
41
+ beforeEach ( function ( ) {
42
+ module ( function ( $provide ) {
43
+ $provide . factory ( 'uisOffset' , function ( ) {
44
+ return function ( el ) {
45
+ return { top : 100 , left : 200 , width : 300 , height : 400 } ;
46
+ } ;
47
+ } ) ;
48
+ } ) ;
49
+ } ) ;
50
+
40
51
beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ , _$injector_ ) {
41
52
$rootScope = _$rootScope_ ;
42
53
scope = $rootScope . $new ( ) ;
@@ -92,6 +103,7 @@ describe('ui-select tests', function() {
92
103
if ( attrs . tagging !== undefined ) { attrsHtml += ' tagging="' + attrs . tagging + '"' ; }
93
104
if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
94
105
if ( attrs . title !== undefined ) { attrsHtml += ' title="' + attrs . title + '"' ; }
106
+ if ( attrs . appendToBody != undefined ) { attrsHtml += ' append-to-body="' + attrs . appendToBody + '"' ; }
95
107
}
96
108
97
109
return compileTemplate (
@@ -161,6 +173,12 @@ describe('ui-select tests', function() {
161
173
scope . $digest ( ) ;
162
174
} ;
163
175
176
+ function closeDropdown ( el ) {
177
+ var $select = el . scope ( ) . $select ;
178
+ $select . open = false ;
179
+ scope . $digest ( ) ;
180
+ }
181
+
164
182
165
183
// Tests
166
184
@@ -1791,4 +1809,57 @@ describe('ui-select tests', function() {
1791
1809
}
1792
1810
} ) ;
1793
1811
} ) ;
1812
+
1813
+ describe ( 'select with the append to body option' , function ( ) {
1814
+ var body ;
1815
+
1816
+ beforeEach ( inject ( function ( $document ) {
1817
+ body = $document . find ( 'body' ) [ 0 ] ;
1818
+ } ) ) ;
1819
+
1820
+ it ( 'should only be moved to the body when the appendToBody option is true' , function ( ) {
1821
+ var el = createUiSelect ( { appendToBody : false } ) ;
1822
+ openDropdown ( el ) ;
1823
+ expect ( el . parent ( ) [ 0 ] ) . not . toBe ( body ) ;
1824
+ } ) ;
1825
+
1826
+ it ( 'should be moved to the body when the appendToBody is true in uiSelectConfig' , inject ( function ( uiSelectConfig ) {
1827
+ uiSelectConfig . appendToBody = true ;
1828
+ var el = createUiSelect ( ) ;
1829
+ openDropdown ( el ) ;
1830
+ expect ( el . parent ( ) [ 0 ] ) . toBe ( body ) ;
1831
+ } ) ) ;
1832
+
1833
+ it ( 'should be moved to the body when opened' , function ( ) {
1834
+ var el = createUiSelect ( { appendToBody : true } ) ;
1835
+ openDropdown ( el ) ;
1836
+ expect ( el . parent ( ) [ 0 ] ) . toBe ( body ) ;
1837
+ closeDropdown ( el ) ;
1838
+ expect ( el . parent ( ) [ 0 ] ) . not . toBe ( body ) ;
1839
+ } ) ;
1840
+
1841
+ it ( 'should remove itself from the body when the scope is destroyed' , function ( ) {
1842
+ var el = createUiSelect ( { appendToBody : true } ) ;
1843
+ openDropdown ( el ) ;
1844
+ expect ( el . parent ( ) [ 0 ] ) . toBe ( body ) ;
1845
+ el . scope ( ) . $destroy ( ) ;
1846
+ expect ( el . parent ( ) [ 0 ] ) . not . toBe ( body ) ;
1847
+ } ) ;
1848
+
1849
+ it ( 'should have specific position and dimensions' , function ( ) {
1850
+ var el = createUiSelect ( { appendToBody : true } ) ;
1851
+ var originalWidth = el . css ( 'width' ) ;
1852
+ openDropdown ( el ) ;
1853
+ expect ( el . css ( 'position' ) ) . toBe ( 'absolute' ) ;
1854
+ expect ( el . css ( 'top' ) ) . toBe ( '100px' ) ;
1855
+ expect ( el . css ( 'left' ) ) . toBe ( '200px' ) ;
1856
+ expect ( el . css ( 'width' ) ) . toBe ( '300px' ) ;
1857
+ closeDropdown ( el ) ;
1858
+ expect ( el . css ( 'position' ) ) . toBe ( '' ) ;
1859
+ expect ( el . css ( 'top' ) ) . toBe ( '' ) ;
1860
+ expect ( el . css ( 'left' ) ) . toBe ( '' ) ;
1861
+ expect ( el . css ( 'width' ) ) . toBe ( originalWidth ) ;
1862
+ } ) ;
1863
+ } ) ;
1864
+
1794
1865
} ) ;
0 commit comments