Skip to content

Commit d220ab6

Browse files
committed
fix(cdk/tree): tests from merge conflicts
1 parent ac89503 commit d220ab6

File tree

4 files changed

+52
-35
lines changed

4 files changed

+52
-35
lines changed

src/cdk/tree/tree-with-tree-control.spec.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,41 @@ describe('CdkTree with TreeControl', () => {
117117
expect(nodes[0].classList).toContain('customNodeClass');
118118
});
119119

120+
it('with the right accessibility roles', () => {
121+
expect(treeElement.getAttribute('role')).toBe('tree');
122+
123+
expect(
124+
getNodes(treeElement).every(node => {
125+
return node.getAttribute('role') === 'treeitem';
126+
}),
127+
).toBe(true);
128+
});
129+
130+
it('with the right aria-levels', () => {
131+
// add a child to the first node
132+
let data = dataSource.data;
133+
dataSource.addChild(data[0], true);
134+
fixture.detectChanges();
135+
136+
const ariaLevels = getNodes(treeElement).map(n => n.getAttribute('aria-level'));
137+
expect(ariaLevels).toEqual(['2', '3', '2', '2']);
138+
});
139+
140+
it('with the right aria-expanded attrs', () => {
141+
// add a child to the first node
142+
let data = dataSource.data;
143+
dataSource.addChild(data[2]);
144+
fixture.detectChanges();
145+
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
146+
expect(ariaExpandedStates).toEqual([null, null, 'false', null]);
147+
148+
component.treeControl.expandAll();
149+
fixture.detectChanges();
150+
151+
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
152+
expect(ariaExpandedStates).toEqual([null, null, 'true', null]);
153+
});
154+
120155
it('with the right data', () => {
121156
expect(dataSource.data.length).toBe(3);
122157

@@ -762,13 +797,8 @@ describe('CdkTree with TreeControl', () => {
762797
});
763798

764799
it('with the right aria-expanded attrs', () => {
765-
expect(
766-
getNodes(treeElement)
767-
.map(x => `${x.getAttribute('aria-expanded')}`)
768-
.join(', '),
769-
)
770-
.withContext('aria-expanded attributes')
771-
.toEqual('false, false, false');
800+
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
801+
expect(ariaExpandedStates).toEqual([null, null, null]);
772802

773803
component.toggleRecursively = false;
774804
let data = dataSource.data;
@@ -782,13 +812,8 @@ describe('CdkTree with TreeControl', () => {
782812

783813
// Note: only four elements are present here; children are not present
784814
// in DOM unless the parent node is expanded.
785-
expect(
786-
getNodes(treeElement)
787-
.map(x => `${x.getAttribute('aria-expanded')}`)
788-
.join(', '),
789-
)
790-
.withContext('aria-expanded attributes')
791-
.toEqual('false, true, false, false');
815+
const ariaExpanded = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
816+
expect(ariaExpanded).toEqual([null, 'true', 'false', null]);
792817
});
793818

794819
it('should expand/collapse the node multiple times using keyboard', () => {
@@ -862,6 +887,7 @@ describe('CdkTree with TreeControl', () => {
862887
let data = dataSource.data;
863888
const child = dataSource.addChild(data[1], false);
864889
dataSource.addChild(child, false);
890+
fixture.changeDetectorRef.markForCheck();
865891
fixture.detectChanges();
866892

867893
expectNestedTreeToMatch(

src/cdk/tree/tree.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('CdkTree', () => {
151151
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
152152
expect(ariaExpandedStates).toEqual([null, null, 'false', null]);
153153

154-
component.expandAll();
154+
component.tree.expandAll();
155155
fixture.detectChanges();
156156

157157
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));

src/material/tree/tree-using-tree-control.spec.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,8 @@ describe('MatTree', () => {
440440
});
441441

442442
it('with the right aria-expanded attrs', () => {
443-
expect(
444-
getNodes(treeElement)
445-
.map(x => `${x.getAttribute('aria-expanded')}`)
446-
.join(', '),
447-
)
448-
.withContext('aria-expanded attributes')
449-
.toEqual('false, false, false');
443+
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
444+
expect(ariaExpandedStates).toEqual([null, null, null]);
450445

451446
component.toggleRecursively = false;
452447
const data = underlyingDataSource.data;
@@ -459,13 +454,8 @@ describe('MatTree', () => {
459454

460455
// Note: only four elements are present here; children are not present
461456
// in DOM unless the parent node is expanded.
462-
expect(
463-
getNodes(treeElement)
464-
.map(x => `${x.getAttribute('aria-expanded')}`)
465-
.join(', '),
466-
)
467-
.withContext('aria-expanded attributes')
468-
.toEqual('false, true, false, false');
457+
const ariaExpanded = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
458+
expect(ariaExpanded).toEqual([null, 'true', 'false', null]);
469459
});
470460

471461
it('should expand/collapse the node', () => {
@@ -644,7 +634,7 @@ describe('MatTree', () => {
644634
it('sets aria attributes for tree nodes', () => {
645635
expect(nodes.map(x => `${x.getAttribute('aria-expanded')}`).join(', '))
646636
.withContext('aria-expanded attributes')
647-
.toEqual('false, false, false, false, false, false');
637+
.toEqual('null, false, false, null, null, null');
648638
expect(nodes.map(x => `${x.getAttribute('aria-level')}`).join(', '))
649639
.withContext('aria-level attributes')
650640
.toEqual('1, 1, 2, 3, 3, 1');
@@ -661,13 +651,13 @@ describe('MatTree', () => {
661651
fixture.detectChanges();
662652
expect(nodes.map(x => `${x.getAttribute('aria-expanded')}`).join(', '))
663653
.withContext('aria-expanded attributes')
664-
.toEqual('false, true, false, false, false, false');
654+
.toEqual('null, true, false, null, null, null');
665655

666656
tree.collapse(underlyingDataSource.data[1]);
667657
fixture.detectChanges();
668658
expect(nodes.map(x => `${x.getAttribute('aria-expanded')}`).join(', '))
669659
.withContext('aria-expanded attributes')
670-
.toEqual('false, false, false, false, false, false');
660+
.toEqual('null, false, false, null, null, null');
671661
});
672662
});
673663
});

src/material/tree/tree.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('MatTree', () => {
6161
// add a child to the first node
6262
const data = underlyingDataSource.data;
6363
underlyingDataSource.addChild(data[2]);
64-
component.expandAll();
64+
component.tree.expandAll();
6565
fixture.detectChanges();
6666

6767
const ariaLevels = getNodes(treeElement).map(n => n.getAttribute('aria-level'));
@@ -76,7 +76,7 @@ describe('MatTree', () => {
7676
let ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
7777
expect(ariaExpandedStates).toEqual([null, null, 'false']);
7878

79-
component.expandAll();
79+
component.tree.expandAll();
8080
fixture.detectChanges();
8181

8282
ariaExpandedStates = getNodes(treeElement).map(n => n.getAttribute('aria-expanded'));
@@ -878,7 +878,8 @@ function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
878878
<mat-tree [dataSource]="dataSource" [childrenAccessor]="getChildren">
879879
<mat-tree-node *matTreeNodeDef="let node" class="customNodeClass"
880880
matTreeNodePadding [matTreeNodePaddingIndent]="28"
881-
matTreeNodeToggle>
881+
matTreeNodeToggle
882+
[isExpandable]="isExpandable(node)">
882883
{{node.pizzaTopping}} - {{node.pizzaCheese}} + {{node.pizzaBase}}
883884
</mat-tree-node>
884885
</mat-tree>

0 commit comments

Comments
 (0)