File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
114134interface TreeNode {
You can’t perform that action at this time.
0 commit comments