Skip to content

Commit 13e1fab

Browse files
committed
feat(select,input,form-field): move test harnesses out of experimental
Moves the test harnesses for the `select`, `input` and `form-field` packages out of `material-experimental`.
1 parent af6c13f commit 13e1fab

32 files changed

+175
-74
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@
8989

9090
# Material experimental package
9191
/src/material-experimental/* @jelbourn
92-
/src/material-experimental/input/** @devversion
93-
/src/material-experimental/form-field/** @devversion
9492
/src/material-experimental/mdc-autocomplete/** @crisbeto
9593
/src/material-experimental/mdc-button/** @andrewseguin
9694
/src/material-experimental/mdc-card/** @mmalerba
@@ -112,7 +110,6 @@
112110
/src/material-experimental/mdc-theming/** @mmalerba
113111
/src/material-experimental/mdc-typography/** @mmalerba
114112
/src/material-experimental/popover-edit/** @kseamon @andrewseguin
115-
/src/material-experimental/select/** @crisbeto
116113

117114
# CDK experimental package
118115
/src/cdk-experimental/* @jelbourn

src/material-experimental/config.bzl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
entryPoints = [
2-
"form-field/testing",
3-
"form-field/testing/control",
4-
"input/testing",
52
"mdc-autocomplete",
63
"mdc-button",
74
"mdc-button/testing",
@@ -22,14 +19,13 @@ entryPoints = [
2219
"mdc-slider",
2320
"mdc-tabs",
2421
"popover-edit",
25-
"select/testing",
2622
]
2723

2824
# List of all non-testing entry-points of the Angular material-experimental package.
2925
MATERIAL_EXPERIMENTAL_ENTRYPOINTS = [
3026
ep
3127
for ep in entryPoints
32-
if not ep.endswith("/testing")
28+
if not "/testing" in ep
3329
]
3430

3531
# List of all testing entry-points of the Angular material-experimental package.

src/material/config.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ entryPoints = [
5353
"toolbar",
5454
"tooltip",
5555
"tree",
56+
"form-field/testing",
57+
"form-field/testing/control",
58+
"input/testing",
59+
"select/testing",
5660
]
5761

5862
# List of all non-testing entry-points of the Angular Material package.
5963
MATERIAL_ENTRYPOINTS = [
6064
ep
6165
for ep in entryPoints
62-
if not ep.endswith("/testing")
66+
if not "/testing" in ep
6367
]
6468

6569
# List of all testing entry-points of the Angular Material package.

src/material-experimental/form-field/testing/BUILD.bazel renamed to src/material/form-field/testing/BUILD.bazel

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ ts_library(
88
["**/*.ts"],
99
exclude = ["**/*.spec.ts"],
1010
),
11-
module_name = "@angular/material-experimental/form-field/testing",
11+
module_name = "@angular/material/form-field/testing",
1212
deps = [
1313
"//src/cdk/testing",
14-
"//src/material-experimental/form-field/testing/control",
15-
"//src/material-experimental/input/testing",
16-
"//src/material-experimental/select/testing",
14+
"//src/material/form-field/testing/control",
15+
"//src/material/input/testing",
16+
"//src/material/select/testing",
1717
],
1818
)
1919

