1- import { Component , ElementRef , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
1+ import { Component , viewChildren , viewChild , ElementRef , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
22import { ComponentFixture , TestBed } from '@angular/core/testing' ;
33import { of } from 'rxjs' ;
44import { CdkTreeModule } from './tree-module' ;
@@ -7,21 +7,19 @@ import {NOOP_TREE_KEY_MANAGER_FACTORY_PROVIDER} from '@angular/cdk/a11y';
77describe ( 'CdkTree when provided LegacyTreeKeyManager' , ( ) => {
88 let fixture : ComponentFixture < SimpleCdkTreeApp > ;
99
10- beforeEach ( ( ) => {
10+ beforeEach ( async ( ) => {
1111 TestBed . configureTestingModule ( {
12- imports : [ CdkTreeModule ] ,
13- declarations : [ SimpleCdkTreeApp ] ,
12+ imports : [ SimpleCdkTreeApp ] ,
1413 providers : [ NOOP_TREE_KEY_MANAGER_FACTORY_PROVIDER ] ,
1514 } ) ;
1615
16+ await TestBed . compileComponents ( ) ;
1717 fixture = TestBed . createComponent ( SimpleCdkTreeApp ) ;
18- fixture . detectChanges ( ) ;
19- fixture . detectChanges ( ) ;
2018 } ) ;
2119
2220 describe ( 'with default node options' , ( ) => {
2321 it ( 'renders nodes with tabindex attribute of -1' , ( ) => {
24- const treeItems = fixture . componentInstance . treeNodes ;
22+ const treeItems = fixture . componentInstance . treeNodes ( ) ;
2523
2624 expect ( treeItems . map ( x => `${ x . nativeElement . getAttribute ( 'tabindex' ) } ` ) . join ( ', ' ) )
2725 . withContext ( 'tabindex of tree nodes' )
@@ -31,14 +29,14 @@ describe('CdkTree when provided LegacyTreeKeyManager', () => {
3129
3230 describe ( 'when focusing the second node' , ( ) => {
3331 beforeEach ( ( ) => {
34- const treeItems = fixture . componentInstance . treeNodes ;
32+ const treeItems = fixture . componentInstance . treeNodes ( ) ;
3533
36- treeItems . get ( 1 ) ! . nativeElement . focus ( ) ;
34+ treeItems [ 1 ] ! . nativeElement . focus ( ) ;
3735 fixture . detectChanges ( ) ;
3836 } ) ;
3937
4038 it ( 'does not change tabindex of nodes' , ( ) => {
41- const treeItems = fixture . componentInstance . treeNodes ;
39+ const treeItems = fixture . componentInstance . treeNodes ( ) ;
4240
4341 expect ( treeItems . map ( x => `${ x . nativeElement . getAttribute ( 'tabindex' ) } ` ) . join ( ', ' ) )
4442 . withContext ( 'tabindex of tree nodes' )
@@ -48,9 +46,9 @@ describe('CdkTree when provided LegacyTreeKeyManager', () => {
4846
4947 describe ( 'when clicking the second node' , ( ) => {
5048 beforeEach ( ( ) => {
51- const treeItems = fixture . componentInstance . treeNodes ;
49+ const treeItems = fixture . componentInstance . treeNodes ( ) ;
5250
53- treeItems . get ( 1 ) ! . nativeElement . click ( ) ;
51+ treeItems [ 1 ] ! . nativeElement . click ( ) ;
5452 fixture . detectChanges ( ) ;
5553 } ) ;
5654
@@ -59,7 +57,7 @@ describe('CdkTree when provided LegacyTreeKeyManager', () => {
5957 } ) ;
6058
6159 it ( 'does not change tabindex of nodes' , ( ) => {
62- const treeItems = fixture . componentInstance . treeNodes ;
60+ const treeItems = fixture . componentInstance . treeNodes ( ) ;
6361
6462 expect ( treeItems . map ( x => `${ x . nativeElement . getAttribute ( 'tabindex' ) } ` ) . join ( ', ' ) )
6563 . withContext ( 'tabindex of tree nodes' )
@@ -75,19 +73,20 @@ class MinimalTestData {
7573
7674@Component ( {
7775 template : `
78- <cdk-tree #tree [dataSource]="dataSource" [childrenAccessor]="getChildren">
76+ <cdk-tree [dataSource]="dataSource" [childrenAccessor]="getChildren">
7977 <cdk-tree-node #node *cdkTreeNodeDef="let node">
8078 {{node.name}}
8179 </cdk-tree-node>
8280 </cdk-tree>
8381 ` ,
82+ standalone : true ,
83+ imports : [ CdkTreeModule ] ,
8484} )
8585class SimpleCdkTreeApp {
8686 isExpandable = ( node : MinimalTestData ) => node . children . length > 0 ;
8787 getChildren = ( node : MinimalTestData ) => node . children ;
8888
8989 dataSource = of ( [ new MinimalTestData ( 'apple' ) , new MinimalTestData ( 'banana' ) ] ) ;
9090
91- @ViewChild ( 'tree' , { read : ElementRef } ) tree : ElementRef < HTMLElement > ;
92- @ViewChildren ( 'node' ) treeNodes : QueryList < ElementRef < HTMLElement > > ;
91+ readonly treeNodes = viewChildren < ElementRef < HTMLElement > > ( 'node' ) ;
9392}
0 commit comments