Skip to content

Commit 3dc33f1

Browse files
mmalerbajelbourn
authored andcommitted
feat(button): move harness out of experimental (#17098)
1 parent dec116b commit 3dc33f1

File tree

14 files changed

+164
-66
lines changed

14 files changed

+164
-66
lines changed

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

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
44
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite")
66

77
ng_module(
88
name = "mdc-button",
99
srcs = glob(
1010
["**/*.ts"],
1111
exclude = [
1212
"**/*.spec.ts",
13-
"harness/**",
1413
],
1514
),
1615
assets = [
@@ -26,18 +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/coercion",
37-
"//src/cdk/testing",
38-
],
39-
)
40-
4128
sass_library(
4229
name = "mdc_button_scss_lib",
4330
srcs = glob(["**/_*.scss"]),
@@ -94,16 +81,17 @@ sass_binary(
9481

9582
ng_test_library(
9683
name = "button_tests_lib",
97-
srcs = [
98-
"harness/button-harness.spec.ts",
99-
],
84+
srcs = glob(
85+
["**/*.spec.ts"],
86+
exclude = [
87+
"**/*.e2e.spec.ts",
88+
],
89+
),
10090
deps = [
101-
":harness",
10291
":mdc-button",
10392
"//src/cdk/platform",
104-
"//src/cdk/testing",
105-
"//src/cdk/testing/testbed",
10693
"//src/material/button",
94+
"//src/material/core",
10795
"@npm//@angular/platform-browser",
10896
],
10997
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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-button/testing",
12+
deps = [
13+
"//src/cdk/coercion",
14+
"//src/cdk/testing",
15+
"//src/material/button/testing",
16+
],
17+
)
18+
19+
ng_test_library(
20+
name = "unit_tests_lib",
21+
srcs = glob(["**/*.spec.ts"]),
22+
deps = [
23+
":testing",
24+
"//src/material-experimental/mdc-button",
25+
"//src/material/button/testing:harness_tests_lib",
26+
],
27+
)
28+
29+
ng_web_test_suite(
30+
name = "unit_tests",
31+
static_files = ["@npm//:node_modules/@material/ripple/dist/mdc.ripple.js"],
32+
deps = [
33+
":unit_tests_lib",
34+
"//src/material-experimental:mdc_require_config.js",
35+
],
36+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {runHarnessTests} from '@angular/material/button/testing/shared.spec';
2+
import {MatButtonModule} from '../index';
3+
import {MatButtonHarness} from './button-harness';
4+
5+
describe('MDC-based MatButtonHarness', () => {
6+
runHarnessTests(MatButtonModule, MatButtonHarness);
7+
});

src/material-experimental/mdc-button/harness/mdc-button-harness.ts renamed to src/material-experimental/mdc-button/testing/button-harness.ts

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

99
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
1010
import {coerceBooleanProperty} from '@angular/cdk/coercion';
11-
import {ButtonHarnessFilters} from './button-harness-filters';
11+
import {ButtonHarnessFilters} from '@angular/material/button/testing/button-harness-filters';
1212

1313

1414
/**
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: 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 './button-harness';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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/button/testing",
12+
deps = [
13+
"//src/cdk/coercion",
14+
"//src/cdk/testing",
15+
],
16+
)
17+
18+
ng_test_library(
19+
name = "harness_tests_lib",
20+
srcs = ["shared.spec.ts"],
21+
deps = [
22+
":testing",
23+
"//src/cdk/platform",
24+
"//src/cdk/testing",
25+
"//src/cdk/testing/testbed",
26+
"//src/material/button",
27+
"@npm//@angular/forms",
28+
"@npm//@angular/platform-browser",
29+
],
30+
)
31+
32+
ng_test_library(
33+
name = "unit_tests_lib",
34+
srcs = glob(
35+
["**/*.spec.ts"],
36+
exclude = ["shared.spec.ts"],
37+
),
38+
deps = [
39+
":harness_tests_lib",
40+
":testing",
41+
"//src/material/button",
42+
],
43+
)
44+
45+
ng_web_test_suite(
46+
name = "unit_tests",
47+
deps = [":unit_tests_lib"],
48+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {MatButtonModule} from '@angular/material/button';
2+
import {runHarnessTests} from '@angular/material/button/testing/shared.spec';
3+
import {MatButtonHarness} from './button-harness';
4+
5+
describe('Non-MDC-based MatButtonHarness', () => {
6+
runHarnessTests(MatButtonModule, MatButtonHarness);
7+
});

src/material/button/testing/index.ts

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: 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 './button-harness';
10+
export * from './button-harness-filters';

src/material-experimental/mdc-button/harness/button-harness.spec.ts renamed to src/material/button/testing/shared.spec.ts

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,29 @@
1+
import {Platform, PlatformModule} from '@angular/cdk/platform';
12
import {HarnessLoader} from '@angular/cdk/testing';
23
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
3-
import {Platform, PlatformModule} from '@angular/cdk/platform';
44
import {Component} from '@angular/core';
55
import {ComponentFixture, inject, TestBed} from '@angular/core/testing';
66
import {MatButtonModule} from '@angular/material/button';
7-
import {MatButtonModule as MatMdcButtonModule} from '../index';
8-
import {MatButtonHarness} from './button-harness';
9-
import {MatButtonHarness as MatMdcButtonHarness} from './mdc-button-harness';
10-
11-
let fixture: ComponentFixture<ButtonHarnessTest>;
12-
let loader: HarnessLoader;
13-
let buttonHarness: typeof MatButtonHarness;
14-
let platform: Platform;
15-
16-
describe('MatButtonHarness', () => {
17-
describe('non-MDC-based', () => {
18-
beforeEach(async () => {
19-
await TestBed.configureTestingModule({
20-
imports: [MatButtonModule, PlatformModule],
21-
declarations: [ButtonHarnessTest],
22-
}).compileComponents();
23-
24-
fixture = TestBed.createComponent(ButtonHarnessTest);
25-
fixture.detectChanges();
26-
loader = TestbedHarnessEnvironment.loader(fixture);
27-
buttonHarness = MatButtonHarness;
28-
});
29-
30-
runTests();
31-
});
7+
import {MatButtonHarness} from '@angular/material/button/testing/button-harness';
328

33-
describe('MDC-based', () => {
34-
beforeEach(async () => {
35-
await TestBed.configureTestingModule({
36-
imports: [MatMdcButtonModule],
37-
declarations: [ButtonHarnessTest],
38-
}).compileComponents();
39-
40-
fixture = TestBed.createComponent(ButtonHarnessTest);
41-
fixture.detectChanges();
42-
loader = TestbedHarnessEnvironment.loader(fixture);
43-
// Public APIs are the same as MatButtonHarness, but cast is necessary because of different
44-
// private fields.
45-
buttonHarness = MatMdcButtonHarness as any;
46-
});
47-
48-
runTests();
9+
/** Shared tests to run on both the original and MDC-based buttons. */
10+
export function runHarnessTests(
11+
buttonModule: typeof MatButtonModule, buttonHarness: typeof MatButtonHarness) {
12+
let fixture: ComponentFixture<ButtonHarnessTest>;
13+
let loader: HarnessLoader;
14+
let platform: Platform;
15+
16+
beforeEach(async () => {
17+
await TestBed.configureTestingModule({
18+
imports: [buttonModule, PlatformModule],
19+
declarations: [ButtonHarnessTest],
20+
}).compileComponents();
21+
22+
fixture = TestBed.createComponent(ButtonHarnessTest);
23+
fixture.detectChanges();
24+
loader = TestbedHarnessEnvironment.loader(fixture);
4925
});
50-
});
5126

52-
/** Shared tests to run on both the original and MDC-based buttons. */
53-
function runTests() {
5427
beforeEach(inject([Platform], (p: Platform) => {
5528
platform = p;
5629
}));

test/karma-system-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ System.config({
101101
'@angular/material/badge': 'dist/packages/material/badge/index.js',
102102
'@angular/material/bottom-sheet': 'dist/packages/material/bottom-sheet/index.js',
103103
'@angular/material/button': 'dist/packages/material/button/index.js',
104+
'@angular/material/button/testing': 'dist/packages/material/button/testing/index.js',
105+
'@angular/material/button/testing/shared.spec': 'dist/packages/material/button/testing/shared.spec.js',
104106
'@angular/material/button-toggle': 'dist/packages/material/button-toggle/index.js',
105107
'@angular/material/card': 'dist/packages/material/card/index.js',
106108
'@angular/material/checkbox': 'dist/packages/material/checkbox/index.js',

0 commit comments

Comments
 (0)