@@ -338,6 +338,40 @@ describe('md-date-picker', function() {
338
338
document . body . removeChild ( element ) ;
339
339
} ) ;
340
340
341
+ it ( 'should adjust the pane position if it would go off-screen if body is not scrollable' ,
342
+ function ( ) {
343
+ // Make the body super huge and scroll halfway down.
344
+ var body = document . body ;
345
+ var superLongElement = document . createElement ( 'div' ) ;
346
+ superLongElement . style . height = '10000px' ;
347
+ superLongElement . style . width = '1px' ;
348
+ body . appendChild ( superLongElement ) ;
349
+ body . scrollTop = 700 ;
350
+
351
+ // Absolutely position the picker near (say ~30px) the edge of the viewport.
352
+ element . style . position = 'absolute' ;
353
+ element . style . top = ( document . body . scrollTop + window . innerHeight - 30 ) + 'px' ;
354
+ element . style . left = '0' ;
355
+ body . appendChild ( element ) ;
356
+
357
+ // Make the body non-scrollable.
358
+ var previousBodyOverflow = body . style . overflow ;
359
+ body . style . overflow = 'hidden' ;
360
+
361
+ // Open the pane.
362
+ element . querySelector ( 'md-button' ) . click ( ) ;
363
+ $timeout . flush ( ) ;
364
+
365
+ // Expect that the pane is on-screen.
366
+ var paneRect = controller . calendarPane . getBoundingClientRect ( ) ;
367
+ expect ( paneRect . bottom ) . toBeLessThan ( window . innerHeight + 1 ) ;
368
+ body . removeChild ( superLongElement ) ;
369
+
370
+ // Restore body to pre-test state.
371
+ body . removeChild ( element ) ;
372
+ body . style . overflow = previousBodyOverflow ;
373
+ } ) ;
374
+
341
375
it ( 'should shink the calendar pane when it would otherwise not fit on the screen' , function ( ) {
342
376
// Fake the window being very narrow so that the calendar pane won't fit on-screen.
343
377
controller . $window = { innerWidth : 200 , innherHeight : 800 } ;
0 commit comments