Skip to content

Commit 0028c68

Browse files
feat(material/tooltip): add isDisabled method to harness (#27038)
1 parent 1ce3a3b commit 0028c68

File tree

7 files changed

+31
-3
lines changed

7 files changed

+31
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {_MatTooltipHarnessBase, TooltipHarnessFilters} from '@angular/material/t
1717
export class MatLegacyTooltipHarness extends _MatTooltipHarnessBase {
1818
protected _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-tooltip');
1919
protected _hiddenClass = 'mat-tooltip-hide';
20+
protected _disabledClass = 'mat-tooltip-disabled';
2021
protected _showAnimationName = 'mat-tooltip-show';
2122
protected _hideAnimationName = 'mat-tooltip-hide';
2223
static hostSelector = '.mat-tooltip-trigger';

src/material/legacy-tooltip/tooltip.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
exportAs: 'matTooltip',
5050
host: {
5151
'class': 'mat-tooltip-trigger',
52+
'[class.mat-tooltip-disabled]': 'disabled',
5253
},
5354
})
5455
export class MatLegacyTooltip extends _MatTooltipBase<LegacyTooltipComponent> {

src/material/tooltip/testing/shared.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function runHarnessTests(
2727

2828
it('should load all tooltip harnesses', async () => {
2929
const tooltips = await loader.getAllHarnesses(tooltipHarness);
30-
expect(tooltips.length).toBe(2);
30+
expect(tooltips.length).toBe(3);
3131
});
3232

3333
it('should be able to show a tooltip', async () => {
@@ -56,12 +56,21 @@ export function runHarnessTests(
5656
const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
5757
expect(await tooltip.getTooltipText()).toBe('');
5858
});
59+
60+
it('should get disabled state', async () => {
61+
const enabled = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
62+
const disabled = await loader.getHarness(tooltipHarness.with({selector: '#three'}));
63+
64+
expect(await enabled.isDisabled()).toBe(false);
65+
expect(await disabled.isDisabled()).toBe(true);
66+
});
5967
}
6068

6169
@Component({
6270
template: `
63-
<button [matTooltip]="message" id="one">Trigger 1</button>
64-
<button matTooltip="Static message" id="two">Trigger 2</button>
71+
<button [matTooltip]='message' id='one'>Trigger 1</button>
72+
<button matTooltip='Static message' id='two'>Trigger 2</button>
73+
<button matTooltip='Disabled Tooltip' [matTooltipDisabled]='true' id='three'>Trigger 3</button>
6574
`,
6675
})
6776
class TooltipHarnessTest {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {TooltipHarnessFilters} from './tooltip-harness-filters';
1818
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
1919
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;
2020
protected abstract _hiddenClass: string;
21+
protected abstract _disabledClass: string;
2122
protected abstract _showAnimationName: string;
2223
protected abstract _hideAnimationName: string;
2324

@@ -52,6 +53,12 @@ export abstract class _MatTooltipHarnessBase extends ComponentHarness {
5253
return !!panel && !(await panel.hasClass(this._hiddenClass));
5354
}
5455

56+
/** Gets whether the tooltip is disabled */
57+
async isDisabled(): Promise<boolean> {
58+
const host = await this.host();
59+
return host.hasClass(this._disabledClass);
60+
}
61+
5562
/** Gets a promise for the tooltip panel's text. */
5663
async getTooltipText(): Promise<string> {
5764
const panel = await this._optionalPanel();
@@ -65,6 +72,7 @@ export class MatTooltipHarness extends _MatTooltipHarnessBase {
6572
this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
6673
static hostSelector = '.mat-mdc-tooltip-trigger';
6774
protected _hiddenClass = 'mat-mdc-tooltip-hide';
75+
protected _disabledClass = 'mat-mdc-tooltip-disabled';
6876
protected _showAnimationName = 'mat-mdc-tooltip-show';
6977
protected _hideAnimationName = 'mat-mdc-tooltip-hide';
7078

src/material/tooltip/tooltip.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
204204
get positionAtOrigin(): boolean {
205205
return this._positionAtOrigin;
206206
}
207+
207208
set positionAtOrigin(value: BooleanInput) {
208209
this._positionAtOrigin = coerceBooleanProperty(value);
209210
this._detach();
@@ -855,6 +856,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
855856
exportAs: 'matTooltip',
856857
host: {
857858
'class': 'mat-mdc-tooltip-trigger',
859+
'[class.mat-mdc-tooltip-disabled]': 'disabled',
858860
},
859861
})
860862
export class MatTooltip extends _MatTooltipBase<TooltipComponent> {

tools/public_api_guard/material/legacy-tooltip-testing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export { LegacyTooltipHarnessFilters }
1414

1515
// @public @deprecated
1616
export class MatLegacyTooltipHarness extends _MatTooltipHarnessBase {
17+
// (undocumented)
18+
protected _disabledClass: string;
1719
// (undocumented)
1820
protected _hiddenClass: string;
1921
// (undocumented)

tools/public_api_guard/material/tooltip-testing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { TestElement } from '@angular/cdk/testing';
1313

1414
// @public
1515
export class MatTooltipHarness extends _MatTooltipHarnessBase {
16+
// (undocumented)
17+
protected _disabledClass: string;
1618
// (undocumented)
1719
protected _hiddenClass: string;
1820
// (undocumented)
@@ -28,12 +30,15 @@ export class MatTooltipHarness extends _MatTooltipHarnessBase {
2830

2931
// @public (undocumented)
3032
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
33+
// (undocumented)
34+
protected abstract _disabledClass: string;
3135
getTooltipText(): Promise<string>;
3236
// (undocumented)
3337
protected abstract _hiddenClass: string;
3438
hide(): Promise<void>;
3539
// (undocumented)
3640
protected abstract _hideAnimationName: string;
41+
isDisabled(): Promise<boolean>;
3742
isOpen(): Promise<boolean>;
3843
// (undocumented)
3944
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;

0 commit comments

Comments
 (0)