File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
src/material/tree/testing Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,28 @@ export function runHarnessTests(
96
96
// no-op if already collapsed
97
97
expect ( await firstGroup . isExpanded ( ) ) . toBe ( false ) ;
98
98
} ) ;
99
+
100
+ it ( 'should correctly get tree structure' , async ( ) => {
101
+ const trees = await loader . getAllHarnesses ( treeHarness ) ;
102
+ const flatTree = trees [ 0 ] ;
103
+ expect ( await flatTree . getTreeStructure ( ) ) . toEqual (
104
+ `Flat Group 1
105
+ Flat Group 2` ) ;
106
+ } ) ;
107
+
108
+ it ( 'should correctly get tree structure' , async ( ) => {
109
+ const trees = await loader . getAllHarnesses ( treeHarness ) ;
110
+ const nestedTree = trees [ 1 ] ;
111
+ expect ( await nestedTree . getTreeStructure ( ) ) . toEqual (
112
+ `Nested Group 1
113
+ \tNested Leaf 1.1
114
+ \tNested Leaf 1.2
115
+ \tNested Leaf 1.3
116
+ Nested Group 2
117
+ \tNested Group 2.1
118
+ \t\tNested Leaf 2.1.1
119
+ \t\tNested Leaf 2.1.2` ) ;
120
+ } ) ;
99
121
}
100
122
101
123
interface FoodNode {
Original file line number Diff line number Diff line change @@ -28,4 +28,17 @@ export class MatTreeHarness extends ComponentHarness {
28
28
async getNodes ( filter : TreeNodeHarnessFilters = { } ) : Promise < MatTreeNodeHarness [ ] > {
29
29
return this . locatorForAll ( MatTreeNodeHarness . with ( filter ) ) ( ) ;
30
30
}
31
+
32
+ async getTreeStructure ( ) : Promise < string > {
33
+ let treeString = '' ;
34
+ const nodes = await this . getNodes ( ) ;
35
+ for ( let i = 0 ; i < nodes . length ; i ++ ) {
36
+ treeString += i === 0 ? '' : '\n' ;
37
+ const node = nodes [ i ] ;
38
+ const level = await node . getLevel ( ) ;
39
+ treeString += '\t' . repeat ( level - 1 ) ;
40
+ treeString += await node . getText ( ) ;
41
+ }
42
+ return treeString ;
43
+ }
31
44
}
You can’t perform that action at this time.
0 commit comments