66 * found in the LICENSE file at https://angular.io/license
77 */
88import { 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' ;
1018
1119import { CollectionViewer , DataSource } from '@angular/cdk/collections' ;
1220import { Directionality , Direction } from '@angular/cdk/bidi' ;
@@ -17,7 +25,7 @@ import {BaseTreeControl} from './control/base-tree-control';
1725import { TreeControl } from './control/tree-control' ;
1826import { FlatTreeControl } from './control/flat-tree-control' ;
1927import { NestedTreeControl } from './control/nested-tree-control' ;
20- import { CdkTreeModule } from './index' ;
28+ import { CdkTreeModule , CdkTreeNodePadding } from './index' ;
2129import { CdkTree , CdkTreeNode } from './tree' ;
2230import { getTreeControlFunctionsMissingError } from './tree-errors' ;
2331
@@ -137,6 +145,18 @@ describe('CdkTree', () => {
137145 [ `${ data [ 2 ] . pizzaTopping } - ${ data [ 2 ] . pizzaCheese } + ${ data [ 2 ] . pizzaBase } ` ] ) ;
138146 } ) ;
139147
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+
140160 it ( 'should reset the opposite direction padding if the direction changes' , ( ) => {
141161 const node = getNodes ( treeElement ) [ 0 ] ;
142162
@@ -1046,7 +1066,10 @@ function expectFlatTreeToMatch(treeElement: Element,
10461066 }
10471067
10481068 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 ;
10501073 const expectedLevel = `${ ( expectedNode . length ) * expectedPaddingIndent } ${ expectedPaddingUnits } ` ;
10511074 if ( actualLevel != expectedLevel ) {
10521075 missedExpectations . push (
@@ -1132,7 +1155,7 @@ class SimpleCdkTreeApp {
11321155 indent : number | string = 28 ;
11331156
11341157 @ViewChild ( CdkTree , { static : false } ) tree : CdkTree < TestData > ;
1135-
1158+ @ ViewChildren ( CdkTreeNodePadding ) paddingNodes : QueryList < CdkTreeNodePadding < TestData > > ;
11361159}
11371160
11381161@Component ( {
0 commit comments