20+
filegroup(
21+
name = "source-files",
22+
srcs = glob(["**/*.ts"]),
23+
)
24+
2025
ng_test_library(
2126
name = "harness_tests_lib",
2227
srcs = ["shared.spec.ts"],
@@ -39,12 +44,12 @@ ng_test_library(
3944
deps = [
4045
":harness_tests_lib",
4146
":testing",
42-
"//src/material-experimental/input/testing",
43-
"//src/material-experimental/select/testing",
4447
"//src/material/autocomplete",
4548
"//src/material/form-field",
4649
"//src/material/input",
50+
"//src/material/input/testing",
4751
"//src/material/select",
52+
"//src/material/select/testing",
4853
],
4954
)
5055

src/material-experimental/form-field/testing/control/BUILD.bazel renamed to src/material/form-field/testing/control/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ load("//tools:defaults.bzl", "ts_library")
55
ts_library(
66
name = "control",
77
srcs = glob(["**/*.ts"]),
8-
module_name = "@angular/material-experimental/form-field/testing/control",
8+
module_name = "@angular/material/form-field/testing/control",
99
deps = ["//src/cdk/testing"],
1010
)
11+
12+
filegroup(
13+
name = "source-files",
14+
srcs = glob(["**/*.ts"]),
15+
)

src/material-experimental/form-field/testing/form-field-harness-filters.ts renamed to src/material/form-field/testing/form-field-harness-filters.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11-
export interface FormFieldHarnessFilters extends BaseHarnessFilters {}
11+
export interface FormFieldHarnessFilters extends BaseHarnessFilters {
12+
floatingLabelText?: string | RegExp;
13+
hasErrors?: boolean;
14+
}

src/material-experimental/form-field/testing/form-field-harness.spec.ts renamed to src/material/form-field/testing/form-field-harness.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {MatInputHarness} from '@angular/material-experimental/input/testing';
2-
import {MatSelectHarness} from '@angular/material-experimental/select/testing';
1+
import {MatInputHarness} from '@angular/material/input/testing';
2+
import {MatSelectHarness} from '@angular/material/select/testing';
33
import {MatAutocompleteModule} from '@angular/material/autocomplete';
44
import {MatFormFieldModule} from '@angular/material/form-field';
55
import {MatInputModule} from '@angular/material/input';

src/material-experimental/form-field/testing/form-field-harness.ts renamed to src/material/form-field/testing/form-field-harness.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import {
1313
HarnessQuery,
1414
TestElement
1515
} from '@angular/cdk/testing';
16-
import {
17-
MatFormFieldControlHarness
18-
} from '@angular/material-experimental/form-field/testing/control';
19-
import {MatInputHarness} from '@angular/material-experimental/input/testing';
20-
import {MatSelectHarness} from '@angular/material-experimental/select/testing';
16+
import {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';
17+
import {MatInputHarness} from '@angular/material/input/testing';
18+
import {MatSelectHarness} from '@angular/material/select/testing';
2119
import {FormFieldHarnessFilters} from './form-field-harness-filters';
2220

2321
// TODO(devversion): support datepicker harness once developed (COMP-203).
@@ -37,14 +35,18 @@ export class MatFormFieldHarness extends ComponentHarness {
3735
* @return a `HarnessPredicate` configured with the given options.
3836
*/
3937
static with(options: FormFieldHarnessFilters = {}): HarnessPredicate<MatFormFieldHarness> {
40-
return new HarnessPredicate(MatFormFieldHarness, options);
38+
return new HarnessPredicate(MatFormFieldHarness, options)
39+
.addOption('floatingLabelText', options.floatingLabelText, async (harness, text) =>
40+
HarnessPredicate.stringMatches(await harness.getLabel(), text))
41+
.addOption('hasErrors', options.hasErrors, async (harness, hasErrors) =>
42+
await harness.hasErrors() === hasErrors);
4143
}
4244

4345
private _prefixContainer = this.locatorForOptional('.mat-form-field-prefix');
4446
private _suffixContainer = this.locatorForOptional('.mat-form-field-suffix');
4547
private _label = this.locatorForOptional('.mat-form-field-label');
4648
private _errors = this.locatorForAll('.mat-error');
47-
private _hints = this.locatorForAll('mat-hint,.mat-hint');
49+
private _hints = this.locatorForAll('mat-hint, .mat-hint');
4850

4951
private _inputControl = this.locatorForOptional(MatInputHarness);
5052
private _selectControl = this.locatorForOptional(MatSelectHarness);
@@ -117,6 +119,11 @@ export class MatFormFieldHarness extends ComponentHarness {
117119
return (await this.host()).hasClass('mat-form-field-can-float');
118120
}
119121

122+
/** Whether the form-field has errors. */
123+
async hasErrors(): Promise<boolean> {
124+
return (await this.getErrorMessages()).length > 0;
125+
}
126+
120127
/** Whether the label is currently floating. */
121128
async isLabelFloating(): Promise<boolean> {
122129
return (await this.host()).hasClass('mat-form-field-should-float');

src/material-experimental/form-field/testing/public-api.ts renamed to src/material/form-field/testing/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Re-export everything from the "form-field/testing/control" entry-point. To avoid
1010
// circular dependencies, harnesses for default form-field controls (i.e. input, select)
1111
// need to import the base form-field control harness through a separate entry-point.
12-
export * from '@angular/material-experimental/form-field/testing/control';
12+
export * from '@angular/material/form-field/testing/control';
1313

1414
export * from './form-field-harness';
1515
export * from './form-field-harness-filters';

src/material-experimental/input/testing/BUILD.bazel renamed to src/material/input/testing/BUILD.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ ts_library(
88
["**/*.ts"],
99
exclude = ["**/*.spec.ts"],
1010
),
11-
module_name = "@angular/material-experimental/input/testing",
11+
module_name = "@angular/material/input/testing",
1212
deps = [
1313
"//src/cdk/coercion",
1414
"//src/cdk/testing",
15-
"//src/material-experimental/form-field/testing/control",
15+
"//src/material/form-field/testing/control",
1616
],
1717
)
1818

19+
filegroup(
20+
name = "source-files",
21+
srcs = glob(["**/*.ts"]),
22+
)
23+
1924
ng_test_library(
2025
name = "harness_tests_lib",
2126
srcs = ["shared.spec.ts"],

src/material-experimental/input/testing/input-harness-filters.ts renamed to src/material/input/testing/input-harness-filters.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

1111
export interface InputHarnessFilters extends BaseHarnessFilters {
12-
value?: string;
12+
value?: string | RegExp;
13+
placeholder?: string | RegExp;
1314
}

src/material-experimental/input/testing/input-harness.ts renamed to src/material/input/testing/input-harness.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
*/
88

99
import {HarnessPredicate} from '@angular/cdk/testing';
10-
import {
11-
MatFormFieldControlHarness
12-
} from '@angular/material-experimental/form-field/testing/control';
10+
import {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';
1311
import {InputHarnessFilters} from './input-harness-filters';
1412

1513
/** Harness for interacting with a standard Material inputs in tests. */
@@ -27,8 +25,12 @@ export class MatInputHarness extends MatFormFieldControlHarness {
2725
*/
2826
static with(options: InputHarnessFilters = {}): HarnessPredicate<MatInputHarness> {
2927
return new HarnessPredicate(MatInputHarness, options)
30-
.addOption(
31-
'value', options.value, async (harness, value) => (await harness.getValue()) === value);
28+
.addOption('value', options.value, async (harness, value) => {
29+
return (await harness.getValue()) === value;
30+
})
31+
.addOption('placeholder', options.placeholder, async (harness, placeholder) => {
32+
return (await harness.getPlaceholder()) === placeholder;
33+
});
3234
}
3335

3436
/** Whether the input is disabled. */
@@ -67,7 +69,7 @@ export class MatInputHarness extends MatFormFieldControlHarness {
6769
return (await (await this.host()).getProperty('type'))!;
6870
}
6971

70-
/** Gets the placeholder of the input. / */
72+
/** Gets the placeholder of the input. */
7173
async getPlaceholder(): Promise<string> {
7274
// The "placeholder" property of the native input is never undefined.
7375
return (await (await this.host()).getProperty('placeholder'))!;

src/material-experimental/select/testing/BUILD.bazel renamed to src/material/select/testing/BUILD.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ ts_library(
88
["**/*.ts"],
99
exclude = ["**/*.spec.ts"],
1010
),
11-
module_name = "@angular/material-experimental/select/testing",
11+
module_name = "@angular/material/select/testing",
1212
deps = [
1313
"//src/cdk/coercion",
1414
"//src/cdk/testing",
15-
"//src/material-experimental/form-field/testing/control",
15+
"//src/material/form-field/testing/control",
1616
],
1717
)
1818

19+
filegroup(
20+
name = "source-files",
21+
srcs = glob(["**/*.ts"]),
22+
)
23+
1924
ng_test_library(
2025
name = "harness_tests_lib",
2126
srcs = ["shared.spec.ts"],

src/material-experimental/select/testing/select-harness.ts renamed to src/material/select/testing/select-harness.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {HarnessPredicate, TestElement} from '@angular/cdk/testing';
10-
import {
11-
MatFormFieldControlHarness
12-
} from '@angular/material-experimental/form-field/testing/control';
9+
import {HarnessPredicate} from '@angular/cdk/testing';
10+
import {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';
1311
import {SelectHarnessFilters} from './select-harness-filters';
14-
import {MatSelectOptionHarness, MatSelectOptionGroupHarness} from './option-harness';
15-
16-
/** Selector for the select panel. */
17-
const PANEL_SELECTOR = '.mat-select-panel';
12+
import {
13+
MatSelectOptionHarness,
14+
MatSelectOptionGroupHarness,
15+
OptionHarnessFilters,
16+
} from './option-harness';
1817

1918
/** Harness for interacting with a standard mat-select in tests. */
2019
export class MatSelectHarness extends MatFormFieldControlHarness {
2120
private _documentRootLocator = this.documentRootLocatorFactory();
22-
private _panel = this._documentRootLocator.locatorFor(PANEL_SELECTOR);
2321
private _backdrop = this._documentRootLocator.locatorFor('.cdk-overlay-backdrop');
24-
private _optionalPanel = this._documentRootLocator.locatorForOptional(PANEL_SELECTOR);
25-
private _options = this._documentRootLocator.locatorForAll(MatSelectOptionHarness);
22+
private _optionalPanel = this._documentRootLocator.locatorForOptional('.mat-select-panel');
2623
private _groups = this._documentRootLocator.locatorForAll(MatSelectOptionGroupHarness);
2724
private _trigger = this.locatorFor('.mat-select-trigger');
2825
private _value = this.locatorFor('.mat-select-value');
@@ -80,14 +77,9 @@ export class MatSelectHarness extends MatFormFieldControlHarness {
8077
return (await this.host()).blur();
8178
}
8279

83-
/** Gets the select panel. */
84-
async getPanel(): Promise<TestElement> {
85-
return this._panel();
86-
}
87-
8880
/** Gets the options inside the select panel. */
89-
async getOptions(): Promise<MatSelectOptionHarness[]> {
90-
return this._options();
81+
async getOptions(filter: OptionHarnessFilters = {}): Promise<MatSelectOptionHarness[]> {
82+
return this._documentRootLocator.locatorForAll(MatSelectOptionHarness.with(filter))();
9183
}
9284

9385
/** Gets the groups of options inside the panel. */
@@ -107,6 +99,19 @@ export class MatSelectHarness extends MatFormFieldControlHarness {
10799
}
108100
}
109101

102+
/** Selects the options that match the passed-in filter. */
103+
async select(filter: OptionHarnessFilters = {}): Promise<void> {
104+
await this.open();
105+
106+
const [isMultiple, options] = await Promise.all([this.isMultiple(), this.getOptions(filter)]);
107+
108+
if (isMultiple) {
109+
await Promise.all(options.map(option => option.click()));
110+
} else if (options.length) {
111+
await options[0].click();
112+
}
113+
}
114+
110115
/** Closes the select's panel. */
111116
async close(): Promise<void> {
112117
if (await this.isOpen()) {

src/material-experimental/select/testing/shared.spec.ts renamed to src/material/select/testing/shared.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ export function runHarnessTests(
136136
expect(await select.isOpen()).toBe(false);
137137
});
138138

139-
it('should be able to get the select panel', async () => {
140-
const select = await loader.getHarness(selectHarness.with({selector: '#single-selection'}));
141-
await select.open();
142-
expect(await select.getPanel()).toBeTruthy();
143-
});
144-
145139
it('should be able to get the select options', async () => {
146140
const select = await loader.getHarness(selectHarness.with({selector: '#single-selection'}));
147141
await select.open();

test/karma-system-config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ System.config({
168168
'@angular/material/tooltip': 'dist/packages/material/tooltip/index.js',
169169
'@angular/material/tree': 'dist/packages/material/tree/index.js',
170170

171-
'@angular/material-experimental/form-field/testing':
172-
'dist/packages/material-experimental/form-field/testing/index.js',
173-
'@angular/material-experimental/form-field/testing/control':
174-
'dist/packages/material-experimental/form-field/testing/control/index.js',
175-
'@angular/material-experimental/form-field/testing/shared.spec':
176-
'dist/packages/material-experimental/form-field/testing/shared.spec.js',
177-
'@angular/material-experimental/input/testing':
178-
'dist/packages/material-experimental/input/testing/index.js',
171+
'@angular/material/form-field/testing':
172+
'dist/packages/material/form-field/testing/index.js',
173+
'@angular/material/form-field/testing/control':
174+
'dist/packages/material/form-field/testing/control/index.js',
175+
'@angular/material/form-field/testing/shared.spec':
176+
'dist/packages/material/form-field/testing/shared.spec.js',
177+
'@angular/material/input/testing':
178+
'dist/packages/material/input/testing/index.js',
179179
'@angular/material-experimental/mdc-autocomplete':
180180
'dist/packages/material-experimental/mdc-autocomplete/index.js',
181181
'@angular/material-experimental/mdc-button':
@@ -204,10 +204,10 @@ System.config({
204204
'dist/packages/material-experimental/mdc-progress-bar/index.js',
205205
'@angular/material-experimental/popover-edit':
206206
'dist/packages/material-experimental/popover-edit/index.js',
207-
'@angular/material-experimental/select/testing':
208-
'dist/packages/material-experimental/select/testing/index.js',
209-
'@angular/material-experimental/select/testing/shared.spec':
210-
'dist/packages/material-experimental/select/testing/shared.spec.js',
207+
'@angular/material/select/testing':
208+
'dist/packages/material/select/testing/index.js',
209+
'@angular/material/select/testing/shared.spec':
210+
'dist/packages/material/select/testing/shared.spec.js',
211211
},
212212
packages: {
213213
// Thirdparty barrels.

0 commit comments

Comments
 (0)