7
7
*/
8
8
9
9
import {
10
- AsyncFactoryFn ,
11
10
ComponentHarness ,
12
11
ComponentHarnessConstructor ,
13
12
HarnessPredicate ,
@@ -16,7 +15,6 @@ import {
16
15
import { TooltipHarnessFilters } from './tooltip-harness-filters' ;
17
16
18
17
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
19
- protected abstract _optionalPanel : AsyncFactoryFn < TestElement | null > ;
20
18
protected abstract _hiddenClass : string ;
21
19
protected abstract _showAnimationName : string ;
22
20
protected abstract _hideAnimationName : string ;
@@ -30,7 +28,7 @@ export abstract class _MatTooltipHarnessBase extends ComponentHarness {
30
28
// element has ripples.
31
29
await host . dispatchEvent ( 'touchstart' , { changedTouches : [ ] } ) ;
32
30
await host . hover ( ) ;
33
- const panel = await this . _optionalPanel ( ) ;
31
+ const panel = await this . _getPanel ( ) ;
34
32
await panel ?. dispatchEvent ( 'animationend' , { animationName : this . _showAnimationName } ) ;
35
33
}
36
34
@@ -42,27 +40,32 @@ export abstract class _MatTooltipHarnessBase extends ComponentHarness {
42
40
// the tooltip binds different events depending on the device.
43
41
await host . dispatchEvent ( 'touchend' ) ;
44
42
await host . mouseAway ( ) ;
45
- const panel = await this . _optionalPanel ( ) ;
43
+ const panel = await this . _getPanel ( ) ;
46
44
await panel ?. dispatchEvent ( 'animationend' , { animationName : this . _hideAnimationName } ) ;
47
45
}
48
46
49
47
/** Gets whether the tooltip is open. */
50
48
async isOpen ( ) : Promise < boolean > {
51
- const panel = await this . _optionalPanel ( ) ;
49
+ const panel = await this . _getPanel ( ) ;
52
50
return ! ! panel && ! ( await panel . hasClass ( this . _hiddenClass ) ) ;
53
51
}
54
52
55
53
/** Gets a promise for the tooltip panel's text. */
56
54
async getTooltipText ( ) : Promise < string > {
57
- const panel = await this . _optionalPanel ( ) ;
55
+ const panel = await this . _getPanel ( ) ;
58
56
return panel ? panel . text ( ) : '' ;
59
57
}
58
+
59
+ /** Gets the tooltip panel associated with the trigger. */
60
+ private async _getPanel ( ) : Promise < TestElement | null > {
61
+ const host = await this . host ( ) ;
62
+ const locatorFactory = this . documentRootLocatorFactory ( ) ;
63
+ return locatorFactory . locatorForOptional ( `#${ await host . getAttribute ( 'data-mat-tooltip' ) } ` ) ( ) ;
64
+ }
60
65
}
61
66
62
67
/** Harness for interacting with a standard mat-tooltip in tests. */
63
68
export class MatTooltipHarness extends _MatTooltipHarnessBase {
64
- protected _optionalPanel =
65
- this . documentRootLocatorFactory ( ) . locatorForOptional ( '.mat-mdc-tooltip' ) ;
66
69
static hostSelector = '.mat-mdc-tooltip-trigger' ;
67
70
protected _hiddenClass = 'mat-mdc-tooltip-hide' ;
68
71
protected _showAnimationName = 'mat-mdc-tooltip-show' ;
0 commit comments