Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions src/cdk/tree/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ describe('CdkTree', () => {
configureCdkTreeTestingModule([SimpleCdkTreeApp]);
fixture = TestBed.createComponent(SimpleCdkTreeApp);

fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with a connected data source', () => {
Expand Down Expand Up @@ -141,12 +141,12 @@ describe('CdkTree', () => {
configureCdkTreeTestingModule([CdkTreeAppWithToggle]);
fixture = TestBed.createComponent(CdkTreeAppWithToggle);

fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('should expand/collapse the node', () => {
Expand Down Expand Up @@ -227,12 +227,12 @@ describe('CdkTree', () => {
configureCdkTreeTestingModule([WhenNodeCdkTreeApp]);
fixture = TestBed.createComponent(WhenNodeCdkTreeApp);

fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -265,13 +265,13 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([ArrayDataSourceCdkTreeApp]);
fixture = TestBed.createComponent(ArrayDataSourceCdkTreeApp);
fixture.detectChanges();


component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -305,12 +305,12 @@ describe('CdkTree', () => {
configureCdkTreeTestingModule([ObservableDataSourceCdkTreeApp]);
fixture = TestBed.createComponent(ObservableDataSourceCdkTreeApp);

fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -343,13 +343,14 @@ describe('CdkTree', () => {
function createTrackByTestComponent(trackByStrategy: 'reference' | 'property' | 'index') {
configureCdkTreeTestingModule([CdkTreeAppWithTrackBy]);
fixture = TestBed.createComponent(CdkTreeAppWithTrackBy);
fixture.detectChanges();

component = fixture.componentInstance;
component.trackByStrategy = trackByStrategy;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();

// Each node receives an attribute 'initialIndex' the element's original place
getNodes(treeElement).forEach((node: Element, index: number) => {
Expand Down Expand Up @@ -436,13 +437,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([NestedCdkTreeApp]);
fixture = TestBed.createComponent(NestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with a connected data source', () => {
Expand Down Expand Up @@ -524,13 +524,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([StaticNestedCdkTreeApp]);
fixture = TestBed.createComponent(StaticNestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand All @@ -551,13 +550,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([WhenNodeNestedCdkTreeApp]);
fixture = TestBed.createComponent(WhenNodeNestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -590,13 +588,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([NestedCdkTreeAppWithToggle]);
fixture = TestBed.createComponent(NestedCdkTreeAppWithToggle);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('should expand/collapse the node multiple times', () => {
Expand Down Expand Up @@ -689,13 +686,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([ArrayDataSourceNestedCdkTreeApp]);
fixture = TestBed.createComponent(ArrayDataSourceNestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -726,13 +722,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([ObservableDataSourceNestedCdkTreeApp]);
fixture = TestBed.createComponent(ObservableDataSourceNestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('with the right data', () => {
Expand Down Expand Up @@ -763,15 +758,15 @@ describe('CdkTree', () => {
function createTrackByTestComponent(trackByStrategy: 'reference' | 'property' | 'index') {
configureCdkTreeTestingModule([NestedCdkTreeAppWithTrackBy]);
fixture = TestBed.createComponent(NestedCdkTreeAppWithTrackBy);
fixture.detectChanges();

component = fixture.componentInstance;
component.trackByStrategy = trackByStrategy;
dataSource = component.dataSource as FakeDataSource;

tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();

// Each node receives an attribute 'initialIndex' the element's original place
getNodes(treeElement).forEach((node: Element, index: number) => {
node.setAttribute('initialIndex', index.toString());
Expand Down Expand Up @@ -912,13 +907,12 @@ describe('CdkTree', () => {
beforeEach(() => {
configureCdkTreeTestingModule([DepthNestedCdkTreeApp]);
fixture = TestBed.createComponent(DepthNestedCdkTreeApp);
fixture.detectChanges();

component = fixture.componentInstance;
dataSource = component.dataSource as FakeDataSource;
tree = component.tree;
treeElement = fixture.nativeElement.querySelector('cdk-tree');

fixture.detectChanges();
});

it('should have correct depth for nested tree', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class CdkTree<T>
@Input() trackBy: TrackByFunction<T>;

// Outlets within the tree's template where the dataNodes will be inserted.
@ViewChild(CdkTreeNodeOutlet) _nodeOutlet: CdkTreeNodeOutlet;
@ViewChild(CdkTreeNodeOutlet, {static: true}) _nodeOutlet: CdkTreeNodeOutlet;

/** The tree node template for the tree */
@ContentChildren(CdkTreeNodeDef) _nodeDefs: QueryList<CdkTreeNodeDef<T>>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ import {MatTreeNodeOutlet} from './outlet';
})
export class MatTree<T> extends CdkTree<T> {
// Outlets within the tree's template where the dataNodes will be inserted.
@ViewChild(MatTreeNodeOutlet) _nodeOutlet: MatTreeNodeOutlet;
@ViewChild(MatTreeNodeOutlet, {static: true}) _nodeOutlet: MatTreeNodeOutlet;
}