|
1 | 1 | import {inject, TestBed, fakeAsync} from '@angular/core/testing';
|
2 |
| -import {Component, NgZone} from '@angular/core'; |
| 2 | +import {Component, ElementRef, NgZone} from '@angular/core'; |
3 | 3 | import {Subject} from 'rxjs';
|
4 | 4 | import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
|
5 |
| -import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling'; |
| 5 | +import {CdkScrollable, ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling'; |
6 | 6 | import {Overlay, OverlayConfig, OverlayRef, OverlayModule, OverlayContainer} from '../index';
|
7 | 7 |
|
8 | 8 | describe('CloseScrollStrategy', () => {
|
9 | 9 | let overlayRef: OverlayRef;
|
10 | 10 | let componentPortal: ComponentPortal<MozarellaMsg>;
|
11 |
| - let scrolledSubject = new Subject(); |
| 11 | + let scrolledSubject = new Subject<CdkScrollable | undefined>(); |
12 | 12 | let scrollPosition: number;
|
13 | 13 |
|
14 | 14 | beforeEach(fakeAsync(() => {
|
@@ -55,6 +55,16 @@ describe('CloseScrollStrategy', () => {
|
55 | 55 | expect(overlayRef.detach).toHaveBeenCalled();
|
56 | 56 | });
|
57 | 57 |
|
| 58 | + it('should not detach if the scrollable is inside the overlay', () => { |
| 59 | + overlayRef.attach(componentPortal); |
| 60 | + spyOn(overlayRef, 'detach'); |
| 61 | + |
| 62 | + scrolledSubject.next({ |
| 63 | + getElementRef: () => new ElementRef(overlayRef.overlayElement), |
| 64 | + } as CdkScrollable); |
| 65 | + expect(overlayRef.detach).not.toHaveBeenCalled(); |
| 66 | + }); |
| 67 | + |
58 | 68 | it('should not attempt to detach the overlay after it has been detached', () => {
|
59 | 69 | overlayRef.attach(componentPortal);
|
60 | 70 | overlayRef.detach();
|
|
0 commit comments