Skip to content

Commit 727e162

Browse files
committed
Revert "test: rewrite tests that test zone.js implementation details"
This reverts commit de01346.
1 parent de01346 commit 727e162

File tree

6 files changed

+662
-352
lines changed

6 files changed

+662
-352
lines changed

src/cdk/a11y/focus-monitor/focus-monitor.spec.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {TAB} from '@angular/cdk/keycodes';
22
import {Platform} from '@angular/cdk/platform';
33
import {DOCUMENT} from '@angular/common';
4-
import {Component, ViewChild, provideZoneChangeDetection} from '@angular/core';
4+
import {Component, ViewChild} from '@angular/core';
55
import {ComponentFixture, TestBed, fakeAsync, flush, inject, tick} from '@angular/core/testing';
66
import {By} from '@angular/platform-browser';
77
import {
@@ -34,7 +34,6 @@ describe('FocusMonitor', () => {
3434
TestBed.configureTestingModule({
3535
imports: [A11yModule, PlainButton],
3636
providers: [
37-
provideZoneChangeDetection(),
3837
{
3938
provide: DOCUMENT,
4039
useFactory: () => {
@@ -900,25 +899,6 @@ describe('FocusMonitor input label detection', () => {
900899
}));
901900
});
902901

903-
describe('cdkMonitorFocus with change detection counter', () => {
904-
beforeEach(() => {
905-
TestBed.configureTestingModule({
906-
imports: [A11yModule, ButtonWithCDCounter],
907-
providers: [{provide: Platform, useValue: {isBrowser: true}}],
908-
}).compileComponents();
909-
});
910-
911-
it('should detect changes caused by focus change', async () => {
912-
const fixture = TestBed.createComponent(ButtonWithCDCounter);
913-
fixture.autoDetectChanges();
914-
const buttonElement = fixture.nativeElement.querySelector('button');
915-
buttonElement.focus();
916-
await fixture.whenStable();
917-
const focusChangeCounter = fixture.nativeElement.querySelector('.focus-change-counter');
918-
expect(focusChangeCounter.innerText).toBe('1');
919-
});
920-
});
921-
922902
@Component({
923903
template: `<div class="parent"><button>focus me!</button></div>`,
924904
standalone: true,
@@ -981,15 +961,3 @@ class CheckboxWithLabel {}
981961
class ExportedFocusMonitor {
982962
@ViewChild('exportedDir') exportedDirRef: CdkMonitorFocus;
983963
}
984-
985-
@Component({
986-
template: `
987-
<button cdkMonitorElementFocus (cdkFocusChange)="focusChangeCount = focusChangeCount + 1"></button>
988-
<div class="focus-change-counter">{{focusChangeCount}}</div>
989-
`,
990-
standalone: true,
991-
imports: [A11yModule],
992-
})
993-
class ButtonWithCDCounter {
994-
focusChangeCount = 0;
995-
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {Platform} from '@angular/cdk/platform';
2+
import {patchElementFocus} from '@angular/cdk/testing/private';
3+
import {Component, NgZone, provideZoneChangeDetection} from '@angular/core';
4+
import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing';
5+
import {A11yModule} from '../a11y-module';
6+
import {FocusMonitor} from './focus-monitor';
7+
8+
describe('FocusMonitor observable stream Zone.js integration', () => {
9+
let fixture: ComponentFixture<PlainButton>;
10+
let buttonElement: HTMLElement;
11+
let focusMonitor: FocusMonitor;
12+
let fakePlatform: Platform;
13+
14+
beforeEach(() => {
15+
fakePlatform = {isBrowser: true} as Platform;
16+
TestBed.configureTestingModule({
17+
imports: [A11yModule, PlainButton],
18+
providers: [{provide: Platform, useValue: fakePlatform}, provideZoneChangeDetection()],
19+
}).compileComponents();
20+
});
21+
22+
beforeEach(inject([FocusMonitor], (fm: FocusMonitor) => {
23+
fixture = TestBed.createComponent(PlainButton);
24+
focusMonitor = fm;
25+
fixture.detectChanges();
26+
buttonElement = fixture.debugElement.nativeElement.querySelector('button');
27+
patchElementFocus(buttonElement);
28+
}));
29+
30+
it('should emit inside the NgZone', fakeAsync(() => {
31+
const spy = jasmine.createSpy('zone spy');
32+
focusMonitor.monitor(buttonElement).subscribe(() => spy(NgZone.isInAngularZone()));
33+
expect(spy).not.toHaveBeenCalled();
34+
35+
buttonElement.focus();
36+
fixture.detectChanges();
37+
tick();
38+
expect(spy).toHaveBeenCalledWith(true);
39+
}));
40+
});
41+
42+
@Component({
43+
template: `<div class="parent"><button>focus me!</button></div>`,
44+
standalone: true,
45+
imports: [A11yModule],
46+
})
47+
class PlainButton {}

0 commit comments

Comments
 (0)