99import { ComponentHarness , HarnessPredicate } from '@angular/cdk/testing' ;
1010import { ListboxHarnessFilters , ListboxOptionHarnessFilters } from './listbox-harness-filters' ;
1111
12+ /** Harness for interacting with a standard ngOption in tests. */
1213export class ListboxOptionHarness extends ComponentHarness {
1314 static hostSelector = '[ngOption]' ;
1415
16+ /**
17+ * Gets a `HarnessPredicate` that can be used to search for an option
18+ * with specific attributes.
19+ * @param options Options for filtering which option instances are considered a match.
20+ * @return a `HarnessPredicate` configured with the given options.
21+ */
1522 static with ( options : ListboxOptionHarnessFilters = { } ) : HarnessPredicate < ListboxOptionHarness > {
1623 return new HarnessPredicate ( ListboxOptionHarness , options )
1724 . addOption ( 'text' , options . text , ( harness , text ) =>
@@ -29,11 +36,13 @@ export class ListboxOptionHarness extends ComponentHarness {
2936 ) ;
3037 }
3138
39+ /** Whether the option is selected. */
3240 async isSelected ( ) : Promise < boolean > {
3341 const host = await this . host ( ) ;
3442 return ( await host . getAttribute ( 'aria-selected' ) ) === 'true' ;
3543 }
3644
45+ /** Whether the option is disabled. */
3746 async isDisabled ( ) : Promise < boolean > {
3847 const host = await this . host ( ) ;
3948 return (
@@ -42,20 +51,29 @@ export class ListboxOptionHarness extends ComponentHarness {
4251 ) ;
4352 }
4453
54+ /** Gets the option's text. */
4555 async getText ( ) : Promise < string > {
4656 const host = await this . host ( ) ;
4757 return host . text ( ) ;
4858 }
4959
60+ /** Clicks the option to toggle its selected state. */
5061 async click ( ) : Promise < void > {
5162 const host = await this . host ( ) ;
5263 return host . click ( ) ;
5364 }
5465}
5566
67+ /** Harness for interacting with a standard ngListbox in tests. */
5668export class ListboxHarness extends ComponentHarness {
5769 static hostSelector = '[ngListbox]' ;
5870
71+ /**
72+ * Gets a `HarnessPredicate` that can be used to search for a listbox
73+ * with specific attributes.
74+ * @param options Options for filtering which listbox instances are considered a match.
75+ * @return a `HarnessPredicate` configured with the given options.
76+ */
5977 static with ( options : ListboxHarnessFilters = { } ) : HarnessPredicate < ListboxHarness > {
6078 return new HarnessPredicate ( ListboxHarness , options ) . addOption (
6179 'disabled' ,
@@ -64,26 +82,31 @@ export class ListboxHarness extends ComponentHarness {
6482 ) ;
6583 }
6684
85+ /** Gets the orientation of the listbox. */
6786 async getOrientation ( ) : Promise < 'vertical' | 'horizontal' > {
6887 const host = await this . host ( ) ;
6988 const orientation = await host . getAttribute ( 'aria-orientation' ) ;
7089 return orientation === 'horizontal' ? 'horizontal' : 'vertical' ;
7190 }
7291
92+ /** Whether the listbox is multiselectable. */
7393 async isMulti ( ) : Promise < boolean > {
7494 const host = await this . host ( ) ;
7595 return ( await host . getAttribute ( 'aria-multiselectable' ) ) === 'true' ;
7696 }
7797
98+ /** Whether the listbox is disabled. */
7899 async isDisabled ( ) : Promise < boolean > {
79100 const host = await this . host ( ) ;
80101 return ( await host . getAttribute ( 'aria-disabled' ) ) === 'true' ;
81102 }
82103
104+ /** Gets the options inside the listbox. */
83105 async getOptions ( filters : ListboxOptionHarnessFilters = { } ) : Promise < ListboxOptionHarness [ ] > {
84106 return this . locatorForAll ( ListboxOptionHarness . with ( filters ) ) ( ) ;
85107 }
86108
109+ /** Focuses the listbox container. */
87110 async focus ( ) : Promise < void > {
88111 await ( await this . host ( ) ) . focus ( ) ;
89112 }
@@ -92,4 +115,10 @@ export class ListboxHarness extends ComponentHarness {
92115 async blur ( ) : Promise < void > {
93116 await ( await this . host ( ) ) . blur ( ) ;
94117 }
118+
119+ /** Gets the ID of the active option. */
120+ async getActiveDescendantId ( ) : Promise < string | null > {
121+ const host = await this . host ( ) ;
122+ return host . getAttribute ( 'aria-activedescendant' ) ;
123+ }
95124}
0 commit comments