Skip to content
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

feat(material-experimental/checkbox): Add test harnesses for both versions of mat-checkbox #16334

Merged
merged 8 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
/src/material-experimental/mdc-radio/** @mmalerba
/src/material-experimental/mdc-slide-toggle/** @crisbeto
/src/material-experimental/mdc-tabs/** @crisbeto
/src/material-experimental/mdc-theming/** @mmalerba
/src/material-experimental/mdc-typography/** @mmalerba
/src/material-experimental/popover-edit/** @kseamon @andrewseguin

# CDK experimental package
Expand Down
6 changes: 0 additions & 6 deletions src/cdk-experimental/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ ng_module(
["**/*.ts"],
exclude = [
"**/*.spec.ts",
"tests/**",
],
),
module_name = "@angular/cdk-experimental/testing",
deps = [
"//src/cdk/testing",
"@npm//@angular/core",
"@npm//protractor",
],
)

ng_web_test_suite(
Expand Down
16 changes: 16 additions & 0 deletions src/cdk-experimental/testing/protractor/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "protractor",
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
module_name = "@angular/cdk-experimental/testing/protractor",
deps = [
"//src/cdk-experimental/testing",
"@npm//protractor",
],
)
3 changes: 1 addition & 2 deletions src/cdk-experimental/testing/protractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* found in the LICENSE file at https://angular.io/license
*/

export * from './protractor-element';
export * from './protractor-harness-environment';
export * from './public-api';
5 changes: 5 additions & 0 deletions src/cdk-experimental/testing/protractor/protractor-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ export class ProtractorElement implements TestElement {
async getAttribute(name: string): Promise<string|null> {
return this.element.getAttribute(name);
}

async hasClass(name: string): Promise<boolean> {
const classes = (await this.getAttribute('class')) || '';
return new Set(classes.split(/\s+/).filter(c => c)).has(name);
mmalerba marked this conversation as resolved.
Show resolved Hide resolved
}
}
10 changes: 10 additions & 0 deletions src/cdk-experimental/testing/protractor/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 './protractor-element';
export * from './protractor-harness-environment';
2 changes: 0 additions & 2 deletions src/cdk-experimental/testing/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@

export * from './component-harness';
export * from './harness-environment';
export * from './protractor';
export * from './test-element';
export * from './testbed';
3 changes: 3 additions & 0 deletions src/cdk-experimental/testing/test-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ export interface TestElement {
* falls back to reading the property.
*/
getAttribute(name: string): Promise<string | null>;

/** Checks whether the element has the given class. */
hasClass(name: string): Promise<boolean>;
}
17 changes: 17 additions & 0 deletions src/cdk-experimental/testing/testbed/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "testbed",
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
module_name = "@angular/cdk-experimental/testing/testbed",
deps = [
"//src/cdk-experimental/testing",
"//src/cdk/testing",
"@npm//@angular/core",
],
)
3 changes: 1 addition & 2 deletions src/cdk-experimental/testing/testbed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* found in the LICENSE file at https://angular.io/license
*/

export * from './testbed-harness-environment';
export * from './unit-test-element';
export * from './public-api';
10 changes: 10 additions & 0 deletions src/cdk-experimental/testing/testbed/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 './testbed-harness-environment';
export * from './unit-test-element';
7 changes: 6 additions & 1 deletion src/cdk-experimental/testing/testbed/unit-test-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class UnitTestElement implements TestElement {

async text(): Promise<string> {
await this._stabilize();
return this.element.textContent || '';
return (this.element.textContent || '').trim();
}

async getAttribute(name: string): Promise<string|null> {
Expand All @@ -100,4 +100,9 @@ export class UnitTestElement implements TestElement {
}
return value;
}

async hasClass(name: string): Promise<boolean> {
await this._stabilize();
return this.element.classList.contains(name);
}
}
2 changes: 2 additions & 0 deletions src/cdk-experimental/testing/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ng_test_library(
":test_components",
":test_harnesses",
"//src/cdk-experimental/testing",
"//src/cdk-experimental/testing/testbed",
],
)

Expand All @@ -45,5 +46,6 @@ ng_e2e_test_library(
deps = [
":test_harnesses",
"//src/cdk-experimental/testing",
"//src/cdk-experimental/testing/protractor",
],
)
4 changes: 2 additions & 2 deletions src/cdk-experimental/testing/tests/protractor.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HarnessLoader} from '@angular/cdk-experimental/testing';
import {ProtractorHarnessEnvironment} from '@angular/cdk-experimental/testing/protractor';
import {browser} from 'protractor';
import {HarnessLoader} from '../component-harness';
import {ProtractorHarnessEnvironment} from '../protractor';
import {MainComponentHarness} from './harnesses/main-component-harness';
import {SubComponentHarness} from './harnesses/sub-component-harness';

Expand Down
4 changes: 2 additions & 2 deletions src/cdk-experimental/testing/tests/testbed.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HarnessLoader} from '@angular/cdk-experimental/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {HarnessLoader} from '../component-harness';
import {TestbedHarnessEnvironment} from '../testbed/index';
import {MainComponentHarness} from './harnesses/main-component-harness';
import {SubComponentHarness} from './harnesses/sub-component-harness';
import {TestComponentsModule} from './test-components-module';
Expand Down
23 changes: 21 additions & 2 deletions src/material-experimental/mdc-checkbox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
load("@npm_angular_bazel//:index.bzl", "protractor_web_test_suite")
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite")
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")

ng_module(
name = "mdc-checkbox",
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
exclude = [
"**/*.spec.ts",
"harness/**",
],
),
assets = [":checkbox_scss"] + glob(["**/*.html"]),
module_name = "@angular/material-experimental/mdc-checkbox",
Expand All @@ -25,6 +28,18 @@ ng_module(
],
)

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

sass_library(
name = "mdc_checkbox_scss_lib",
srcs = glob(["**/_*.scss"]),
Expand Down Expand Up @@ -55,8 +70,12 @@ ng_test_library(
exclude = ["**/*.e2e.spec.ts"],
),
deps = [
":harness",
":mdc-checkbox",
"//src/cdk-experimental/testing",
"//src/cdk-experimental/testing/testbed",
"//src/cdk/testing",
"//src/material/checkbox",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
],
Expand Down
Loading