Skip to content

Commit 65648a4

Browse files
committed
test: Convert tests for cdk-experimental, components-examples, google-maps, youtube-player to zoneless (#29181)
(cherry picked from commit 9404e5f)
1 parent 5ef11b1 commit 65648a4

File tree

11 files changed

+155
-80
lines changed

11 files changed

+155
-80
lines changed

src/cdk-experimental/combobox/combobox.spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import {CdkComboboxPopup} from '@angular/cdk-experimental/combobox/combobox-popup';
22
import {DOWN_ARROW, ESCAPE} from '@angular/cdk/keycodes';
33
import {dispatchKeyboardEvent, dispatchMouseEvent} from '@angular/cdk/testing/private';
4-
import {
5-
Component,
6-
DebugElement,
7-
ElementRef,
8-
ViewChild,
9-
provideZoneChangeDetection,
10-
signal,
11-
} from '@angular/core';
4+
import {Component, DebugElement, ElementRef, ViewChild, signal} from '@angular/core';
125
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
136
import {By} from '@angular/platform-browser';
147
import {CdkCombobox} from './combobox';
@@ -32,7 +25,6 @@ describe('Combobox', () => {
3225

3326
beforeEach(waitForAsync(() => {
3427
TestBed.configureTestingModule({
35-
providers: [provideZoneChangeDetection()],
3628
imports: [CdkComboboxModule, ComboboxToggle],
3729
}).compileComponents();
3830
}));
@@ -54,11 +46,13 @@ describe('Combobox', () => {
5446

5547
it('should update the aria disabled attribute', () => {
5648
comboboxInstance.disabled = true;
49+
fixture.changeDetectorRef.markForCheck();
5750
fixture.detectChanges();
5851

5952
expect(comboboxElement.getAttribute('aria-disabled')).toBe('true');
6053

6154
comboboxInstance.disabled = false;
55+
fixture.changeDetectorRef.markForCheck();
6256
fixture.detectChanges();
6357

6458
expect(comboboxElement.getAttribute('aria-disabled')).toBe('false');
@@ -129,6 +123,7 @@ describe('Combobox', () => {
129123
it('should not open panel when disabled', () => {
130124
expect(comboboxInstance.isOpen()).toBeFalse();
131125
comboboxInstance.disabled = true;
126+
fixture.changeDetectorRef.markForCheck();
132127
fixture.detectChanges();
133128

134129
dispatchMouseEvent(comboboxElement, 'click');

src/cdk-experimental/combobox/combobox.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import {Directionality} from '@angular/cdk/bidi';
9+
import {BooleanInput, coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {DOWN_ARROW, ENTER, ESCAPE, TAB} from '@angular/cdk/keycodes';
11+
import {
12+
ConnectedPosition,
13+
FlexibleConnectedPositionStrategy,
14+
Overlay,
15+
OverlayConfig,
16+
OverlayRef,
17+
} from '@angular/cdk/overlay';
18+
import {_getEventTarget} from '@angular/cdk/platform';
19+
import {TemplatePortal} from '@angular/cdk/portal';
820
import {DOCUMENT} from '@angular/common';
921
import {
22+
ChangeDetectorRef,
1023
Directive,
1124
ElementRef,
1225
EventEmitter,
@@ -19,19 +32,8 @@ import {
1932
Output,
2033
TemplateRef,
2134
ViewContainerRef,
35+
inject,
2236
} from '@angular/core';
23-
import {TemplatePortal} from '@angular/cdk/portal';
24-
import {
25-
ConnectedPosition,
26-
FlexibleConnectedPositionStrategy,
27-
Overlay,
28-
OverlayConfig,
29-
OverlayRef,
30-
} from '@angular/cdk/overlay';
31-
import {Directionality} from '@angular/cdk/bidi';
32-
import {BooleanInput, coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
33-
import {_getEventTarget} from '@angular/cdk/platform';
34-
import {DOWN_ARROW, ENTER, ESCAPE, TAB} from '@angular/cdk/keycodes';
3537

3638
export type AriaHasPopupValue = 'false' | 'true' | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog';
3739
export type OpenAction = 'focus' | 'click' | 'downKey' | 'toggle';
@@ -107,6 +109,8 @@ export class CdkCombobox<T = unknown> implements OnDestroy {
107109
contentId: string = '';
108110
contentType: AriaHasPopupValue;
109111

112+
private _changeDetectorRef = inject(ChangeDetectorRef);
113+
110114
constructor(
111115
private readonly _elementRef: ElementRef<HTMLElement>,
112116
private readonly _overlay: Overlay,
@@ -193,6 +197,7 @@ export class CdkCombobox<T = unknown> implements OnDestroy {
193197
this.opened.next();
194198
this._overlayRef = this._overlayRef || this._overlay.create(this._getOverlayConfig());
195199
this._overlayRef.attach(this._getPanelContent());
200+
this._changeDetectorRef.markForCheck();
196201
if (!this._isTextTrigger()) {
197202
// TODO: instead of using a focus function, potentially use cdk/a11y focus trapping
198203
this._doc.getElementById(this.contentId)?.focus();
@@ -205,6 +210,7 @@ export class CdkCombobox<T = unknown> implements OnDestroy {
205210
if (this.isOpen() && !this.disabled) {
206211
this.closed.next();
207212
this._overlayRef.detach();
213+
this._changeDetectorRef.markForCheck();
208214
}
209215
}
210216

0 commit comments

Comments
 (0)