Skip to content

Commit 7398c9a

Browse files
mmalerbajelbourn
authored andcommitted
feat(material-experimental/checkbox): Add test harnesses for both versions of mat-checkbox (#16334)
1 parent 6ee271f commit 7398c9a

27 files changed

+708
-20
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
/src/material-experimental/mdc-radio/** @mmalerba
9595
/src/material-experimental/mdc-slide-toggle/** @crisbeto
9696
/src/material-experimental/mdc-tabs/** @crisbeto
97+
/src/material-experimental/mdc-theming/** @mmalerba
98+
/src/material-experimental/mdc-typography/** @mmalerba
9799
/src/material-experimental/popover-edit/** @kseamon @andrewseguin
98100

99101
# CDK experimental package

src/cdk-experimental/testing/BUILD.bazel

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ ng_module(
99
["**/*.ts"],
1010
exclude = [
1111
"**/*.spec.ts",
12-
"tests/**",
1312
],
1413
),
1514
module_name = "@angular/cdk-experimental/testing",
16-
deps = [
17-
"//src/cdk/testing",
18-
"@npm//@angular/core",
19-
"@npm//protractor",
20-
],
2115
)
2216

2317
ng_web_test_suite(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "protractor",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/cdk-experimental/testing/protractor",
12+
deps = [
13+
"//src/cdk-experimental/testing",
14+
"@npm//protractor",
15+
],
16+
)

src/cdk-experimental/testing/protractor/index.ts

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

9-
export * from './protractor-element';
10-
export * from './protractor-harness-environment';
9+
export * from './public-api';

src/cdk-experimental/testing/protractor/protractor-element.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ export class ProtractorElement implements TestElement {
5050
async getAttribute(name: string): Promise<string|null> {
5151
return this.element.getAttribute(name);
5252
}
53+
54+
async hasClass(name: string): Promise<boolean> {
55+
const classes = (await this.getAttribute('class')) || '';
56+
return new Set(classes.split(/\s+/).filter(c => c)).has(name);
57+
}
5358
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 './protractor-element';
10+
export * from './protractor-harness-environment';

src/cdk-experimental/testing/public-api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88

99
export * from './component-harness';
1010
export * from './harness-environment';
11-
export * from './protractor';
1211
export * from './test-element';
13-
export * from './testbed';

src/cdk-experimental/testing/test-element.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ export interface TestElement {
4343
* falls back to reading the property.
4444
*/
4545
getAttribute(name: string): Promise<string | null>;
46+
47+
/** Checks whether the element has the given class. */
48+
hasClass(name: string): Promise<boolean>;
4649
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "testbed",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/cdk-experimental/testing/testbed",
12+
deps = [
13+
"//src/cdk-experimental/testing",
14+
"//src/cdk/testing",
15+
"@npm//@angular/core",
16+
],
17+
)

src/cdk-experimental/testing/testbed/index.ts

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

9-
export * from './testbed-harness-environment';
10-
export * from './unit-test-element';
9+
export * from './public-api';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 './testbed-harness-environment';
10+
export * from './unit-test-element';

src/cdk-experimental/testing/testbed/unit-test-element.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class UnitTestElement implements TestElement {
8686

8787
async text(): Promise<string> {
8888
await this._stabilize();
89-
return this.element.textContent || '';
89+
return (this.element.textContent || '').trim();
9090
}
9191

9292
async getAttribute(name: string): Promise<string|null> {
@@ -100,4 +100,9 @@ export class UnitTestElement implements TestElement {
100100
}
101101
return value;
102102
}
103+
104+
async hasClass(name: string): Promise<boolean> {
105+
await this._stabilize();
106+
return this.element.classList.contains(name);
107+
}
103108
}

src/cdk-experimental/testing/tests/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ng_test_library(
3636
":test_components",
3737
":test_harnesses",
3838
"//src/cdk-experimental/testing",
39+
"//src/cdk-experimental/testing/testbed",
3940
],
4041
)
4142

@@ -45,5 +46,6 @@ ng_e2e_test_library(
4546
deps = [
4647
":test_harnesses",
4748
"//src/cdk-experimental/testing",
49+
"//src/cdk-experimental/testing/protractor",
4850
],
4951
)

src/cdk-experimental/testing/tests/protractor.e2e.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import {HarnessLoader} from '@angular/cdk-experimental/testing';
2+
import {ProtractorHarnessEnvironment} from '@angular/cdk-experimental/testing/protractor';
13
import {browser} from 'protractor';
2-
import {HarnessLoader} from '../component-harness';
3-
import {ProtractorHarnessEnvironment} from '../protractor';
44
import {MainComponentHarness} from './harnesses/main-component-harness';
55
import {SubComponentHarness} from './harnesses/sub-component-harness';
66

src/cdk-experimental/testing/tests/testbed.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import {HarnessLoader} from '@angular/cdk-experimental/testing';
2+
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
13
import {ComponentFixture, TestBed} from '@angular/core/testing';
2-
import {HarnessLoader} from '../component-harness';
3-
import {TestbedHarnessEnvironment} from '../testbed/index';
44
import {MainComponentHarness} from './harnesses/main-component-harness';
55
import {SubComponentHarness} from './harnesses/sub-component-harness';
66
import {TestComponentsModule} from './test-components-module';

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package(default_visibility = ["//visibility:public"])
22

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
44
load("@npm_angular_bazel//:index.bzl", "protractor_web_test_suite")
5-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-checkbox",
99
srcs = glob(
1010
["**/*.ts"],
11-
exclude = ["**/*.spec.ts"],
11+
exclude = [
12+
"**/*.spec.ts",
13+
"harness/**",
14+
],
1215
),
1316
assets = [":checkbox_scss"] + glob(["**/*.html"]),
1417
module_name = "@angular/material-experimental/mdc-checkbox",
@@ -25,6 +28,18 @@ ng_module(
2528
],
2629
)
2730

31+
ts_library(
32+
name = "harness",
33+
srcs = glob(
34+
["harness/**/*.ts"],
35+
exclude = ["**/*.spec.ts"],
36+
),
37+
deps = [
38+
"//src/cdk-experimental/testing",
39+
"//src/cdk/coercion",
40+
],
41+
)
42+
2843
sass_library(
2944
name = "mdc_checkbox_scss_lib",
3045
srcs = glob(["**/_*.scss"]),
@@ -55,8 +70,12 @@ ng_test_library(
5570
exclude = ["**/*.e2e.spec.ts"],
5671
),
5772
deps = [
73+
":harness",
5874
":mdc-checkbox",
75+
"//src/cdk-experimental/testing",
76+
"//src/cdk-experimental/testing/testbed",
5977
"//src/cdk/testing",
78+
"//src/material/checkbox",
6079
"@npm//@angular/forms",
6180
"@npm//@angular/platform-browser",
6281
],
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 type CheckboxHarnessFilters = {
10+
label?: string | RegExp
11+
};

0 commit comments

Comments
 (0)