@@ -37,6 +37,17 @@ describe('ui-select tests', function() {
3737 } ) ;
3838
3939 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+
4051 beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ , _$injector_ ) {
4152 $rootScope = _$rootScope_ ;
4253 scope = $rootScope . $new ( ) ;
@@ -92,6 +103,7 @@ describe('ui-select tests', function() {
92103 if ( attrs . tagging !== undefined ) { attrsHtml += ' tagging="' + attrs . tagging + '"' ; }
93104 if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
94105 if ( attrs . title !== undefined ) { attrsHtml += ' title="' + attrs . title + '"' ; }
106+ if ( attrs . appendToBody != undefined ) { attrsHtml += ' append-to-body="' + attrs . appendToBody + '"' ; }
95107 }
96108
97109 return compileTemplate (
@@ -161,6 +173,12 @@ describe('ui-select tests', function() {
161173 scope . $digest ( ) ;
162174 } ;
163175
176+ function closeDropdown ( el ) {
177+ var $select = el . scope ( ) . $select ;
178+ $select . open = false ;
179+ scope . $digest ( ) ;
180+ }
181+
164182
165183 // Tests
166184
@@ -1791,4 +1809,57 @@ describe('ui-select tests', function() {
17911809 }
17921810 } ) ;
17931811 } ) ;
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+
17941865} ) ;
0 commit comments