Skip to content

Commit

Permalink
test: Convert tests for cdk-experimental, components-examples, google…
Browse files Browse the repository at this point in the history
…-maps, youtube-player to zoneless (#29181)

(cherry picked from commit 9404e5f)
  • Loading branch information
mmalerba committed Jun 4, 2024
1 parent 5ef11b1 commit 65648a4
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 80 deletions.
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

0 comments on commit 65648a4

Please sign in to comment.