11import { Platform , _supportsShadowDom } from '@angular/cdk/platform' ;
2+ import { CdkPortalOutlet , PortalModule , TemplatePortal } from '@angular/cdk/portal' ;
23import {
34 Component ,
4- ViewChild ,
55 TemplateRef ,
6+ ViewChild ,
67 ViewContainerRef ,
78 ViewEncapsulation ,
8- provideZoneChangeDetection ,
99} from '@angular/core' ;
10- import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
11- import { PortalModule , CdkPortalOutlet , TemplatePortal } from '@angular/cdk/portal' ;
12- import { A11yModule , FocusTrap , CdkTrapFocus } from '../index' ;
10+ import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
1311import { By } from '@angular/platform-browser' ;
12+ import { A11yModule , CdkTrapFocus , FocusTrap } from '../index' ;
1413
1514describe ( 'FocusTrap' , ( ) => {
1615 beforeEach ( waitForAsync ( ( ) => {
1716 TestBed . configureTestingModule ( {
18- providers : [ provideZoneChangeDetection ( ) ] ,
1917 imports : [
2018 A11yModule ,
2119 PortalModule ,
@@ -106,6 +104,7 @@ describe('FocusTrap', () => {
106104 expect ( rootElement . querySelectorAll ( 'div.cdk-visually-hidden' ) . length ) . toBe ( 2 ) ;
107105
108106 fixture . componentInstance . renderFocusTrap = false ;
107+ fixture . changeDetectorRef . markForCheck ( ) ;
109108 fixture . detectChanges ( ) ;
110109
111110 expect ( rootElement . querySelectorAll ( 'div.cdk-visually-hidden' ) . length ) . toBe ( 0 ) ;
@@ -120,6 +119,7 @@ describe('FocusTrap', () => {
120119 expect ( anchors . every ( current => current . getAttribute ( 'aria-hidden' ) === 'true' ) ) . toBe ( true ) ;
121120
122121 fixture . componentInstance . _isFocusTrapEnabled = false ;
122+ fixture . changeDetectorRef . markForCheck ( ) ;
123123 fixture . detectChanges ( ) ;
124124
125125 expect ( anchors . every ( current => ! current . hasAttribute ( 'tabindex' ) ) ) . toBe ( true ) ;
@@ -216,12 +216,16 @@ describe('FocusTrap', () => {
216216 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
217217
218218 fixture . componentInstance . showTrappedRegion = true ;
219+ fixture . changeDetectorRef . markForCheck ( ) ;
219220 fixture . detectChanges ( ) ;
220221
221222 fixture . whenStable ( ) . then ( ( ) => {
222223 expect ( getActiveElement ( ) . id ) . toBe ( 'auto-capture-target' ) ;
223224
224- fixture . destroy ( ) ;
225+ fixture . componentInstance . showTrappedRegion = false ;
226+ fixture . changeDetectorRef . markForCheck ( ) ;
227+ fixture . detectChanges ( ) ;
228+
225229 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
226230 } ) ;
227231 } ) ) ;
@@ -230,19 +234,24 @@ describe('FocusTrap', () => {
230234 const fixture = TestBed . createComponent ( FocusTrapWithAutoCapture ) ;
231235 fixture . componentInstance . autoCaptureEnabled = false ;
232236 fixture . componentInstance . showTrappedRegion = true ;
237+ fixture . changeDetectorRef . markForCheck ( ) ;
233238 fixture . detectChanges ( ) ;
234239
235240 const buttonOutsideTrappedRegion = fixture . nativeElement . querySelector ( 'button' ) ;
236241 buttonOutsideTrappedRegion . focus ( ) ;
237242 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
238243
239244 fixture . componentInstance . autoCaptureEnabled = true ;
245+ fixture . changeDetectorRef . markForCheck ( ) ;
240246 fixture . detectChanges ( ) ;
241247
242248 fixture . whenStable ( ) . then ( ( ) => {
243249 expect ( getActiveElement ( ) . id ) . toBe ( 'auto-capture-target' ) ;
244250
245- fixture . destroy ( ) ;
251+ fixture . componentInstance . showTrappedRegion = false ;
252+ fixture . changeDetectorRef . markForCheck ( ) ;
253+ fixture . detectChanges ( ) ;
254+
246255 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
247256 } ) ;
248257 } ) ) ;
@@ -260,12 +269,16 @@ describe('FocusTrap', () => {
260269 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
261270
262271 fixture . componentInstance . showTrappedRegion = true ;
272+ fixture . changeDetectorRef . markForCheck ( ) ;
263273 fixture . detectChanges ( ) ;
264274
265275 fixture . whenStable ( ) . then ( ( ) => {
266276 expect ( getActiveElement ( ) . id ) . toBe ( 'auto-capture-target' ) ;
267277
268- fixture . destroy ( ) ;
278+ fixture . componentInstance . showTrappedRegion = false ;
279+ fixture . changeDetectorRef . markForCheck ( ) ;
280+ fixture . detectChanges ( ) ;
281+
269282 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
270283 } ) ;
271284 } ) ) ;
@@ -278,19 +291,24 @@ describe('FocusTrap', () => {
278291 const fixture = TestBed . createComponent ( FocusTrapWithAutoCaptureInShadowDom ) ;
279292 fixture . componentInstance . autoCaptureEnabled = false ;
280293 fixture . componentInstance . showTrappedRegion = true ;
294+ fixture . changeDetectorRef . markForCheck ( ) ;
281295 fixture . detectChanges ( ) ;
282296
283297 const buttonOutsideTrappedRegion = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
284298 buttonOutsideTrappedRegion . focus ( ) ;
285299 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
286300
287301 fixture . componentInstance . autoCaptureEnabled = true ;
302+ fixture . changeDetectorRef . markForCheck ( ) ;
288303 fixture . detectChanges ( ) ;
289304
290305 fixture . whenStable ( ) . then ( ( ) => {
291306 expect ( getActiveElement ( ) . id ) . toBe ( 'auto-capture-target' ) ;
292307
293- fixture . destroy ( ) ;
308+ fixture . componentInstance . showTrappedRegion = false ;
309+ fixture . changeDetectorRef . markForCheck ( ) ;
310+ fixture . detectChanges ( ) ;
311+
294312 expect ( getActiveElement ( ) ) . toBe ( buttonOutsideTrappedRegion ) ;
295313 } ) ;
296314 } ) ) ;
0 commit comments