-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move some CDK tests to zoneless (#29103)
* test: move some CDK tests to zoneless * test: Fix flakiness in virtual scroll tests * test: remove overzealous markForCheck calls
- Loading branch information
Showing
7 changed files
with
344 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {ComponentPortal, PortalModule} from '@angular/cdk/portal'; | ||
import {Component, NgZone, provideZoneChangeDetection} from '@angular/core'; | ||
import {TestBed, fakeAsync, inject} from '@angular/core/testing'; | ||
import {Subject} from 'rxjs'; | ||
import {Overlay} from '../overlay'; | ||
import {OverlayConfig} from '../overlay-config'; | ||
import {OverlayContainer} from '../overlay-container'; | ||
import {OverlayModule} from '../overlay-module'; | ||
import {OverlayRef} from '../overlay-ref'; | ||
import {CdkScrollable, ScrollDispatcher, ViewportRuler} from '../public-api'; | ||
|
||
describe('CloseScrollStrategy Zone.js integration', () => { | ||
let overlayRef: OverlayRef; | ||
let componentPortal: ComponentPortal<MozarellaMsg>; | ||
let scrolledSubject = new Subject<CdkScrollable | undefined>(); | ||
let scrollPosition: number; | ||
|
||
beforeEach(fakeAsync(() => { | ||
scrollPosition = 0; | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [OverlayModule, PortalModule, MozarellaMsg], | ||
providers: [ | ||
provideZoneChangeDetection(), | ||
{ | ||
provide: ScrollDispatcher, | ||
useFactory: () => ({ | ||
scrolled: () => scrolledSubject, | ||
}), | ||
}, | ||
{ | ||
provide: ViewportRuler, | ||
useFactory: () => ({ | ||
getViewportScrollPosition: () => ({top: scrollPosition}), | ||
}), | ||
}, | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
beforeEach(inject([Overlay], (overlay: Overlay) => { | ||
let overlayConfig = new OverlayConfig({scrollStrategy: overlay.scrollStrategies.close()}); | ||
overlayRef = overlay.create(overlayConfig); | ||
componentPortal = new ComponentPortal(MozarellaMsg); | ||
})); | ||
|
||
afterEach(inject([OverlayContainer], (container: OverlayContainer) => { | ||
overlayRef.dispose(); | ||
container.getContainerElement().remove(); | ||
})); | ||
|
||
it('should detach inside the NgZone', () => { | ||
const spy = jasmine.createSpy('detachment spy'); | ||
const subscription = overlayRef.detachments().subscribe(() => spy(NgZone.isInAngularZone())); | ||
|
||
overlayRef.attach(componentPortal); | ||
scrolledSubject.next(); | ||
|
||
expect(spy).toHaveBeenCalledWith(true); | ||
subscription.unsubscribe(); | ||
}); | ||
}); | ||
|
||
/** Simple component that we can attach to the overlay. */ | ||
@Component({ | ||
template: '<p>Mozarella</p>', | ||
standalone: true, | ||
imports: [OverlayModule, PortalModule], | ||
}) | ||
class MozarellaMsg {} |
Oops, something went wrong.