File tree Expand file tree Collapse file tree 7 files changed +41
-4
lines changed
tools/public_api_guard/material Expand file tree Collapse file tree 7 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -13,4 +13,7 @@ import {BaseHarnessFilters} from '@angular/cdk/testing';
1313 * @deprecated Use `SelectHarnessFilters` from `@angular/material/select/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
1414 * @breaking -change 17.0.0
1515 */
16- export interface LegacySelectHarnessFilters extends BaseHarnessFilters { }
16+ export interface LegacySelectHarnessFilters extends BaseHarnessFilters {
17+ /** Only find instances which match the given disabled state. */
18+ disabled ?: boolean ;
19+ }
Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ export class MatLegacySelectHarness extends _MatSelectHarnessBase<
4141 * @return a `HarnessPredicate` configured with the given options.
4242 */
4343 static with ( options : LegacySelectHarnessFilters = { } ) : HarnessPredicate < MatLegacySelectHarness > {
44- return new HarnessPredicate ( MatLegacySelectHarness , options ) ;
44+ return new HarnessPredicate ( MatLegacySelectHarness , options ) . addOption (
45+ 'disabled' ,
46+ options . disabled ,
47+ async ( harness , disabled ) => {
48+ return ( await harness . isDisabled ( ) ) === disabled ;
49+ } ,
50+ ) ;
4551 }
4652}
Original file line number Diff line number Diff line change 99import { BaseHarnessFilters } from '@angular/cdk/testing' ;
1010
1111/** A set of criteria that can be used to filter a list of `MatSelectHarness` instances. */
12- export interface SelectHarnessFilters extends BaseHarnessFilters { }
12+ export interface SelectHarnessFilters extends BaseHarnessFilters {
13+ /** Only find instances which match the given disabled state. */
14+ disabled ?: boolean ;
15+ }
Original file line number Diff line number Diff line change @@ -182,6 +182,12 @@ export class MatSelectHarness extends _MatSelectHarnessBase<
182182 this : ComponentHarnessConstructor < T > ,
183183 options : SelectHarnessFilters = { } ,
184184 ) : HarnessPredicate < T > {
185- return new HarnessPredicate ( this , options ) ;
185+ return new HarnessPredicate ( this , options ) . addOption (
186+ 'disabled' ,
187+ options . disabled ,
188+ async ( harness , disabled ) => {
189+ return ( await harness . isDisabled ( ) ) === disabled ;
190+ } ,
191+ ) ;
186192 }
187193}
Original file line number Diff line number Diff line change @@ -44,6 +44,23 @@ export function runHarnessTests(
4444 expect ( selects . length ) . toBe ( 4 ) ;
4545 } ) ;
4646
47+ it ( 'should filter by whether a select is disabled' , async ( ) => {
48+ let enabledSelects = await loader . getAllHarnesses ( selectHarness . with ( { disabled : false } ) ) ;
49+ let disabledSelects = await loader . getAllHarnesses ( selectHarness . with ( { disabled : true } ) ) ;
50+
51+ expect ( enabledSelects . length ) . toBe ( 4 ) ;
52+ expect ( disabledSelects . length ) . toBe ( 0 ) ;
53+
54+ fixture . componentInstance . isDisabled = true ;
55+ fixture . detectChanges ( ) ;
56+
57+ enabledSelects = await loader . getAllHarnesses ( selectHarness . with ( { disabled : false } ) ) ;
58+ disabledSelects = await loader . getAllHarnesses ( selectHarness . with ( { disabled : true } ) ) ;
59+
60+ expect ( enabledSelects . length ) . toBe ( 3 ) ;
61+ expect ( disabledSelects . length ) . toBe ( 1 ) ;
62+ } ) ;
63+
4764 it ( 'should be able to check whether a select is in multi-selection mode' , async ( ) => {
4865 const singleSelection = await loader . getHarness (
4966 selectHarness . with ( {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { _MatSelectHarnessBase } from '@angular/material/select/testing';
1414
1515// @public @deprecated
1616export interface LegacySelectHarnessFilters extends BaseHarnessFilters {
17+ disabled? : boolean ;
1718}
1819
1920// @public @deprecated
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ export abstract class _MatSelectHarnessBase<OptionType extends ComponentHarnessC
6060
6161// @public
6262export interface SelectHarnessFilters extends BaseHarnessFilters {
63+ disabled? : boolean ;
6364}
6465
6566// (No @packageDocumentation comment for this package)
You can’t perform that action at this time.
0 commit comments