@@ -119,7 +119,6 @@ describe('CdkTree', () => {
119
119
if ( config . label !== undefined ) node . label = config . label ;
120
120
if ( config . children !== undefined ) node . children = config . children ;
121
121
if ( config . disabled !== undefined ) node . disabled = config . disabled ;
122
- if ( config . preserveContent !== undefined ) node . preserveContent = config . preserveContent ;
123
122
updateTree ( { nodes : newNodes } ) ;
124
123
return ;
125
124
}
@@ -151,6 +150,16 @@ describe('CdkTree', () => {
151
150
return item ?. getAttribute ( 'data-value' ) ?? undefined ;
152
151
}
153
152
153
+ function expandAll ( ) {
154
+ const fruitsEl = getTreeItemElementByValue ( 'fruits' ) ! ;
155
+ click ( fruitsEl ) ;
156
+ const berriesEl = getTreeItemElementByValue ( 'berries' ) ! ;
157
+ click ( berriesEl ) ;
158
+ const vegetablesEl = getTreeItemElementByValue ( 'vegetables' ) ! ;
159
+ click ( vegetablesEl ) ;
160
+ updateTree ( { value : [ ] } ) ;
161
+ }
162
+
154
163
afterEach ( async ( ) => {
155
164
fixture . detectChanges ( ) ;
156
165
await runAccessibilityChecks ( fixture . nativeElement ) ;
@@ -160,17 +169,15 @@ describe('CdkTree', () => {
160
169
describe ( 'default configuration' , ( ) => {
161
170
beforeEach ( ( ) => {
162
171
setupTestTree ( ) ;
163
- // Preserve collapsed children nodes for checking attributes.
164
- updateTreeItemByValue ( 'fruits' , { preserveContent : true } ) ;
165
- updateTreeItemByValue ( 'berries' , { preserveContent : true } ) ;
166
- updateTreeItemByValue ( 'vegetables' , { preserveContent : true } ) ;
167
172
} ) ;
168
173
169
174
it ( 'should correctly set the role attribute to "tree" for CdkTree' , ( ) => {
170
175
expect ( treeElement . getAttribute ( 'role' ) ) . toBe ( 'tree' ) ;
171
176
} ) ;
172
177
173
178
it ( 'should correctly set the role attribute to "treeitem" for CdkTreeItem' , ( ) => {
179
+ expandAll ( ) ;
180
+
174
181
expect ( getTreeItemElementByValue ( 'fruits' ) ! . getAttribute ( 'role' ) ) . toBe ( 'treeitem' ) ;
175
182
expect ( getTreeItemElementByValue ( 'vegetables' ) ! . getAttribute ( 'role' ) ) . toBe ( 'treeitem' ) ;
176
183
expect ( getTreeItemElementByValue ( 'grains' ) ! . getAttribute ( 'role' ) ) . toBe ( 'treeitem' ) ;
@@ -183,6 +190,8 @@ describe('CdkTree', () => {
183
190
} ) ;
184
191
185
192
it ( 'should correctly set the role attribute to "group" for CdkTreeItemGroup' , ( ) => {
193
+ expandAll ( ) ;
194
+
186
195
expect ( getTreeItemGroupElementByValue ( 'fruits' ) ! . getAttribute ( 'role' ) ) . toBe ( 'group' ) ;
187
196
expect ( getTreeItemGroupElementByValue ( 'vegetables' ) ! . getAttribute ( 'role' ) ) . toBe ( 'group' ) ;
188
197
expect ( getTreeItemGroupElementByValue ( 'berries' ) ! . getAttribute ( 'role' ) ) . toBe ( 'group' ) ;
@@ -215,17 +224,19 @@ describe('CdkTree', () => {
215
224
} ) ;
216
225
217
226
it ( 'should set aria-level, aria-setsize, and aria-posinset correctly' , ( ) => {
227
+ expandAll ( ) ;
228
+
218
229
const fruits = getTreeItemElementByValue ( 'fruits' ) ! ;
219
230
expect ( fruits . getAttribute ( 'aria-level' ) ) . toBe ( '1' ) ;
220
231
expect ( fruits . getAttribute ( 'aria-setsize' ) ) . toBe ( '4' ) ;
221
232
expect ( fruits . getAttribute ( 'aria-posinset' ) ) . toBe ( '1' ) ;
222
- expect ( fruits . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false ' ) ;
233
+ expect ( fruits . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true ' ) ;
223
234
224
235
const vegetables = getTreeItemElementByValue ( 'vegetables' ) ! ;
225
236
expect ( vegetables . getAttribute ( 'aria-level' ) ) . toBe ( '1' ) ;
226
237
expect ( vegetables . getAttribute ( 'aria-setsize' ) ) . toBe ( '4' ) ;
227
238
expect ( vegetables . getAttribute ( 'aria-posinset' ) ) . toBe ( '2' ) ;
228
- expect ( vegetables . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false ' ) ;
239
+ expect ( vegetables . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true ' ) ;
229
240
230
241
const grains = getTreeItemElementByValue ( 'grains' ) ! ;
231
242
expect ( grains . getAttribute ( 'aria-level' ) ) . toBe ( '1' ) ;
@@ -246,7 +257,7 @@ describe('CdkTree', () => {
246
257
expect ( berries . getAttribute ( 'aria-level' ) ) . toBe ( '2' ) ;
247
258
expect ( berries . getAttribute ( 'aria-setsize' ) ) . toBe ( '3' ) ;
248
259
expect ( berries . getAttribute ( 'aria-posinset' ) ) . toBe ( '3' ) ;
249
- expect ( berries . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false ' ) ;
260
+ expect ( berries . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true ' ) ;
250
261
251
262
const strawberry = getTreeItemElementByValue ( 'strawberry' ) ! ;
252
263
expect ( strawberry . getAttribute ( 'aria-level' ) ) . toBe ( '3' ) ;
@@ -264,10 +275,6 @@ describe('CdkTree', () => {
264
275
describe ( 'custom configuration' , ( ) => {
265
276
beforeEach ( ( ) => {
266
277
setupTestTree ( ) ;
267
- // Preserve collapsed children nodes for checking attributes.
268
- updateTreeItemByValue ( 'fruits' , { preserveContent : true } ) ;
269
- updateTreeItemByValue ( 'berries' , { preserveContent : true } ) ;
270
- updateTreeItemByValue ( 'vegetables' , { preserveContent : true } ) ;
271
278
} ) ;
272
279
273
280
it ( 'should set aria-orientation to "horizontal"' , ( ) => {
@@ -296,6 +303,7 @@ describe('CdkTree', () => {
296
303
} ) ;
297
304
298
305
it ( 'should set aria-selected to "true" for selected items' , ( ) => {
306
+ expandAll ( ) ;
299
307
updateTree ( { value : [ 'apple' ] } ) ;
300
308
301
309
const appleItem = getTreeItemElementByValue ( 'apple' ) ! ;
@@ -306,11 +314,13 @@ describe('CdkTree', () => {
306
314
307
315
it ( 'should set aria-expanded to "true" for expanded items' , ( ) => {
308
316
right ( ) ;
317
+
309
318
const fruitsItem = getTreeItemElementByValue ( 'fruits' ) ! ;
310
319
expect ( fruitsItem . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
311
320
} ) ;
312
321
313
322
it ( 'should set aria-current to specific current type when nav="true"' , ( ) => {
323
+ expandAll ( ) ;
314
324
updateTree ( { nav : true , value : [ 'apple' ] } ) ;
315
325
316
326
const appleItem = getTreeItemElementByValue ( 'apple' ) ! ;
@@ -323,6 +333,8 @@ describe('CdkTree', () => {
323
333
} ) ;
324
334
325
335
it ( 'should not set aria-selected when nav="true"' , ( ) => {
336
+ expandAll ( ) ;
337
+
326
338
updateTree ( { value : [ 'apple' ] , nav : true } ) ;
327
339
const appleItem = getTreeItemElementByValue ( 'apple' ) ! ;
328
340
expect ( appleItem . hasAttribute ( 'aria-selected' ) ) . toBe ( false ) ;
@@ -402,10 +414,7 @@ describe('CdkTree', () => {
402
414
} ) ;
403
415
404
416
it ( 'should set tabindex="-1" for all items' , ( ) => {
405
- // Preserve collapsed children nodes for checking attributes.
406
- updateTreeItemByValue ( 'fruits' , { preserveContent : true } ) ;
407
- updateTreeItemByValue ( 'berries' , { preserveContent : true } ) ;
408
- updateTreeItemByValue ( 'vegetables' , { preserveContent : true } ) ;
417
+ expandAll ( ) ;
409
418
410
419
expect ( getTreeItemElementByValue ( 'fruits' ) ! . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
411
420
expect ( getTreeItemElementByValue ( 'apple' ) ! . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
@@ -425,10 +434,7 @@ describe('CdkTree', () => {
425
434
describe ( 'value and selection' , ( ) => {
426
435
it ( 'should select items based on the initial value input' , ( ) => {
427
436
setupTestTree ( ) ;
428
- // Preserve collapsed children nodes for checking attributes.
429
- updateTreeItemByValue ( 'fruits' , { preserveContent : true } ) ;
430
- updateTreeItemByValue ( 'berries' , { preserveContent : true } ) ;
431
- updateTreeItemByValue ( 'vegetables' , { preserveContent : true } ) ;
437
+ expandAll ( ) ;
432
438
updateTree ( { value : [ 'apple' , 'strawberry' , 'carrot' ] } ) ;
433
439
434
440
expect ( getTreeItemElementByValue ( 'apple' ) ! . getAttribute ( 'aria-selected' ) ) . toBe ( 'true' ) ;
@@ -1320,7 +1326,6 @@ interface TestTreeNode<V = string> {
1320
1326
label : string ;
1321
1327
disabled ?: boolean ;
1322
1328
children ?: TestTreeNode < V > [ ] ;
1323
- preserveContent ?: boolean ;
1324
1329
}
1325
1330
1326
1331
@Component ( {
@@ -1359,7 +1364,6 @@ interface TestTreeNode<V = string> {
1359
1364
<ul
1360
1365
cdkTreeItemGroup
1361
1366
[ownedBy]="treeItem"
1362
- [preserveContent]="!!node.preserveContent"
1363
1367
[attr.data-group-for]="node.value"
1364
1368
#group="cdkTreeItemGroup">
1365
1369
<ng-template cdkTreeItemGroupContent>
0 commit comments