@@ -8,7 +8,7 @@ splitMoveTests('mouse', 'mousedown', 'mousemove', 'mouseup');
88// Wrapper to abstract over using touch events or mouse events.
99function splitMoveTests ( description , startEvent , moveEvent , endEvent ) {
1010 return describe ( 'Directive: uiLayout with ' + description + ' events' , function ( ) {
11- var element , scope , compile ,
11+ var element , scope , compile , $timeout ,
1212 validTemplate = '<div ui-layout><header ui-layout-container></header><footer ui-layout-container></footer></div>' ,
1313 defaultDividerSize = 10 ;
1414
@@ -29,9 +29,10 @@ function splitMoveTests(description, startEvent, moveEvent, endEvent) {
2929
3030 module ( 'ui.layout' ) ;
3131
32- inject ( function ( $rootScope , $compile ) {
32+ inject ( function ( $rootScope , $compile , _$timeout_ ) {
3333 scope = $rootScope . $new ( ) ;
3434 compile = $compile ;
35+ $timeout = _$timeout_ ;
3536 } ) ;
3637 } ) ;
3738
@@ -110,7 +111,7 @@ function splitMoveTests(description, startEvent, moveEvent, endEvent) {
110111
111112 it ( 'should not follow the ' + description + ' before ' + startEvent , function ( ) {
112113 var expectedPos = Math . floor ( ( element_bb . height - defaultDividerSize ) / 2 ) ;
113- expect ( Math . ceil ( parseFloat ( $splitbar [ 0 ] . style . top ) ) ) . toEqual ( expectedPos ) ; // Obvious...
114+ expect ( Math . ceil ( parseFloat ( $splitbar [ 0 ] . style . top ) ) ) . toEqual ( expectedPos ) ;
114115
115116 // Move without clicking on it
116117 browserTrigger ( $splitbar , moveEvent , { y : Math . random ( ) * element_bb . width } ) ;
@@ -149,11 +150,12 @@ function splitMoveTests(description, startEvent, moveEvent, endEvent) {
149150 } ) ;
150151
151152 it ( 'should toggle before' , function ( ) {
152- var expectedSize = Math . floor ( ( element_bb . height - defaultDividerSize ) / 2 ) ;
153+ var expectedAutosized = Math . floor ( ( element_bb . height - defaultDividerSize ) / 2 ) ;
154+
153155 var $header = element . children ( ) . eq ( 0 ) [ 0 ] ;
154156
155- expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedSize ) ;
156- expect ( $header . getBoundingClientRect ( ) . height ) . toEqual ( expectedSize ) ;
157+ expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedAutosized ) ;
158+ expect ( $header . getBoundingClientRect ( ) . height ) . toEqual ( expectedAutosized ) ;
157159
158160 browserTrigger ( toggleBeforeButton , 'click' ) ;
159161
@@ -163,28 +165,33 @@ function splitMoveTests(description, startEvent, moveEvent, endEvent) {
163165
164166 browserTrigger ( toggleBeforeButton , 'click' ) ;
165167
166- expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedSize ) ;
167- expect ( $header . getBoundingClientRect ( ) . height ) . toEqual ( expectedSize ) ;
168+ expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedAutosized ) ;
169+ expect ( $header . getBoundingClientRect ( ) . height ) . toEqual ( expectedAutosized ) ;
168170 expect ( toggleAfterButton . style . display ) . toBe ( 'inline' ) ;
169171 } ) ;
170172
171173 it ( 'should toggle after' , function ( ) {
172- var expectedSize = Math . floor ( ( element_bb . height - defaultDividerSize ) / 2 ) ;
173- var $footer = element . children ( ) . eq ( 2 ) [ 0 ] ;
174174
175- expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedSize ) ;
176- expect ( $footer . getBoundingClientRect ( ) . height ) . toEqual ( expectedSize ) ;
175+ var roundedHalf = Math . floor ( ( element_bb . height - defaultDividerSize ) / 2 ) ,
176+ expectedAutosized = roundedHalf ,
177+ expectedLastAutosized = roundedHalf ;
177178
178- browserTrigger ( toggleAfterButton , 'click' ) ;
179+ // add remainder to the last element when parent size is odd
180+ if ( element_bb . height % 2 === 1 ) {
181+ expectedLastAutosized += 1 ;
182+ }
183+ var $footer = element . children ( ) . eq ( 2 ) [ 0 ] ;
184+ expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedAutosized ) ;
185+ expect ( $footer . getBoundingClientRect ( ) . height ) . toEqual ( expectedLastAutosized ) ;
179186
187+ browserTrigger ( toggleAfterButton , 'click' ) ;
180188 expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( element_bb . height - defaultDividerSize ) ;
181189 expect ( $footer . getBoundingClientRect ( ) . height ) . toEqual ( 0 ) ;
182190 expect ( toggleBeforeButton . style . display ) . toBe ( 'none' ) ;
183191
184192 browserTrigger ( toggleAfterButton , 'click' ) ;
185-
186- expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedSize ) ;
187- expect ( $footer . getBoundingClientRect ( ) . height ) . toEqual ( expectedSize ) ;
193+ expect ( parseInt ( $splitbar [ 0 ] . style . top ) ) . toEqual ( expectedAutosized ) ;
194+ expect ( $footer . getBoundingClientRect ( ) . height ) . toEqual ( expectedLastAutosized ) ;
188195 expect ( toggleBeforeButton . style . display ) . toBe ( 'inline' ) ;
189196 } ) ;
190197 } ) ;
0 commit comments