Skip to content

Commit 09ded04

Browse files
mmalerbajelbourn
authored andcommitted
feat(checkbox): move checkbox harness out of experimental (#17067)
1 parent b454e38 commit 09ded04

File tree

14 files changed

+168
-53
lines changed

14 files changed

+168
-53
lines changed
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-checkbox/testing",
12+
deps = [
13+
"//src/cdk/coercion",
14+
"//src/cdk/testing",
15+
"//src/material/checkbox/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-checkbox",
25+
"//src/material/checkbox/testing:shared_unit_tests",
26+
],
27+
)
28+
29+
ng_web_test_suite(
30+
name = "unit_tests",
31+
static_files = [
32+
"@npm//:node_modules/@material/checkbox/dist/mdc.checkbox.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+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {MatCheckboxModule} from '../index';
2+
import {MatCheckboxHarness} from './checkbox-harness';
3+
import {runTests} from '@angular/material/checkbox/testing/shared.spec';
4+
5+
describe('MDC-based MatCheckboxHarness', () => {
6+
runTests(MatCheckboxModule, MatCheckboxHarness as any);
7+
});

src/material-experimental/mdc-checkbox/harness/mdc-checkbox-harness.ts renamed to src/material-experimental/mdc-checkbox/testing/checkbox-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 {CheckboxHarnessFilters} from './checkbox-harness-filters';
11+
import {CheckboxHarnessFilters} from '@angular/material/checkbox/testing';
1212

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

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

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

9-
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
109
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
1111
import {CheckboxHarnessFilters} from './checkbox-harness-filters';
1212

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

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

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,30 @@ import {Component} from '@angular/core';
44
import {ComponentFixture, TestBed} from '@angular/core/testing';
55
import {FormControl, ReactiveFormsModule} from '@angular/forms';
66
import {MatCheckboxModule} from '@angular/material/checkbox';
7-
import {MatCheckboxModule as MatMdcCheckboxModule} from '../index';
8-
import {MatCheckboxHarness} from './checkbox-harness';
9-
import {MatCheckboxHarness as MatMdcCheckboxHarness} from './mdc-checkbox-harness';
10-
11-
let fixture: ComponentFixture<CheckboxHarnessTest>;
12-
let loader: HarnessLoader;
13-
let checkboxHarness: typeof MatCheckboxHarness;
14-
15-
describe('MatCheckboxHarness', () => {
16-
describe('non-MDC-based', () => {
17-
beforeEach(async () => {
18-
await TestBed
19-
.configureTestingModule({
20-
imports: [MatCheckboxModule, ReactiveFormsModule],
21-
declarations: [CheckboxHarnessTest],
22-
})
23-
.compileComponents();
24-
25-
fixture = TestBed.createComponent(CheckboxHarnessTest);
26-
fixture.detectChanges();
27-
loader = TestbedHarnessEnvironment.loader(fixture);
28-
checkboxHarness = MatCheckboxHarness;
29-
});
30-
31-
runTests();
32-
});
33-
34-
describe('MDC-based', () => {
35-
beforeEach(async () => {
36-
await TestBed
37-
.configureTestingModule({
38-
imports: [MatMdcCheckboxModule, ReactiveFormsModule],
39-
declarations: [CheckboxHarnessTest],
40-
})
41-
.compileComponents();
42-
43-
fixture = TestBed.createComponent(CheckboxHarnessTest);
44-
fixture.detectChanges();
45-
loader = TestbedHarnessEnvironment.loader(fixture);
46-
// Public APIs are the same as MatCheckboxHarness, but cast is necessary because of different
47-
// private fields.
48-
checkboxHarness = MatMdcCheckboxHarness as any;
49-
});
50-
51-
runTests();
52-
});
53-
});
54-
55-
/** Shared tests to run on both the original and MDC-based checkboxes. */
56-
function runTests() {
7+
import {MatCheckboxHarness} from '@angular/material/checkbox/testing/checkbox-harness';
8+
9+
/**
10+
* Function that can be used to run the shared checkbox harness tests for either the non-MDC or
11+
* MDC based checkbox harness.
12+
*/
13+
export function runTests(
14+
checkboxModule: typeof MatCheckboxModule, checkboxHarness: typeof MatCheckboxHarness) {
15+
let fixture: ComponentFixture<CheckboxHarnessTest>;
16+
let loader: HarnessLoader;
17+
18+
beforeEach(async () => {
19+
await TestBed
20+
.configureTestingModule({
21+
imports: [checkboxModule, ReactiveFormsModule],
22+
declarations: [CheckboxHarnessTest],
23+
})
24+
.compileComponents();
25+
26+
fixture = TestBed.createComponent(CheckboxHarnessTest);
27+
fixture.detectChanges();
28+
loader = TestbedHarnessEnvironment.loader(fixture);
29+
});
30+
5731
it('should load all checkbox harnesses', async () => {
5832
const checkboxes = await loader.getAllHarnesses(checkboxHarness);
5933
expect(checkboxes.length).toBe(2);

src/material/tsconfig-tests.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"include": [
2929
"**/*.spec.ts",
30-
"index.ts"
30+
"./**/index.ts"
3131
],
3232
"exclude": [
3333
"**/schematics/**/*.ts",

test/karma-system-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ System.config({
102102
'@angular/material/button-toggle': 'dist/packages/material/button-toggle/index.js',
103103
'@angular/material/card': 'dist/packages/material/card/index.js',
104104
'@angular/material/checkbox': 'dist/packages/material/checkbox/index.js',
105+
'@angular/material/checkbox/testing': 'dist/packages/material/checkbox/testing/index.js',
106+
'@angular/material/checkbox/testing/shared.spec': 'dist/packages/material/checkbox/testing/shared.spec.js',
105107
'@angular/material/chips': 'dist/packages/material/chips/index.js',
106108
'@angular/material/core': 'dist/packages/material/core/index.js',
107109
'@angular/material/datepicker': 'dist/packages/material/datepicker/index.js',
@@ -138,6 +140,8 @@ System.config({
138140
'dist/packages/material-experimental/mdc-card/index.js',
139141
'@angular/material-experimental/mdc-checkbox':
140142
'dist/packages/material-experimental/mdc-checkbox/index.js',
143+
'@angular/material-experimental/mdc-checkbox/testing':
144+
'dist/packages/material-experimental/mdc-checkbox/testing/index.js',
141145
'@angular/material-experimental/mdc-chips':
142146
'dist/packages/material-experimental/mdc-chips/index.js',
143147
'@angular/material-experimental/mdc-helpers':

0 commit comments

Comments
 (0)