@@ -10,14 +10,14 @@ import {
10
10
ComponentHarness ,
11
11
ComponentHarnessConstructor ,
12
12
HarnessPredicate ,
13
+ TestElement ,
13
14
} from '@angular/cdk/testing' ;
14
15
import { TooltipHarnessFilters } from './tooltip-harness-filters' ;
15
16
16
17
/** Harness for interacting with a mat-tooltip in tests. */
17
18
export class MatTooltipHarness extends ComponentHarness {
18
19
static hostSelector = '.mat-mdc-tooltip-trigger' ;
19
20
20
- private _optionalPanel = this . documentRootLocatorFactory ( ) . locatorForOptional ( '.mat-mdc-tooltip' ) ;
21
21
private _hiddenClass = 'mat-mdc-tooltip-hide' ;
22
22
private _disabledClass = 'mat-mdc-tooltip-disabled' ;
23
23
private _showAnimationName = 'mat-mdc-tooltip-show' ;
@@ -45,7 +45,7 @@ export class MatTooltipHarness extends ComponentHarness {
45
45
// element has ripples.
46
46
await host . dispatchEvent ( 'touchstart' , { changedTouches : [ ] } ) ;
47
47
await host . hover ( ) ;
48
- const panel = await this . _optionalPanel ( ) ;
48
+ const panel = await this . _getPanel ( ) ;
49
49
await panel ?. dispatchEvent ( 'animationend' , { animationName : this . _showAnimationName } ) ;
50
50
}
51
51
@@ -57,13 +57,13 @@ export class MatTooltipHarness extends ComponentHarness {
57
57
// the tooltip binds different events depending on the device.
58
58
await host . dispatchEvent ( 'touchend' ) ;
59
59
await host . mouseAway ( ) ;
60
- const panel = await this . _optionalPanel ( ) ;
60
+ const panel = await this . _getPanel ( ) ;
61
61
await panel ?. dispatchEvent ( 'animationend' , { animationName : this . _hideAnimationName } ) ;
62
62
}
63
63
64
64
/** Gets whether the tooltip is open. */
65
65
async isOpen ( ) : Promise < boolean > {
66
- const panel = await this . _optionalPanel ( ) ;
66
+ const panel = await this . _getPanel ( ) ;
67
67
return ! ! panel && ! ( await panel . hasClass ( this . _hiddenClass ) ) ;
68
68
}
69
69
@@ -75,7 +75,14 @@ export class MatTooltipHarness extends ComponentHarness {
75
75
76
76
/** Gets a promise for the tooltip panel's text. */
77
77
async getTooltipText ( ) : Promise < string > {
78
- const panel = await this . _optionalPanel ( ) ;
78
+ const panel = await this . _getPanel ( ) ;
79
79
return panel ? panel . text ( ) : '' ;
80
80
}
81
+
82
+ /** Gets the tooltip panel associated with the trigger. */
83
+ private async _getPanel ( ) : Promise < TestElement | null > {
84
+ const host = await this . host ( ) ;
85
+ const locatorFactory = this . documentRootLocatorFactory ( ) ;
86
+ return locatorFactory . locatorForOptional ( `#${ await host . getAttribute ( 'data-mat-tooltip' ) } ` ) ( ) ;
87
+ }
81
88
}
0 commit comments