Skip to content

Commit

Permalink
feat(button): move harness out of experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Sep 16, 2019
1 parent dec116b commit ae216d8
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 66 deletions.
28 changes: 8 additions & 20 deletions src/material-experimental/mdc-button/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package(default_visibility = ["//visibility:public"])

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

ng_module(
name = "mdc-button",
srcs = glob(
["**/*.ts"],
exclude = [
"**/*.spec.ts",
"harness/**",
],
),
assets = [
Expand All @@ -26,18 +25,6 @@ ng_module(
],
)

ts_library(
name = "harness",
srcs = glob(
["harness/**/*.ts"],
exclude = ["**/*.spec.ts"],
),
deps = [
"//src/cdk/coercion",
"//src/cdk/testing",
],
)

sass_library(
name = "mdc_button_scss_lib",
srcs = glob(["**/_*.scss"]),
Expand Down Expand Up @@ -94,16 +81,17 @@ sass_binary(

ng_test_library(
name = "button_tests_lib",
srcs = [
"harness/button-harness.spec.ts",
],
srcs = glob(
["**/*.spec.ts"],
exclude = [
"**/*.e2e.spec.ts",
],
),
deps = [
":harness",
":mdc-button",
"//src/cdk/platform",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/button",
"//src/material/core",
"@npm//@angular/platform-browser",
],
)
Expand Down
36 changes: 36 additions & 0 deletions src/material-experimental/mdc-button/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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-button/testing",
deps = [
"//src/cdk/coercion",
"//src/cdk/testing",
"//src/material/button/testing",
],
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":testing",
"//src/material-experimental/mdc-button",
"//src/material/button/testing:harness_tests_lib",
],
)

ng_web_test_suite(
name = "unit_tests",
static_files = ["@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 {runHarnessTests} from '@angular/material/button/testing/shared.spec';
import {MatButtonModule} from '../index';
import {MatButtonHarness} from './button-harness';

describe('MDC-based MatButtonHarness', () => {
runHarnessTests(MatButtonModule, MatButtonHarness);
});
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 {ButtonHarnessFilters} from './button-harness-filters';
import {ButtonHarnessFilters} from '@angular/material/button/testing/button-harness-filters';


/**
Expand Down
9 changes: 9 additions & 0 deletions src/material-experimental/mdc-button/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-button/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 './button-harness';
48 changes: 48 additions & 0 deletions src/material/button/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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/button/testing",
deps = [
"//src/cdk/coercion",
"//src/cdk/testing",
],
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/platform",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/button",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
],
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(
["**/*.spec.ts"],
exclude = ["shared.spec.ts"],
),
deps = [
":harness_tests_lib",
":testing",
"//src/material/button",
],
)

ng_web_test_suite(
name = "unit_tests",
deps = [":unit_tests_lib"],
)
7 changes: 7 additions & 0 deletions src/material/button/testing/button-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {MatButtonModule} from '@angular/material/button';
import {runHarnessTests} from '@angular/material/button/testing/shared.spec';
import {MatButtonHarness} from './button-harness';

describe('Non-MDC-based MatButtonHarness', () => {
runHarnessTests(MatButtonModule, MatButtonHarness);
});
9 changes: 9 additions & 0 deletions src/material/button/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/button/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 './button-harness';
export * from './button-harness-filters';
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
import {Platform, PlatformModule} from '@angular/cdk/platform';
import {HarnessLoader} from '@angular/cdk/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {Platform, PlatformModule} from '@angular/cdk/platform';
import {Component} from '@angular/core';
import {ComponentFixture, inject, TestBed} from '@angular/core/testing';
import {MatButtonModule} from '@angular/material/button';
import {MatButtonModule as MatMdcButtonModule} from '../index';
import {MatButtonHarness} from './button-harness';
import {MatButtonHarness as MatMdcButtonHarness} from './mdc-button-harness';

let fixture: ComponentFixture<ButtonHarnessTest>;
let loader: HarnessLoader;
let buttonHarness: typeof MatButtonHarness;
let platform: Platform;

describe('MatButtonHarness', () => {
describe('non-MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatButtonModule, PlatformModule],
declarations: [ButtonHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(ButtonHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
buttonHarness = MatButtonHarness;
});

runTests();
});
import {MatButtonHarness} from '@angular/material/button/testing/button-harness';

describe('MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatMdcButtonModule],
declarations: [ButtonHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(ButtonHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
// Public APIs are the same as MatButtonHarness, but cast is necessary because of different
// private fields.
buttonHarness = MatMdcButtonHarness as any;
});

runTests();
/** Shared tests to run on both the original and MDC-based buttons. */
export function runHarnessTests(
buttonModule: typeof MatButtonModule, buttonHarness: typeof MatButtonHarness) {
let fixture: ComponentFixture<ButtonHarnessTest>;
let loader: HarnessLoader;
let platform: Platform;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [buttonModule, PlatformModule],
declarations: [ButtonHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(ButtonHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});
});

/** Shared tests to run on both the original and MDC-based buttons. */
function runTests() {
beforeEach(inject([Platform], (p: Platform) => {
platform = p;
}));
Expand Down
2 changes: 2 additions & 0 deletions test/karma-system-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ System.config({
'@angular/material/badge': 'dist/packages/material/badge/index.js',
'@angular/material/bottom-sheet': 'dist/packages/material/bottom-sheet/index.js',
'@angular/material/button': 'dist/packages/material/button/index.js',
'@angular/material/button/testing': 'dist/packages/material/button/testing/index.js',
'@angular/material/button/testing/shared.spec': 'dist/packages/material/button/testing/shared.spec.js',
'@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',
Expand Down

0 comments on commit ae216d8

Please sign in to comment.