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
542
542
return ( await this . getRootHarnessLoader ( ) ) . getAllHarnesses ( query ) ;
543
543
}
544
544
545
- /**
545
+ /**
546
546
* Returns the number of matching harnesses for the given query within the current harness's
547
547
* content.
548
548
*
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ export class MatDateRangeInputHarness extends DatepickerTriggerHarnessBase {
93
93
94
94
/** Gets the floating label text for the range input, if it exists. */
95
95
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
97
97
const documentRootLocator = await this . documentRootLocatorFactory ( ) ;
98
98
const labelId = await ( await this . host ( ) ) . getAttribute ( 'aria-labelledby' ) ;
99
99
const hostId = await ( await this . host ( ) ) . getAttribute ( 'id' ) ;
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { 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' ;
11
11
import { DatepickerInputHarnessFilters } from './datepicker-harness-filters' ;
12
12
13
13
/** Sets up the filter predicates for a datepicker input harness. */
@@ -28,7 +28,7 @@ export function getInputPredicate<T extends MatDatepickerInputHarnessBase>(
28
28
}
29
29
30
30
/** Base class for datepicker input harnesses. */
31
- export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarness {
31
+ export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarnessBase {
32
32
/** Whether the input is disabled. */
33
33
async isDisabled ( ) : Promise < boolean > {
34
34
return ( await this . host ( ) ) . getProperty < boolean > ( 'disabled' ) ;
@@ -39,11 +39,6 @@ export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlH
39
39
return ( await this . host ( ) ) . getProperty < boolean > ( 'required' ) ;
40
40
}
41
41
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
-
47
42
/** Gets the value of the input. */
48
43
async getValue ( ) : Promise < string > {
49
44
// 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';
12
12
* Base class for custom form-field control harnesses. Harnesses for
13
13
* custom controls with form-fields need to implement this interface.
14
14
*/
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 {
16
21
private readonly floatingLabelSelector = '.mdc-floating-label' ;
17
22
18
23
/** 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 > {
20
25
const documentRootLocator = await this . documentRootLocatorFactory ( ) ;
21
26
const labelId = await ( await this . host ( ) ) . getAttribute ( 'aria-labelledby' ) ;
22
27
const hostId = await ( await this . host ( ) ) . getAttribute ( 'id' ) ;
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { 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' ;
11
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12
12
import { InputHarnessFilters } from './input-harness-filters' ;
13
13
14
14
/** Harness for interacting with a standard Material inputs in tests. */
15
- export class MatInputHarness extends MatFormFieldControlHarness {
15
+ export class MatInputHarness extends MatFormFieldControlHarnessBase {
16
16
private readonly _documentRootLocator = this . documentRootLocatorFactory ( ) ;
17
17
18
18
// TODO: We do not want to handle `select` elements with `matNativeControl` because
@@ -99,11 +99,6 @@ export class MatInputHarness extends MatFormFieldControlHarness {
99
99
return await ( await this . host ( ) ) . getProperty < string > ( 'id' ) ;
100
100
}
101
101
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
-
107
102
/**
108
103
* Focuses the input and returns a promise that indicates when the
109
104
* action is complete.
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { HarnessPredicate , parallel } from '@angular/cdk/testing' ;
10
- import { MatFormFieldControlHarness } from '../../form-field/testing/control' ;
10
+ import { MatFormFieldControlHarnessBase } from '../../form-field/testing/control' ;
11
11
import { MatNativeOptionHarness } from './native-option-harness' ;
12
12
import {
13
13
NativeOptionHarnessFilters ,
14
14
NativeSelectHarnessFilters ,
15
15
} from './native-select-harness-filters' ;
16
16
17
17
/** Harness for interacting with a native `select` in tests. */
18
- export class MatNativeSelectHarness extends MatFormFieldControlHarness {
18
+ export class MatNativeSelectHarness extends MatFormFieldControlHarnessBase {
19
19
static hostSelector = 'select[matNativeControl]' ;
20
20
21
21
/**
@@ -61,11 +61,6 @@ export class MatNativeSelectHarness extends MatFormFieldControlHarness {
61
61
return await ( await this . host ( ) ) . getProperty < string > ( 'id' ) ;
62
62
}
63
63
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
-
69
64
/** Focuses the select and returns a void promise that indicates when the action is complete. */
70
65
async focus ( ) : Promise < void > {
71
66
return ( await this . host ( ) ) . focus ( ) ;
Original file line number Diff line number Diff line change @@ -13,11 +13,11 @@ import {
13
13
OptionHarnessFilters ,
14
14
OptgroupHarnessFilters ,
15
15
} 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' ;
17
17
import { SelectHarnessFilters } from './select-harness-filters' ;
18
18
19
19
/** Harness for interacting with a mat-select in tests. */
20
- export class MatSelectHarness extends MatFormFieldControlHarness {
20
+ export class MatSelectHarness extends MatFormFieldControlHarnessBase {
21
21
static hostSelector = '.mat-mdc-select' ;
22
22
private _prefix = 'mat-mdc' ;
23
23
private _optionClass = MatOptionHarness ;
@@ -74,11 +74,6 @@ export class MatSelectHarness extends MatFormFieldControlHarness {
74
74
return value . text ( ) ;
75
75
}
76
76
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
-
82
77
/** Focuses the select and returns a void promise that indicates when the action is complete. */
83
78
async focus ( ) : Promise < void > {
84
79
return ( await this . host ( ) ) . focus ( ) ;
You can’t perform that action at this time.
0 commit comments