Skip to content

Commit 318ba6b

Browse files
jelbourncrisbeto
authored andcommitted
wip select tests
1 parent 3c66200 commit 318ba6b

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/lib/select/select.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,20 +1630,22 @@ fdescribe('MdSelect', () => {
16301630
`Expected trigger label to align along x-axis, accounting for the padding in rtl.`);
16311631
}));
16321632

1633-
fit('should not adjust if all options are within a group, except the selected one',
1634-
fakeAsync(() => {
1633+
it('should not adjust if all options are within a group, except the selected one',
1634+
async(() => {
16351635
groupFixture.componentInstance.control.setValue('mime-11');
16361636
groupFixture.detectChanges();
16371637

16381638
trigger.click();
16391639
groupFixture.detectChanges();
16401640

1641-
const selected = document.querySelector('.cdk-overlay-pane md-option.mat-selected')!;
1642-
const selectedOptionLeft = selected.getBoundingClientRect().left;
1643-
const triggerLeft = trigger.getBoundingClientRect().left;
1641+
fixture.whenStable().then(() => {
1642+
const selected = document.querySelector('.cdk-overlay-pane md-option.mat-selected')!;
1643+
const selectedOptionLeft = selected.getBoundingClientRect().left;
1644+
const triggerLeft = trigger.getBoundingClientRect().left;
16441645

1645-
// 16px is the default option padding
1646-
expect(Math.floor(selectedOptionLeft)).toEqual(Math.floor(triggerLeft - 16));
1646+
// 16px is the default option padding
1647+
expect(Math.floor(selectedOptionLeft)).toEqual(Math.floor(triggerLeft - 16));
1648+
});
16471649
}));
16481650

16491651
it('should align the first option to the trigger, if nothing is selected', fakeAsync(() => {

src/lib/select/select.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
ViewportRuler
4949
} from '@angular/cdk/overlay';
5050
import {merge} from 'rxjs/observable/merge';
51+
import {first} from 'rxjs/operator/first';
5152
import {Observable} from 'rxjs/Observable';
5253
import {Subscription} from 'rxjs/Subscription';
5354
import {fadeInContent, transformPanel, transformPlaceholder} from './select-animations';
@@ -648,8 +649,10 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
648649
* Callback that is invoked when the overlay panel has been attached.
649650
*/
650651
_onAttached(): void {
651-
this._calculateOverlayOffsetX();
652-
this._setScrollTop();
652+
first.call(this.overlayDir.positionChange).subscribe(() => {
653+
this._calculateOverlayOffsetX();
654+
this._setScrollTop();
655+
});
653656
}
654657

655658
/** Whether the select has a value. */

0 commit comments

Comments
 (0)