@@ -1508,40 +1508,46 @@ describe('MatAutocomplete', () => {
1508
1508
1509
1509
it ( 'should fall back to above position when requested if options are added while ' +
1510
1510
'the panel is open' , fakeAsync ( ( ) => {
1511
- let fixture = createComponent ( AutocompleteWithOnPushDelay ) ;
1511
+ let fixture = createComponent ( SimpleAutocomplete ) ;
1512
+ fixture . componentInstance . states = fixture . componentInstance . states . slice ( 0 , 1 ) ;
1513
+ fixture . componentInstance . filteredStates = fixture . componentInstance . states . slice ( ) ;
1512
1514
fixture . detectChanges ( ) ;
1513
1515
1514
1516
let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1515
1517
let inputReference = fixture . debugElement . query ( By . css ( '.mat-form-field-flex' ) ) . nativeElement ;
1516
1518
1517
1519
// Push the element down so it has a little bit of space, but not enough to render.
1518
- inputReference . style . bottom = '10px ' ;
1520
+ inputReference . style . bottom = '75px ' ;
1519
1521
inputReference . style . position = 'fixed' ;
1520
1522
1521
- // Focus the input to load the deferred options.
1522
1523
dispatchFakeEvent ( inputEl , 'focusin' ) ;
1523
- tick ( 1000 ) ;
1524
-
1525
1524
fixture . detectChanges ( ) ;
1526
- tick ( ) ;
1525
+ zone . simulateZoneExit ( ) ;
1526
+ fixture . detectChanges ( ) ;
1527
1527
1528
- const inputBottom = inputReference . getBoundingClientRect ( ) . bottom ;
1529
- const panel = overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) ! ;
1530
- const panelTop = panel . getBoundingClientRect ( ) . top ;
1528
+ let panel = overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) ! ;
1529
+ let inputRect = inputReference . getBoundingClientRect ( ) ;
1530
+ let panelRect = panel . getBoundingClientRect ( ) ;
1531
1531
1532
- expect ( Math . floor ( inputBottom ) )
1533
- . toEqual ( Math . floor ( panelTop ) ,
1532
+ expect ( Math . floor ( panelRect . top ) )
1533
+ . toBe ( Math . floor ( inputRect . bottom ) ,
1534
1534
`Expected panel top to be below input before repositioning.` ) ;
1535
1535
1536
+ for ( let i = 0 ; i < 20 ; i ++ ) {
1537
+ fixture . componentInstance . filteredStates . push ( { code : 'FK' , name : 'Fake State' } ) ;
1538
+ fixture . detectChanges ( ) ;
1539
+ }
1540
+
1536
1541
// Request a position update now that there are too many suggestions to fit in the viewport.
1537
1542
fixture . componentInstance . trigger . updatePosition ( ) ;
1538
1543
1539
- const inputTop = inputReference . getBoundingClientRect ( ) . top ;
1540
- const panelBottom = panel . getBoundingClientRect ( ) . bottom ;
1544
+ inputRect = inputReference . getBoundingClientRect ( ) ;
1545
+ panelRect = panel . getBoundingClientRect ( ) ;
1541
1546
1542
- expect ( Math . floor ( inputTop ) )
1543
- . toEqual ( Math . floor ( panelBottom ) ,
1547
+ expect ( Math . floor ( panelRect . bottom ) )
1548
+ . toBe ( Math . floor ( inputRect . top ) ,
1544
1549
`Expected panel to fall back to above position after repositioning.` ) ;
1550
+ tick ( ) ;
1545
1551
} ) ) ;
1546
1552
1547
1553
it ( 'should not throw if a panel reposition is requested while the panel is closed' , ( ) => {
0 commit comments