Skip to content

Commit 5e4d5e0

Browse files
authored
feat(material-experimental/mdc-tooltip): add test harness (#21855)
Sets up a test harness for the MDC-based tooltip.
1 parent 52aa210 commit 5e4d5e0

File tree

9 files changed

+128
-16
lines changed

9 files changed

+128
-16
lines changed

scripts/check-mdc-exports-config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export const config = {
9898
'_MatTooltipBase',
9999
'_TooltipComponentBase'
100100
],
101+
'mdc-tooltip/testing': [
102+
// Private symbols that are only exported for MDC.
103+
'_MatTooltipHarnessBase'
104+
],
101105
'mdc-checkbox/testing': [
102106
// Private symbols that are only exported for MDC.
103107
'_MatCheckboxHarnessBase'

src/material-experimental/config.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ entryPoints = [
4444
"mdc-tabs",
4545
"mdc-tabs/testing",
4646
"mdc-tooltip",
47+
"mdc-tooltip/testing",
4748
"menubar",
4849
"popover-edit",
4950
"selection",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
load("//tools:defaults.bzl", "ng_test_library", "ng_web_test_suite", "ts_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ts_library(
6+
name = "testing",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/material-experimental/mdc-tooltip/testing",
12+
deps = [
13+
"//src/cdk/testing",
14+
"//src/material/tooltip/testing",
15+
],
16+
)
17+
18+
filegroup(
19+
name = "source-files",
20+
srcs = glob(["**/*.ts"]),
21+
)
22+
23+
ng_test_library(
24+
name = "unit_tests_lib",
25+
srcs = glob(["**/*.spec.ts"]),
26+
deps = [
27+
":testing",
28+
"//src/material-experimental/mdc-tooltip",
29+
"//src/material/tooltip/testing:harness_tests_lib",
30+
],
31+
)
32+
33+
ng_web_test_suite(
34+
name = "unit_tests",
35+
static_files = ["@npm//:node_modules/@material/tooltip/dist/mdc.tooltip.js"],
36+
deps = [
37+
":unit_tests_lib",
38+
"//src/material-experimental:mdc_require_config.js",
39+
],
40+
)
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';
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 './tooltip-harness';
10+
export {TooltipHarnessFilters} from '@angular/material/tooltip/testing';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {MatTooltipModule} from '@angular/material-experimental/mdc-tooltip';
2+
import {runHarnessTests} from '@angular/material/tooltip/testing/shared.spec';
3+
import {MatTooltipHarness} from './index';
4+
5+
describe('MDC-based MatTooltipHarness', () => {
6+
runHarnessTests(MatTooltipModule, MatTooltipHarness as any);
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
import {HarnessPredicate} from '@angular/cdk/testing';
10+
import {_MatTooltipHarnessBase, TooltipHarnessFilters} from '@angular/material/tooltip/testing';
11+
12+
/** Harness for interacting with a standard mat-tooltip in tests. */
13+
export class MatTooltipHarness extends _MatTooltipHarnessBase {
14+
protected _optionalPanel =
15+
this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
16+
static hostSelector = '.mat-mdc-tooltip-trigger';
17+
18+
/**
19+
* Gets a `HarnessPredicate` that can be used to search
20+
* for a tooltip trigger with specific attributes.
21+
* @param options Options for narrowing the search.
22+
* @return a `HarnessPredicate` configured with the given options.
23+
*/
24+
static with(options: TooltipHarnessFilters = {}): HarnessPredicate<MatTooltipHarness> {
25+
return new HarnessPredicate(MatTooltipHarness, options);
26+
}
27+
}

src/material/tooltip/testing/tooltip-harness.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
9+
import {
10+
AsyncFactoryFn,
11+
ComponentHarness,
12+
HarnessPredicate,
13+
TestElement,
14+
} from '@angular/cdk/testing';
1015
import {TooltipHarnessFilters} from './tooltip-harness-filters';
1116

12-
/** Harness for interacting with a standard mat-tooltip in tests. */
13-
export class MatTooltipHarness extends ComponentHarness {
14-
private _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-tooltip');
15-
static hostSelector = '.mat-tooltip-trigger';
16-
17-
/**
18-
* Gets a `HarnessPredicate` that can be used to search
19-
* for a tooltip trigger with specific attributes.
20-
* @param options Options for narrowing the search.
21-
* @return a `HarnessPredicate` configured with the given options.
22-
*/
23-
static with(options: TooltipHarnessFilters = {}): HarnessPredicate<MatTooltipHarness> {
24-
return new HarnessPredicate(MatTooltipHarness, options);
25-
}
17+
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
18+
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;
2619

2720
/** Shows the tooltip. */
2821
async show(): Promise<void> {
@@ -59,3 +52,19 @@ export class MatTooltipHarness extends ComponentHarness {
5952
return panel ? panel.text() : '';
6053
}
6154
}
55+
56+
/** Harness for interacting with a standard mat-tooltip in tests. */
57+
export class MatTooltipHarness extends _MatTooltipHarnessBase {
58+
protected _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-tooltip');
59+
static hostSelector = '.mat-tooltip-trigger';
60+
61+
/**
62+
* Gets a `HarnessPredicate` that can be used to search
63+
* for a tooltip trigger with specific attributes.
64+
* @param options Options for narrowing the search.
65+
* @return a `HarnessPredicate` configured with the given options.
66+
*/
67+
static with(options: TooltipHarnessFilters = {}): HarnessPredicate<MatTooltipHarness> {
68+
return new HarnessPredicate(MatTooltipHarness, options);
69+
}
70+
}

tools/public_api_guard/material/tooltip/testing.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
export declare class MatTooltipHarness extends ComponentHarness {
1+
export declare abstract class _MatTooltipHarnessBase extends ComponentHarness {
2+
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;
23
getTooltipText(): Promise<string>;
34
hide(): Promise<void>;
45
isOpen(): Promise<boolean>;
56
show(): Promise<void>;
7+
}
8+
9+
export declare class MatTooltipHarness extends _MatTooltipHarnessBase {
10+
protected _optionalPanel: AsyncFactoryFn<TestElement | null>;
611
static hostSelector: string;
712
static with(options?: TooltipHarnessFilters): HarnessPredicate<MatTooltipHarness>;
813
}

0 commit comments

Comments
 (0)