Skip to content

Commit 92f912c

Browse files
committed
cleanup: restructure mdc-chips harness to follow the file structure used
by other harnesses, and add missing filter options
1 parent dec116b commit 92f912c

21 files changed

+206
-59
lines changed

src/material-experimental/mdc-chips/BUILD.bazel

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ ng_module(
99
["**/*.ts"],
1010
exclude = [
1111
"**/*.spec.ts",
12-
"harness/**",
1312
],
1413
),
1514
assets = [":chips_scss"] + glob(["**/*.html"]),
@@ -26,17 +25,6 @@ ng_module(
2625
],
2726
)
2827

29-
ts_library(
30-
name = "harness",
31-
srcs = glob(
32-
["harness/**/*.ts"],
33-
exclude = ["**/*.spec.ts"],
34-
),
35-
deps = [
36-
"//src/cdk/testing",
37-
],
38-
)
39-
4028
sass_library(
4129
name = "mdc_chips_scss_lib",
4230
srcs = glob(["**/_*.scss"]),
@@ -66,15 +54,13 @@ ng_test_library(
6654
exclude = ["**/*.e2e.spec.ts"],
6755
),
6856
deps = [
69-
":harness",
7057
":mdc-chips",
7158
"//src/cdk/a11y",
7259
"//src/cdk/bidi",
7360
"//src/cdk/keycodes",
7461
"//src/cdk/platform",
7562
"//src/cdk/private/testing",
7663
"//src/cdk/testing",
77-
"//src/cdk/testing/testbed",
7864
"//src/material/core",
7965
"//src/material/form-field",
8066
"//src/material/input",

src/material-experimental/mdc-chips/harness/chip-harness.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/material-experimental/mdc-chips/harness/chip-row-harness.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
4+
5+
ng_module(
6+
name = "testing",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/material-experimental/mdc-chips/testing",
12+
deps = [
13+
"//src/cdk/coercion",
14+
"//src/cdk/testing",
15+
],
16+
)
17+
18+
ng_test_library(
19+
name = "unit_tests_lib",
20+
srcs = glob(["**/*.spec.ts"]),
21+
deps = [
22+
":testing",
23+
"//src/cdk/testing",
24+
"//src/cdk/testing/testbed",
25+
"//src/material-experimental/mdc-chips",
26+
],
27+
)
28+
29+
ng_web_test_suite(
30+
name = "unit_tests",
31+
static_files = [
32+
"@npm//:node_modules/@material/chips/dist/mdc.chips.js",
33+
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
34+
],
35+
deps = [
36+
":unit_tests_lib",
37+
"//src/material-experimental:mdc_require_config.js",
38+
],
39+
)

src/material-experimental/mdc-chips/harness/chip-grid-harness.ts renamed to src/material-experimental/mdc-chips/testing/chip-grid-harness.ts

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

9-
import {ComponentHarness} from '@angular/cdk/testing';
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
10+
import {ChipGridHarnessFilters} from './chip-harness-filters';
11+
import {MatChipInputHarness} from './chip-input-harness';
1012
import {MatChipRowHarness} from './chip-row-harness';
11-
import {MatChipInputHarness} from './chip-input';
1213

1314
/**
1415
* Harness for interacting with a mat-chip-grid in tests.
@@ -17,6 +18,13 @@ import {MatChipInputHarness} from './chip-input';
1718
export class MatChipGridHarness extends ComponentHarness {
1819
static hostSelector = 'mat-chip-grid';
1920

21+
/**
22+
* Gets a `HarnessPredicate` that can be used to search for a chip grid with specific attributes.
23+
*/
24+
static with(options: ChipGridHarnessFilters = {}): HarnessPredicate<MatChipGridHarness> {
25+
return new HarnessPredicate(MatChipGridHarness, options);
26+
}
27+
2028
private _rows = this.locatorForAll(MatChipRowHarness);
2129
private _input = this.locatorFor(MatChipInputHarness);
2230

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {BaseHarnessFilters} from '@angular/cdk/testing';
10+
11+
// TODO(mmalerba): Add additional options that make sense for each harness type.
12+
13+
export interface ChipGridHarnessFilters extends BaseHarnessFilters {}
14+
15+
export interface ChipHarnessFilters extends BaseHarnessFilters {}
16+
17+
export interface ChipInputHarnessFilters extends BaseHarnessFilters {}
18+
19+
export interface ChipListboxHarnessFilters extends BaseHarnessFilters {}
20+
21+
export interface ChipOptionHarnessFilters extends ChipHarnessFilters {}
22+
23+
export interface ChipRowHarnessFilters extends ChipHarnessFilters {}
24+
25+
export interface ChipSetHarnessFilters extends BaseHarnessFilters {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
10+
import {ChipHarnessFilters} from './chip-harness-filters';
11+
12+
/**
13+
* Harness for interacting with a mat-chip in tests.
14+
* @dynamic
15+
*/
16+
export class MatChipHarness extends ComponentHarness {
17+
static hostSelector = 'mat-basic-chip, mat-chip';
18+
19+
/**
20+
* Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes.
21+
*/
22+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
23+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
24+
static with<T extends typeof MatChipHarness>(this: T, options: ChipHarnessFilters = {}):
25+
HarnessPredicate<InstanceType<T>> {
26+
return new HarnessPredicate(MatChipHarness, options) as
27+
unknown as HarnessPredicate<InstanceType<T>>;
28+
}
29+
30+
/** Gets a promise for the text content the option. */
31+
async getText(): Promise<string> {
32+
return (await this.host()).text();
33+
}
34+
}

src/material-experimental/mdc-chips/harness/chip-input.spec.ts renamed to src/material-experimental/mdc-chips/testing/chip-input-harness.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
33
import {Component} from '@angular/core';
44
import {ComponentFixture, TestBed} from '@angular/core/testing';
55
import {MatChipsModule} from '../index';
6-
import {MatChipInputHarness} from './chip-input';
6+
import {MatChipInputHarness} from './chip-input-harness';
77

88
let fixture: ComponentFixture<ChipInputHarnessTest>;
99
let loader: HarnessLoader;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentHarness} from '@angular/cdk/testing';
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
10+
import {ChipInputHarnessFilters} from './chip-harness-filters';
1011

1112
/**
1213
* Harness for interacting with a grid's chip input in tests.
@@ -15,6 +16,13 @@ import {ComponentHarness} from '@angular/cdk/testing';
1516
export class MatChipInputHarness extends ComponentHarness {
1617
static hostSelector = '.mat-mdc-chip-input';
1718

19+
/**
20+
* Gets a `HarnessPredicate` that can be used to search for a chip input with specific attributes.
21+
*/
22+
static with(options: ChipInputHarnessFilters = {}): HarnessPredicate<MatChipInputHarness> {
23+
return new HarnessPredicate(MatChipInputHarness, options);
24+
}
25+
1826
/** Gets a promise for the disabled state. */
1927
async isDisabled(): Promise<boolean> {
2028
return await ((await this.host()).getAttribute('disabled')) === 'true';

src/material-experimental/mdc-chips/harness/chip-listbox-harness.ts renamed to src/material-experimental/mdc-chips/testing/chip-listbox-harness.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentHarness} from '@angular/cdk/testing';
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
10+
import {ChipListboxHarnessFilters} from './chip-harness-filters';
1011
import {MatChipOptionHarness} from './chip-option-harness';
1112

1213
/**
@@ -16,6 +17,14 @@ import {MatChipOptionHarness} from './chip-option-harness';
1617
export class MatChipListboxHarness extends ComponentHarness {
1718
static hostSelector = 'mat-chip-listbox';
1819

20+
/**
21+
* Gets a `HarnessPredicate` that can be used to search for a chip listbox with specific
22+
* attributes.
23+
*/
24+
static with(options: ChipListboxHarnessFilters = {}): HarnessPredicate<MatChipListboxHarness> {
25+
return new HarnessPredicate(MatChipListboxHarness, options);
26+
}
27+
1928
private _options = this.locatorForAll(MatChipOptionHarness);
2029

2130
/** Gets promise of the harnesses for the chip options in the listbox. */

src/material-experimental/mdc-chips/harness/chip-option-harness.ts renamed to src/material-experimental/mdc-chips/testing/chip-option-harness.ts

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

9+
import {HarnessPredicate} from '@angular/cdk/testing';
910
import {MatChipHarness} from './chip-harness';
11+
import {ChipOptionHarnessFilters} from './chip-harness-filters';
1012

1113
/**
1214
* Harness for interacting with a mat-chip-option in tests.
@@ -15,6 +17,18 @@ import {MatChipHarness} from './chip-harness';
1517
export class MatChipOptionHarness extends MatChipHarness {
1618
static hostSelector = 'mat-basic-chip-option, mat-chip-option';
1719

20+
/**
21+
* Gets a `HarnessPredicate` that can be used to search for a chip option with specific
22+
* attributes.
23+
*/
24+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
25+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
26+
static with<T extends typeof MatChipHarness>(
27+
this: T, options: ChipOptionHarnessFilters = {}): HarnessPredicate<InstanceType<T>> {
28+
return new HarnessPredicate(MatChipOptionHarness, options) as
29+
unknown as HarnessPredicate<InstanceType<T>>;
30+
}
31+
1832
/** Gets a promise for the selected state. */
1933
async isSelected(): Promise<boolean> {
2034
return await ((await this.host()).getAttribute('aria-selected')) === 'true';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {HarnessPredicate} from '@angular/cdk/testing';
10+
import {ChipRowHarnessFilters} from './chip-harness-filters';
11+
import {MatChipHarness} from './chip-harness';
12+
13+
/**
14+
* Harness for interacting with a mat-chip-row in tests.
15+
* @dynamic
16+
*/
17+
export class MatChipRowHarness extends MatChipHarness {
18+
static hostSelector = 'mat-chip-row, mat-basic-chip-row';
19+
20+
/**
21+
* Gets a `HarnessPredicate` that can be used to search for a chip row with specific attributes.
22+
*/
23+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
24+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
25+
static with<T extends typeof MatChipHarness>(
26+
this: T, options: ChipRowHarnessFilters = {}): HarnessPredicate<InstanceType<T>> {
27+
return new HarnessPredicate(MatChipRowHarness, options) as
28+
unknown as HarnessPredicate<InstanceType<T>>;
29+
}
30+
}

src/material-experimental/mdc-chips/harness/chip-set-harness.ts renamed to src/material-experimental/mdc-chips/testing/chip-set-harness.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentHarness} from '@angular/cdk/testing';
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
1010
import {MatChipHarness} from './chip-harness';
11+
import {ChipSetHarnessFilters} from './chip-harness-filters';
1112

1213
/**
1314
* Harness for interacting with a mat-chip-set in tests.
@@ -16,6 +17,13 @@ import {MatChipHarness} from './chip-harness';
1617
export class MatChipSetHarness extends ComponentHarness {
1718
static hostSelector = 'mat-chip-set';
1819

20+
/**
21+
* Gets a `HarnessPredicate` that can be used to search for a chip set with specific attributes.
22+
*/
23+
static with(options: ChipSetHarnessFilters = {}): HarnessPredicate<MatChipSetHarness> {
24+
return new HarnessPredicate(MatChipSetHarness, options);
25+
}
26+
1927
private _chips = this.locatorForAll(MatChipHarness);
2028

2129
/** Gets promise of the harnesses for the chips. */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './public-api';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './chip-grid-harness';
10+
export * from './chip-harness';
11+
export * from './chip-harness-filters';
12+
export * from './chip-input-harness';
13+
export * from './chip-listbox-harness';
14+
export * from './chip-option-harness';
15+
export * from './chip-row-harness';
16+
export * from './chip-set-harness';

0 commit comments

Comments
 (0)