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 } from '@angular/core' ;
9
+ import { Component , ViewChild , TrackByFunction , Type , EventEmitter } from '@angular/core' ;
10
10
11
11
import { CollectionViewer , DataSource } from '@angular/cdk/collections' ;
12
+ import { Directionality , Direction } from '@angular/cdk/bidi' ;
12
13
import { combineLatest , BehaviorSubject , Observable } from 'rxjs' ;
13
14
import { map } from 'rxjs/operators' ;
14
15
@@ -27,10 +28,15 @@ describe('CdkTree', () => {
27
28
let dataSource : FakeDataSource ;
28
29
let treeElement : HTMLElement ;
29
30
let tree : CdkTree < TestData > ;
31
+ let dir : { value : Direction , change : EventEmitter < Direction > } ;
30
32
31
33
function configureCdkTreeTestingModule ( declarations : Type < any > [ ] ) {
32
34
TestBed . configureTestingModule ( {
33
35
imports : [ CdkTreeModule ] ,
36
+ providers : [ {
37
+ provide : Directionality ,
38
+ useFactory : ( ) => dir = { value : 'ltr' , change : new EventEmitter < Direction > ( ) }
39
+ } ] ,
34
40
declarations : declarations ,
35
41
} ) . compileComponents ( ) ;
36
42
}
@@ -131,6 +137,23 @@ describe('CdkTree', () => {
131
137
[ `${ data [ 2 ] . pizzaTopping } - ${ data [ 2 ] . pizzaCheese } + ${ data [ 2 ] . pizzaBase } ` ] ) ;
132
138
} ) ;
133
139
140
+ it ( 'should reset the opposite direction padding if the direction changes' , ( ) => {
141
+ const node = getNodes ( treeElement ) [ 0 ] ;
142
+
143
+ component . indent = 10 ;
144
+ fixture . detectChanges ( ) ;
145
+
146
+ expect ( node . style . paddingLeft ) . toBe ( '10px' ) ;
147
+ expect ( node . style . paddingRight ) . toBeFalsy ( ) ;
148
+
149
+ dir . value = 'rtl' ;
150
+ dir . change . emit ( 'rtl' ) ;
151
+ fixture . detectChanges ( ) ;
152
+
153
+ expect ( node . style . paddingRight ) . toBe ( '10px' ) ;
154
+ expect ( node . style . paddingLeft ) . toBeFalsy ( ) ;
155
+ } ) ;
156
+
134
157
} ) ;
135
158
136
159
describe ( 'with toggle' , ( ) => {
@@ -1011,8 +1034,8 @@ class FakeDataSource extends DataSource<TestData> {
1011
1034
}
1012
1035
}
1013
1036
1014
- function getNodes ( treeElement : Element ) : Element [ ] {
1015
- return [ ] . slice . call ( treeElement . querySelectorAll ( '.cdk-tree-node' ) ) ! ;
1037
+ function getNodes ( treeElement : Element ) : HTMLElement [ ] {
1038
+ return Array . from ( treeElement . querySelectorAll ( '.cdk-tree-node' ) ) ;
1016
1039
}
1017
1040
1018
1041
function expectFlatTreeToMatch ( treeElement : Element ,
0 commit comments