6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import { ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
9
- import { Component , ViewChild , TrackByFunction , Type , EventEmitter } from '@angular/core' ;
9
+ import {
10
+ Component ,
11
+ ViewChild ,
12
+ TrackByFunction ,
13
+ Type ,
14
+ EventEmitter ,
15
+ ViewChildren ,
16
+ QueryList ,
17
+ } from '@angular/core' ;
10
18
11
19
import { CollectionViewer , DataSource } from '@angular/cdk/collections' ;
12
20
import { Directionality , Direction } from '@angular/cdk/bidi' ;
@@ -17,7 +25,7 @@ import {BaseTreeControl} from './control/base-tree-control';
17
25
import { TreeControl } from './control/tree-control' ;
18
26
import { FlatTreeControl } from './control/flat-tree-control' ;
19
27
import { NestedTreeControl } from './control/nested-tree-control' ;
20
- import { CdkTreeModule } from './index' ;
28
+ import { CdkTreeModule , CdkTreeNodePadding } from './index' ;
21
29
import { CdkTree , CdkTreeNode } from './tree' ;
22
30
import { getTreeControlFunctionsMissingError } from './tree-errors' ;
23
31
@@ -137,6 +145,18 @@ describe('CdkTree', () => {
137
145
[ `${ data [ 2 ] . pizzaTopping } - ${ data [ 2 ] . pizzaCheese } + ${ data [ 2 ] . pizzaBase } ` ] ) ;
138
146
} ) ;
139
147
148
+ it ( 'should be able to set zero as the indent level' , ( ) => {
149
+ component . paddingNodes . forEach ( node => node . level = 0 ) ;
150
+ fixture . detectChanges ( ) ;
151
+
152
+ const data = dataSource . data ;
153
+
154
+ expectFlatTreeToMatch ( treeElement , 0 , 'px' ,
155
+ [ `${ data [ 0 ] . pizzaTopping } - ${ data [ 0 ] . pizzaCheese } + ${ data [ 0 ] . pizzaBase } ` ] ,
156
+ [ `${ data [ 1 ] . pizzaTopping } - ${ data [ 1 ] . pizzaCheese } + ${ data [ 1 ] . pizzaBase } ` ] ,
157
+ [ `${ data [ 2 ] . pizzaTopping } - ${ data [ 2 ] . pizzaCheese } + ${ data [ 2 ] . pizzaBase } ` ] ) ;
158
+ } ) ;
159
+
140
160
it ( 'should reset the opposite direction padding if the direction changes' , ( ) => {
141
161
const node = getNodes ( treeElement ) [ 0 ] ;
142
162
@@ -1046,7 +1066,10 @@ function expectFlatTreeToMatch(treeElement: Element,
1046
1066
}
1047
1067
1048
1068
function checkLevel ( node : Element , expectedNode : any [ ] ) {
1049
- const actualLevel = ( node as HTMLElement ) . style . paddingLeft ;
1069
+ const rawLevel = ( node as HTMLElement ) . style . paddingLeft ;
1070
+
1071
+ // Some browsers return 0, while others return 0px.
1072
+ const actualLevel = rawLevel === '0' ? '0px' : rawLevel ;
1050
1073
const expectedLevel = `${ ( expectedNode . length ) * expectedPaddingIndent } ${ expectedPaddingUnits } ` ;
1051
1074
if ( actualLevel != expectedLevel ) {
1052
1075
missedExpectations . push (
@@ -1132,7 +1155,7 @@ class SimpleCdkTreeApp {
1132
1155
indent : number | string = 28 ;
1133
1156
1134
1157
@ViewChild ( CdkTree , { static : false } ) tree : CdkTree < TestData > ;
1135
-
1158
+ @ ViewChildren ( CdkTreeNodePadding ) paddingNodes : QueryList < CdkTreeNodePadding < TestData > > ;
1136
1159
}
1137
1160
1138
1161
@Component ( {
0 commit comments