File tree Expand file tree Collapse file tree 7 files changed +17
-32
lines changed
form-field/testing/control Expand file tree Collapse file tree 7 files changed +17
-32
lines changed Original file line number Diff line number Diff line change @@ -542,7 +542,7 @@ export abstract class ContentContainerComponentHarness<S extends string = string
542542 return ( await this . getRootHarnessLoader ( ) ) . getAllHarnesses ( query ) ;
543543 }
544544
545- /**
545+ /**
546546 * Returns the number of matching harnesses for the given query within the current harness's
547547 * content.
548548 *
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ export class MatDateRangeInputHarness extends DatepickerTriggerHarnessBase {
9393
9494 /** Gets the floating label text for the range input, if it exists. */
9595 async getLabel ( ) : Promise < string | null > {
96- // Copied from MatFormFieldControlHarness since this class cannot extend two classes
96+ // Copied from MatFormFieldControlHarnessBase since this class cannot extend two classes
9797 const documentRootLocator = await this . documentRootLocatorFactory ( ) ;
9898 const labelId = await ( await this . host ( ) ) . getAttribute ( 'aria-labelledby' ) ;
9999 const hostId = await ( await this . host ( ) ) . getAttribute ( 'id' ) ;
Original file line number Diff line number Diff line change 77 */
88
99import { ComponentHarnessConstructor , HarnessPredicate } from '@angular/cdk/testing' ;
10- import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control' ;
10+ import { MatFormFieldControlHarnessBase } from '@angular/material/form-field/testing/control' ;
1111import { DatepickerInputHarnessFilters } from './datepicker-harness-filters' ;
1212
1313/** Sets up the filter predicates for a datepicker input harness. */
@@ -28,7 +28,7 @@ export function getInputPredicate<T extends MatDatepickerInputHarnessBase>(
2828}
2929
3030/** Base class for datepicker input harnesses. */
31- export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarness {
31+ export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarnessBase {
3232 /** Whether the input is disabled. */
3333 async isDisabled ( ) : Promise < boolean > {
3434 return ( await this . host ( ) ) . getProperty < boolean > ( 'disabled' ) ;
@@ -39,11 +39,6 @@ export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlH
3939 return ( await this . host ( ) ) . getProperty < boolean > ( 'required' ) ;
4040 }
4141
42- /** Gets the floating label text for the input, if it exists. */
43- async getLabel ( ) : Promise < string | null > {
44- return await this . _getFloatingLabelText ( ) ;
45- }
46-
4742 /** Gets the value of the input. */
4843 async getValue ( ) : Promise < string > {
4944 // The "value" property of the native input is always defined.
Original file line number Diff line number Diff line change @@ -12,11 +12,16 @@ import {ComponentHarness} from '@angular/cdk/testing';
1212 * Base class for custom form-field control harnesses. Harnesses for
1313 * custom controls with form-fields need to implement this interface.
1414 */
15- export abstract class MatFormFieldControlHarness extends ComponentHarness {
15+ export abstract class MatFormFieldControlHarness extends ComponentHarness { }
16+
17+ /**
18+ * Shared functionality for many MatFormFieldControlHarnesses
19+ */
20+ export abstract class MatFormFieldControlHarnessBase extends MatFormFieldControlHarness {
1621 private readonly floatingLabelSelector = '.mdc-floating-label' ;
1722
1823 /** Gets the text content of the floating label, if it exists. */
19- protected async _getFloatingLabelText ( ) : Promise < string | null > {
24+ public async getLabel ( ) : Promise < string | null > {
2025 const documentRootLocator = await this . documentRootLocatorFactory ( ) ;
2126 const labelId = await ( await this . host ( ) ) . getAttribute ( 'aria-labelledby' ) ;
2227 const hostId = await ( await this . host ( ) ) . getAttribute ( 'id' ) ;
Original file line number Diff line number Diff line change 77 */
88
99import { HarnessPredicate , parallel } from '@angular/cdk/testing' ;
10- import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control' ;
10+ import { MatFormFieldControlHarnessBase } from '@angular/material/form-field/testing/control' ;
1111import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1212import { InputHarnessFilters } from './input-harness-filters' ;
1313
1414/** Harness for interacting with a standard Material inputs in tests. */
15- export class MatInputHarness extends MatFormFieldControlHarness {
15+ export class MatInputHarness extends MatFormFieldControlHarnessBase {
1616 private readonly _documentRootLocator = this . documentRootLocatorFactory ( ) ;
1717
1818 // TODO: We do not want to handle `select` elements with `matNativeControl` because
@@ -99,11 +99,6 @@ export class MatInputHarness extends MatFormFieldControlHarness {
9999 return await ( await this . host ( ) ) . getProperty < string > ( 'id' ) ;
100100 }
101101
102- /** Gets the floating label text for the input, if it exists. */
103- async getLabel ( ) : Promise < string | null > {
104- return await this . _getFloatingLabelText ( ) ;
105- }
106-
107102 /**
108103 * Focuses the input and returns a promise that indicates when the
109104 * action is complete.
Original file line number Diff line number Diff line change 77 */
88
99import { HarnessPredicate , parallel } from '@angular/cdk/testing' ;
10- import { MatFormFieldControlHarness } from '../../form-field/testing/control' ;
10+ import { MatFormFieldControlHarnessBase } from '../../form-field/testing/control' ;
1111import { MatNativeOptionHarness } from './native-option-harness' ;
1212import {
1313 NativeOptionHarnessFilters ,
1414 NativeSelectHarnessFilters ,
1515} from './native-select-harness-filters' ;
1616
1717/** Harness for interacting with a native `select` in tests. */
18- export class MatNativeSelectHarness extends MatFormFieldControlHarness {
18+ export class MatNativeSelectHarness extends MatFormFieldControlHarnessBase {
1919 static hostSelector = 'select[matNativeControl]' ;
2020
2121 /**
@@ -61,11 +61,6 @@ export class MatNativeSelectHarness extends MatFormFieldControlHarness {
6161 return await ( await this . host ( ) ) . getProperty < string > ( 'id' ) ;
6262 }
6363
64- /** Gets the floating label text for the input, if it exists. */
65- async getLabel ( ) : Promise < string | null > {
66- return await this . _getFloatingLabelText ( ) ;
67- }
68-
6964 /** Focuses the select and returns a void promise that indicates when the action is complete. */
7065 async focus ( ) : Promise < void > {
7166 return ( await this . host ( ) ) . focus ( ) ;
Original file line number Diff line number Diff line change @@ -13,11 +13,11 @@ import {
1313 OptionHarnessFilters ,
1414 OptgroupHarnessFilters ,
1515} from '@angular/material/core/testing' ;
16- import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control' ;
16+ import { MatFormFieldControlHarnessBase } from '@angular/material/form-field/testing/control' ;
1717import { SelectHarnessFilters } from './select-harness-filters' ;
1818
1919/** Harness for interacting with a mat-select in tests. */
20- export class MatSelectHarness extends MatFormFieldControlHarness {
20+ export class MatSelectHarness extends MatFormFieldControlHarnessBase {
2121 static hostSelector = '.mat-mdc-select' ;
2222 private _prefix = 'mat-mdc' ;
2323 private _optionClass = MatOptionHarness ;
@@ -74,11 +74,6 @@ export class MatSelectHarness extends MatFormFieldControlHarness {
7474 return value . text ( ) ;
7575 }
7676
77- /** Gets the floating label text for the select, if it exists. */
78- async getLabel ( ) : Promise < string | null > {
79- return await this . _getFloatingLabelText ( ) ;
80- }
81-
8277 /** Focuses the select and returns a void promise that indicates when the action is complete. */
8378 async focus ( ) : Promise < void > {
8479 return ( await this . host ( ) ) . focus ( ) ;
You can’t perform that action at this time.
0 commit comments