Skip to content

feat(checkbox): move checkbox harness out of experimental #17067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/material-experimental/mdc-checkbox/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/material-experimental/mdc-checkbox/testing/index.ts
Original file line number Diff line number Diff line change
@@ -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';
9 changes: 9 additions & 0 deletions src/material-experimental/mdc-checkbox/testing/public-api.ts
Original file line number Diff line number Diff line change
@@ -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';
47 changes: 47 additions & 0 deletions src/material/checkbox/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
7 changes: 7 additions & 0 deletions src/material/checkbox/testing/checkbox-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
9 changes: 9 additions & 0 deletions src/material/checkbox/testing/index.ts
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 10 additions & 0 deletions src/material/checkbox/testing/public-api.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckboxHarnessTest>;
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<CheckboxHarnessTest>;
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);
Expand Down
2 changes: 1 addition & 1 deletion src/material/tsconfig-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"include": [
"**/*.spec.ts",
"index.ts"
"./**/index.ts"
],
"exclude": [
"**/schematics/**/*.ts",
Expand Down
4 changes: 4 additions & 0 deletions test/karma-system-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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':
Expand Down