@@ -8,13 +8,14 @@ describe('md-date-picker', function() {
8
8
var initialDate = new Date ( 2015 , FEB , 15 ) ;
9
9
10
10
var ngElement , element , scope , pageScope , controller ;
11
- var $timeout , $$rAF , $animate , keyCodes , dateUtil , dateLocale ;
11
+ var $timeout , $$rAF , $animate , $window , keyCodes , dateUtil , dateLocale ;
12
12
13
13
beforeEach ( module ( 'material.components.datepicker' , 'ngAnimateMock' ) ) ;
14
14
15
15
beforeEach ( inject ( function ( $compile , $rootScope , $injector ) {
16
16
$$rAF = $injector . get ( '$$rAF' ) ;
17
17
$animate = $injector . get ( '$animate' ) ;
18
+ $window = $injector . get ( '$window' ) ;
18
19
dateUtil = $injector . get ( '$$mdDateUtil' ) ;
19
20
dateLocale = $injector . get ( '$mdDateLocale' ) ;
20
21
$timeout = $injector . get ( '$timeout' ) ;
@@ -37,6 +38,8 @@ describe('md-date-picker', function() {
37
38
scope = ngElement . isolateScope ( ) ;
38
39
controller = ngElement . controller ( 'mdDatepicker' ) ;
39
40
element = ngElement [ 0 ] ;
41
+
42
+ controller . closeCalendarPane ( ) ;
40
43
} ) ) ;
41
44
42
45
/**
@@ -194,41 +197,62 @@ describe('md-date-picker', function() {
194
197
document . body . removeChild ( element ) ;
195
198
} ) ;
196
199
197
- it ( 'should shink the calendar pane when it would otherwise not fit on the screen' , function ( ) {
198
- // Make the body narrow so that the calendar pane won't fit on-screen.
199
- document . body . style . width = '300px' ;
200
+ it ( 'should adjust the pane position if it would go off-screen (w/ scrollable)' , function ( ) {
201
+ // Make the body super huge.
202
+ var superLongElement = document . createElement ( 'div' ) ;
203
+ superLongElement . style . height = '10000px' ;
204
+ superLongElement . style . width = '1px' ;
205
+ document . body . appendChild ( superLongElement ) ;
200
206
201
- // Open the calendar pane.
207
+ // Absolutely position the picker near (say ~30px) the edge of the viewport.
208
+ element . style . position = 'absolute' ;
209
+ element . style . top = ( window . innerHeight - 30 ) + 'px' ;
210
+ element . style . left = '0' ;
211
+ document . body . appendChild ( element ) ;
212
+
213
+ // Open the pane.
202
214
element . querySelector ( 'md-button' ) . click ( ) ;
203
215
$timeout . flush ( ) ;
204
216
217
+ // Expect that the pane is on-screen.
218
+ var paneRect = controller . calendarPane . getBoundingClientRect ( ) ;
219
+ expect ( paneRect . bottom ) . toBeLessThan ( window . innerHeight + 1 ) ;
220
+ document . body . removeChild ( superLongElement ) ;
221
+
222
+ document . body . removeChild ( element ) ;
223
+ } ) ;
224
+
225
+ it ( 'should shink the calendar pane when it would otherwise not fit on the screen' , function ( ) {
226
+ // Fake the window being very narrow so that the calendar pane won't fit on-screen.
227
+ controller . $window = { innerWidth : 200 , innherHeight : 800 } ;
228
+
229
+ // Open the calendar pane.
230
+ controller . openCalendarPane ( { } ) ;
231
+
205
232
// Expect the calendarPane to be scaled by an amount between zero and one.
206
233
expect ( controller . calendarPane . style . transform ) . toMatch ( / s c a l e \( 0 \. \d + \) / ) ;
207
-
208
- // Reset the body width.
209
- document . body . style . width = '' ;
210
234
} ) ;
211
235
212
236
it ( 'should not open the calendar pane if disabled' , function ( ) {
213
- controller . setDisabled ( true ) ;
214
- controller . openCalendarPane ( {
215
- target : controller . inputElement
237
+ controller . setDisabled ( true ) ;
238
+ controller . openCalendarPane ( {
239
+ target : controller . inputElement
240
+ } ) ;
241
+ scope . $apply ( ) ;
242
+ expect ( controller . isCalendarOpen ) . toBeFalsy ( ) ;
243
+ expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
216
244
} ) ;
217
- scope . $apply ( ) ;
218
- expect ( controller . isCalendarOpen ) . toBeFalsy ( ) ;
219
- expect ( controller . calendarPane . offsetHeight ) . toBe ( 0 ) ;
220
- } ) ;
221
245
222
246
it ( 'should close the calendar pane on md-calendar-close' , function ( ) {
223
- controller . openCalendarPane ( {
224
- target : controller . inputElement
225
- } ) ;
247
+ controller . openCalendarPane ( {
248
+ target : controller . inputElement
249
+ } ) ;
226
250
227
- scope . $emit ( 'md-calendar-close' ) ;
228
- scope . $apply ( ) ;
229
- expect ( controller . calendarPaneOpenedFrom ) . toBe ( null ) ;
230
- expect ( controller . isCalendarOpen ) . toBe ( false ) ;
231
- } ) ;
251
+ scope . $emit ( 'md-calendar-close' ) ;
252
+ scope . $apply ( ) ;
253
+ expect ( controller . calendarPaneOpenedFrom ) . toBe ( null ) ;
254
+ expect ( controller . isCalendarOpen ) . toBe ( false ) ;
255
+ } ) ;
232
256
} ) ;
233
257
234
258
describe ( 'md-calendar-change' , function ( ) {
0 commit comments