Skip to content

test: Convert tests for cdk-experimental, components-examples, google-maps, youtube-player to zoneless #29181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/cdk-experimental/combobox/combobox.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import {CdkComboboxPopup} from '@angular/cdk-experimental/combobox/combobox-popup';
import {DOWN_ARROW, ESCAPE} from '@angular/cdk/keycodes';
import {dispatchKeyboardEvent, dispatchMouseEvent} from '@angular/cdk/testing/private';
import {
Component,
DebugElement,
ElementRef,
ViewChild,
provideZoneChangeDetection,
signal,
} from '@angular/core';
import {Component, DebugElement, ElementRef, ViewChild, signal} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {CdkCombobox} from './combobox';
Expand All @@ -32,7 +25,6 @@ describe('Combobox', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [provideZoneChangeDetection()],
imports: [CdkComboboxModule, ComboboxToggle],
}).compileComponents();
}));
Expand All @@ -54,11 +46,13 @@ describe('Combobox', () => {

it('should update the aria disabled attribute', () => {
comboboxInstance.disabled = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

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

comboboxInstance.disabled = false;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

expect(comboboxElement.getAttribute('aria-disabled')).toBe('false');
Expand Down Expand Up @@ -129,6 +123,7 @@ describe('Combobox', () => {
it('should not open panel when disabled', () => {
expect(comboboxInstance.isOpen()).toBeFalse();
comboboxInstance.disabled = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

dispatchMouseEvent(comboboxElement, 'click');
Expand Down
30 changes: 18 additions & 12 deletions src/cdk-experimental/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Directionality} from '@angular/cdk/bidi';
import {BooleanInput, coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
import {DOWN_ARROW, ENTER, ESCAPE, TAB} from '@angular/cdk/keycodes';
import {
ConnectedPosition,
FlexibleConnectedPositionStrategy,
Overlay,
OverlayConfig,
OverlayRef,
} from '@angular/cdk/overlay';
import {_getEventTarget} from '@angular/cdk/platform';
import {TemplatePortal} from '@angular/cdk/portal';
import {DOCUMENT} from '@angular/common';
import {
ChangeDetectorRef,
Directive,
ElementRef,
EventEmitter,
Expand All @@ -19,19 +32,8 @@ import {
Output,
TemplateRef,
ViewContainerRef,
inject,
} from '@angular/core';
import {TemplatePortal} from '@angular/cdk/portal';
import {
ConnectedPosition,
FlexibleConnectedPositionStrategy,
Overlay,
OverlayConfig,
OverlayRef,
} from '@angular/cdk/overlay';
import {Directionality} from '@angular/cdk/bidi';
import {BooleanInput, coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
import {_getEventTarget} from '@angular/cdk/platform';
import {DOWN_ARROW, ENTER, ESCAPE, TAB} from '@angular/cdk/keycodes';

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

private _changeDetectorRef = inject(ChangeDetectorRef);

constructor(
private readonly _elementRef: ElementRef<HTMLElement>,
private readonly _overlay: Overlay,
Expand Down Expand Up @@ -193,6 +197,7 @@ export class CdkCombobox<T = unknown> implements OnDestroy {
this.opened.next();
this._overlayRef = this._overlayRef || this._overlay.create(this._getOverlayConfig());
this._overlayRef.attach(this._getPanelContent());
this._changeDetectorRef.markForCheck();
if (!this._isTextTrigger()) {
// TODO: instead of using a focus function, potentially use cdk/a11y focus trapping
this._doc.getElementById(this.contentId)?.focus();
Expand All @@ -205,6 +210,7 @@ export class CdkCombobox<T = unknown> implements OnDestroy {
if (this.isOpen() && !this.disabled) {
this.closed.next();
this._overlayRef.detach();
this._changeDetectorRef.markForCheck();
}
}

Expand Down
Loading
Loading