diff --git a/src/material-experimental/mdc-checkbox/testing/BUILD.bazel b/src/material-experimental/mdc-checkbox/testing/BUILD.bazel new file mode 100644 index 000000000000..2f29d10d8862 --- /dev/null +++ b/src/material-experimental/mdc-checkbox/testing/BUILD.bazel @@ -0,0 +1,39 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite") + +ng_module( + name = "testing", + srcs = glob( + ["**/*.ts"], + exclude = ["**/*.spec.ts"], + ), + module_name = "@angular/material-experimental/mdc-checkbox/testing", + deps = [ + "//src/cdk/coercion", + "//src/cdk/testing", + "//src/material/checkbox/testing", + ], +) + +ng_test_library( + name = "unit_tests_lib", + srcs = glob(["**/*.spec.ts"]), + deps = [ + ":testing", + "//src/material-experimental/mdc-checkbox", + "//src/material/checkbox/testing:shared_unit_tests", + ], +) + +ng_web_test_suite( + name = "unit_tests", + static_files = [ + "@npm//:node_modules/@material/checkbox/dist/mdc.checkbox.js", + "@npm//:node_modules/@material/ripple/dist/mdc.ripple.js", + ], + deps = [ + ":unit_tests_lib", + "//src/material-experimental:mdc_require_config.js", + ], +) diff --git a/src/material-experimental/mdc-checkbox/testing/checkbox-harness.spec.ts b/src/material-experimental/mdc-checkbox/testing/checkbox-harness.spec.ts new file mode 100644 index 000000000000..5810986efca2 --- /dev/null +++ b/src/material-experimental/mdc-checkbox/testing/checkbox-harness.spec.ts @@ -0,0 +1,7 @@ +import {MatCheckboxModule} from '../index'; +import {MatCheckboxHarness} from './checkbox-harness'; +import {runTests} from '@angular/material/checkbox/testing/shared.spec'; + +describe('MDC-based MatCheckboxHarness', () => { + runTests(MatCheckboxModule, MatCheckboxHarness as any); +}); diff --git a/src/material-experimental/mdc-checkbox/harness/mdc-checkbox-harness.ts b/src/material-experimental/mdc-checkbox/testing/checkbox-harness.ts similarity index 98% rename from src/material-experimental/mdc-checkbox/harness/mdc-checkbox-harness.ts rename to src/material-experimental/mdc-checkbox/testing/checkbox-harness.ts index 8bba9f1aa21d..3e8772732fbe 100644 --- a/src/material-experimental/mdc-checkbox/harness/mdc-checkbox-harness.ts +++ b/src/material-experimental/mdc-checkbox/testing/checkbox-harness.ts @@ -8,7 +8,7 @@ import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing'; import {coerceBooleanProperty} from '@angular/cdk/coercion'; -import {CheckboxHarnessFilters} from './checkbox-harness-filters'; +import {CheckboxHarnessFilters} from '@angular/material/checkbox/testing'; /** * Harness for interacting with a MDC-based mat-checkbox in tests. diff --git a/src/material-experimental/mdc-checkbox/testing/index.ts b/src/material-experimental/mdc-checkbox/testing/index.ts new file mode 100644 index 000000000000..676ca90f1ffa --- /dev/null +++ b/src/material-experimental/mdc-checkbox/testing/index.ts @@ -0,0 +1,9 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export * from './public-api'; diff --git a/src/material-experimental/mdc-checkbox/testing/public-api.ts b/src/material-experimental/mdc-checkbox/testing/public-api.ts new file mode 100644 index 000000000000..0c9800a26bd9 --- /dev/null +++ b/src/material-experimental/mdc-checkbox/testing/public-api.ts @@ -0,0 +1,9 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export * from './checkbox-harness'; diff --git a/src/material/checkbox/testing/BUILD.bazel b/src/material/checkbox/testing/BUILD.bazel new file mode 100644 index 000000000000..ce939855ab44 --- /dev/null +++ b/src/material/checkbox/testing/BUILD.bazel @@ -0,0 +1,47 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite") + +ng_module( + name = "testing", + srcs = glob( + ["**/*.ts"], + exclude = ["**/*.spec.ts"], + ), + module_name = "@angular/material/checkbox/testing", + deps = [ + "//src/cdk/coercion", + "//src/cdk/testing", + ], +) + +ng_test_library( + name = "shared_unit_tests", + srcs = ["shared.spec.ts"], + deps = [ + ":testing", + "//src/cdk/testing", + "//src/cdk/testing/testbed", + "//src/material/checkbox", + "@npm//@angular/forms", + "@npm//@angular/platform-browser", + ], +) + +ng_test_library( + name = "unit_tests_lib", + srcs = glob( + ["**/*.spec.ts"], + exclude = ["shared.spec.ts"], + ), + deps = [ + ":shared_unit_tests", + ":testing", + "//src/material/checkbox", + ], +) + +ng_web_test_suite( + name = "unit_tests", + deps = [":unit_tests_lib"], +) diff --git a/src/material-experimental/mdc-checkbox/harness/checkbox-harness-filters.ts b/src/material/checkbox/testing/checkbox-harness-filters.ts similarity index 100% rename from src/material-experimental/mdc-checkbox/harness/checkbox-harness-filters.ts rename to src/material/checkbox/testing/checkbox-harness-filters.ts diff --git a/src/material/checkbox/testing/checkbox-harness.spec.ts b/src/material/checkbox/testing/checkbox-harness.spec.ts new file mode 100644 index 000000000000..93d0348b409c --- /dev/null +++ b/src/material/checkbox/testing/checkbox-harness.spec.ts @@ -0,0 +1,7 @@ +import {MatCheckboxModule} from '@angular/material/checkbox'; +import {MatCheckboxHarness} from './checkbox-harness'; +import {runTests} from '@angular/material/checkbox/testing/shared.spec'; + +describe('Non-MDC-based MatCheckboxHarness', () => { + runTests(MatCheckboxModule, MatCheckboxHarness); +}); diff --git a/src/material-experimental/mdc-checkbox/harness/checkbox-harness.ts b/src/material/checkbox/testing/checkbox-harness.ts similarity index 100% rename from src/material-experimental/mdc-checkbox/harness/checkbox-harness.ts rename to src/material/checkbox/testing/checkbox-harness.ts index 5ca7c2577ede..3194941bdd5b 100644 --- a/src/material-experimental/mdc-checkbox/harness/checkbox-harness.ts +++ b/src/material/checkbox/testing/checkbox-harness.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing'; import {coerceBooleanProperty} from '@angular/cdk/coercion'; +import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing'; import {CheckboxHarnessFilters} from './checkbox-harness-filters'; /** diff --git a/src/material/checkbox/testing/index.ts b/src/material/checkbox/testing/index.ts new file mode 100644 index 000000000000..676ca90f1ffa --- /dev/null +++ b/src/material/checkbox/testing/index.ts @@ -0,0 +1,9 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export * from './public-api'; diff --git a/src/material/checkbox/testing/public-api.ts b/src/material/checkbox/testing/public-api.ts new file mode 100644 index 000000000000..1ea7015aa5ce --- /dev/null +++ b/src/material/checkbox/testing/public-api.ts @@ -0,0 +1,10 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export * from './checkbox-harness'; +export * from './checkbox-harness-filters'; diff --git a/src/material-experimental/mdc-checkbox/harness/checkbox-harness.spec.ts b/src/material/checkbox/testing/shared.spec.ts similarity index 80% rename from src/material-experimental/mdc-checkbox/harness/checkbox-harness.spec.ts rename to src/material/checkbox/testing/shared.spec.ts index a5bc5a34f856..6c9418b7c76f 100644 --- a/src/material-experimental/mdc-checkbox/harness/checkbox-harness.spec.ts +++ b/src/material/checkbox/testing/shared.spec.ts @@ -4,56 +4,30 @@ import {Component} from '@angular/core'; import {ComponentFixture, TestBed} from '@angular/core/testing'; import {FormControl, ReactiveFormsModule} from '@angular/forms'; import {MatCheckboxModule} from '@angular/material/checkbox'; -import {MatCheckboxModule as MatMdcCheckboxModule} from '../index'; -import {MatCheckboxHarness} from './checkbox-harness'; -import {MatCheckboxHarness as MatMdcCheckboxHarness} from './mdc-checkbox-harness'; - -let fixture: ComponentFixture; -let loader: HarnessLoader; -let checkboxHarness: typeof MatCheckboxHarness; - -describe('MatCheckboxHarness', () => { - describe('non-MDC-based', () => { - beforeEach(async () => { - await TestBed - .configureTestingModule({ - imports: [MatCheckboxModule, ReactiveFormsModule], - declarations: [CheckboxHarnessTest], - }) - .compileComponents(); - - fixture = TestBed.createComponent(CheckboxHarnessTest); - fixture.detectChanges(); - loader = TestbedHarnessEnvironment.loader(fixture); - checkboxHarness = MatCheckboxHarness; - }); - - runTests(); - }); - - describe('MDC-based', () => { - beforeEach(async () => { - await TestBed - .configureTestingModule({ - imports: [MatMdcCheckboxModule, ReactiveFormsModule], - declarations: [CheckboxHarnessTest], - }) - .compileComponents(); - - fixture = TestBed.createComponent(CheckboxHarnessTest); - fixture.detectChanges(); - loader = TestbedHarnessEnvironment.loader(fixture); - // Public APIs are the same as MatCheckboxHarness, but cast is necessary because of different - // private fields. - checkboxHarness = MatMdcCheckboxHarness as any; - }); - - runTests(); - }); -}); - -/** Shared tests to run on both the original and MDC-based checkboxes. */ -function runTests() { +import {MatCheckboxHarness} from '@angular/material/checkbox/testing/checkbox-harness'; + +/** + * Function that can be used to run the shared checkbox harness tests for either the non-MDC or + * MDC based checkbox harness. + */ +export function runTests( + checkboxModule: typeof MatCheckboxModule, checkboxHarness: typeof MatCheckboxHarness) { + let fixture: ComponentFixture; + let loader: HarnessLoader; + + beforeEach(async () => { + await TestBed + .configureTestingModule({ + imports: [checkboxModule, ReactiveFormsModule], + declarations: [CheckboxHarnessTest], + }) + .compileComponents(); + + fixture = TestBed.createComponent(CheckboxHarnessTest); + fixture.detectChanges(); + loader = TestbedHarnessEnvironment.loader(fixture); + }); + it('should load all checkbox harnesses', async () => { const checkboxes = await loader.getAllHarnesses(checkboxHarness); expect(checkboxes.length).toBe(2); diff --git a/src/material/tsconfig-tests.json b/src/material/tsconfig-tests.json index 5f9a37a56dec..e38ccb187d72 100644 --- a/src/material/tsconfig-tests.json +++ b/src/material/tsconfig-tests.json @@ -27,7 +27,7 @@ }, "include": [ "**/*.spec.ts", - "index.ts" + "./**/index.ts" ], "exclude": [ "**/schematics/**/*.ts", diff --git a/test/karma-system-config.js b/test/karma-system-config.js index 4dd9fea1dd6b..7bc238de9084 100644 --- a/test/karma-system-config.js +++ b/test/karma-system-config.js @@ -102,6 +102,8 @@ System.config({ '@angular/material/button-toggle': 'dist/packages/material/button-toggle/index.js', '@angular/material/card': 'dist/packages/material/card/index.js', '@angular/material/checkbox': 'dist/packages/material/checkbox/index.js', + '@angular/material/checkbox/testing': 'dist/packages/material/checkbox/testing/index.js', + '@angular/material/checkbox/testing/shared.spec': 'dist/packages/material/checkbox/testing/shared.spec.js', '@angular/material/chips': 'dist/packages/material/chips/index.js', '@angular/material/core': 'dist/packages/material/core/index.js', '@angular/material/datepicker': 'dist/packages/material/datepicker/index.js', @@ -138,6 +140,8 @@ System.config({ 'dist/packages/material-experimental/mdc-card/index.js', '@angular/material-experimental/mdc-checkbox': 'dist/packages/material-experimental/mdc-checkbox/index.js', + '@angular/material-experimental/mdc-checkbox/testing': + 'dist/packages/material-experimental/mdc-checkbox/testing/index.js', '@angular/material-experimental/mdc-chips': 'dist/packages/material-experimental/mdc-chips/index.js', '@angular/material-experimental/mdc-helpers':