Skip to content

Commit aac4a31

Browse files
committed
test(aria/tree): generate additional methods and tests for Tree harness
1 parent 5a54e5b commit aac4a31

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/aria/tree/testing/item-harness.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ export class TreeItemHarness extends ContentContainerComponentHarness<string> {
7676
return (await this.host()).click();
7777
}
7878

79+
/** Focuses the tree item. */
80+
async focus(): Promise<void> {
81+
return (await this.host()).focus();
82+
}
83+
84+
/** Blurs the tree item. */
85+
async blur(): Promise<void> {
86+
return (await this.host()).blur();
87+
}
88+
89+
/** Whether the tree item is active. */
90+
async isActive(): Promise<boolean> {
91+
return (await this._getHostAttribute('data-active')) === 'true';
92+
}
93+
94+
/** Whether the tree item has focus. */
95+
async isFocused(): Promise<boolean> {
96+
return (await this.host()).isFocused();
97+
}
98+
7999
private async _getHostAttribute(attributeName: string): Promise<string | null> {
80100
return (await this.host()).getAttribute(attributeName);
81101
}

src/aria/tree/testing/tree-harness.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ describe('TreeHarness', () => {
109109
],
110110
});
111111
});
112+
113+
it('should be able to get whether a tree item has focus', async () => {
114+
const tree = await loader.getHarness(TreeHarness);
115+
const item = (await tree.getItems({text: 'angular.json'}))[0];
116+
117+
expect(await item.isFocused()).toBeFalse();
118+
119+
await item.focus();
120+
expect(await item.isFocused()).toBeTrue();
121+
122+
await item.blur();
123+
expect(await item.isFocused()).toBeFalse();
124+
});
125+
126+
it('should be able to get whether a tree item is active', async () => {
127+
const tree = await loader.getHarness(TreeHarness);
128+
const item = (await tree.getItems({text: 'public'}))[0];
129+
130+
expect(await item.isActive()).toBeTrue();
131+
});
112132
});
113133

114134
interface TreeNode {

0 commit comments

Comments
 (0)