Skip to content

Commit 328223a

Browse files
committed
fix(cdk/tree): restore deleted tests, remove zone change detection
1 parent d220ab6 commit 328223a

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/material/tree/tree-using-legacy-key-manager.spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
Component,
3-
ElementRef,
4-
QueryList,
5-
ViewChild,
6-
ViewChildren,
7-
provideZoneChangeDetection,
8-
} from '@angular/core';
1+
import {Component, ElementRef, QueryList, ViewChild, ViewChildren} from '@angular/core';
92
import {of} from 'rxjs';
103
import {ComponentFixture, TestBed} from '@angular/core/testing';
114
import {MatTreeModule} from './tree-module';
@@ -20,7 +13,7 @@ describe('MatTree when provided LegacyTreeKeyManager', () => {
2013
TestBed.configureTestingModule({
2114
imports: [MatTreeModule],
2215
declarations: [SimpleMatTreeApp],
23-
providers: [provideZoneChangeDetection(), NOOP_TREE_KEY_MANAGER_FACTORY_PROVIDER],
16+
providers: [NOOP_TREE_KEY_MANAGER_FACTORY_PROVIDER],
2417
}).compileComponents();
2518

2619
fixture = TestBed.createComponent(SimpleMatTreeApp);
@@ -40,6 +33,7 @@ describe('MatTree when provided LegacyTreeKeyManager', () => {
4033
describe('when nodes have TabIndex Input binding of 42', () => {
4134
beforeEach(() => {
4235
fixture.componentInstance.tabIndexInputBinding = 42;
36+
fixture.changeDetectorRef.markForCheck();
4337
fixture.detectChanges();
4438
});
4539

@@ -55,6 +49,7 @@ describe('MatTree when provided LegacyTreeKeyManager', () => {
5549
describe('when nodes have tabindex attribute binding of 2', () => {
5650
beforeEach(() => {
5751
fixture.componentInstance.tabindexAttributeBinding = '2';
52+
fixture.changeDetectorRef.markForCheck();
5853
fixture.detectChanges();
5954
});
6055

src/material/tree/tree-using-tree-control.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {FlatTreeControl, NestedTreeControl, TreeControl} from '@angular/cdk/tree';
9-
import {provideZoneChangeDetection, Component, ViewChild, Type} from '@angular/core';
9+
import {Component, ViewChild, Type} from '@angular/core';
1010
import {ComponentFixture, TestBed} from '@angular/core/testing';
1111
import {BehaviorSubject, Observable} from 'rxjs';
1212
import {map} from 'rxjs/operators';
@@ -28,7 +28,6 @@ describe('MatTree', () => {
2828
function configureMatTreeTestingModule(declarations: Type<any>[]) {
2929
TestBed.configureTestingModule({
3030
imports: [MatTreeModule],
31-
providers: [provideZoneChangeDetection()],
3231
declarations: declarations,
3332
}).compileComponents();
3433
}
@@ -64,6 +63,32 @@ describe('MatTree', () => {
6463
});
6564
});
6665

66+
it('with the right aria-level attrs', () => {
67+
// add a child to the first node
68+
const data = underlyingDataSource.data;
69+
underlyingDataSource.addChild(data[2]);
70+
component.treeControl.expandAll();
71+
fixture.detectChanges();
72+
73+
const ariaLevels = getNodes(treeElement).map(n => n.getAttribute('aria-level'));
74+
expect(ariaLevels).toEqual(['1', '1', '1', '2']);
75+
});
76+
77+
it('with the right aria-expanded attrs', () => {
78+
// add a child to the first node
79+
const data = underlyingDataSource.data;
80+
underlyingDataSource.addChild(data[2]);
81+
fixture.detectChanges();
82+
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
83+
expect(ariaExpandedStates).toEqual([null, null, 'false']);
84+
85+
component.treeControl.expandAll();
86+
fixture.detectChanges();
87+
88+
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
89+
expect(ariaExpandedStates).toEqual([null, null, 'true', null]);
90+
});
91+
6792
it('with the right data', () => {
6893
expect(underlyingDataSource.data.length).toBe(3);
6994

@@ -608,6 +633,7 @@ describe('MatTree', () => {
608633

609634
it('ignores clicks on disabled items', () => {
610635
underlyingDataSource.data[1].isDisabled = true;
636+
fixture.changeDetectorRef.markForCheck();
611637
fixture.detectChanges();
612638

613639
// attempt to click on the first child

src/material/tree/tree.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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 {provideZoneChangeDetection, Component, ViewChild, Type} from '@angular/core';
8+
import {Component, ViewChild, Type} from '@angular/core';
99
import {ComponentFixture, TestBed} from '@angular/core/testing';
1010
import {BehaviorSubject, Observable} from 'rxjs';
1111
import {map} from 'rxjs/operators';
@@ -21,7 +21,6 @@ describe('MatTree', () => {
2121
function configureMatTreeTestingModule(declarations: Type<any>[]) {
2222
TestBed.configureTestingModule({
2323
imports: [MatTreeModule],
24-
providers: [provideZoneChangeDetection()],
2524
declarations: declarations,
2625
}).compileComponents();
2726
}
@@ -633,6 +632,7 @@ describe('MatTree', () => {
633632

634633
it('ignores clicks on disabled items', () => {
635634
underlyingDataSource.data[1].isDisabled = true;
635+
fixture.changeDetectorRef.markForCheck();
636636
fixture.detectChanges();
637637

638638
// attempt to click on the first child

0 commit comments

Comments
 (0)