Skip to content

Commit

Permalink
feat(material/tooltip): add isDisabled method to harness (#27038)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadmehrabi committed May 8, 2023
1 parent 1ce3a3b commit 0028c68
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/material/legacy-tooltip/testing/tooltip-harness.ts
Expand Up @@ -17,6 +17,7 @@ import {_MatTooltipHarnessBase, TooltipHarnessFilters} from '@angular/material/t
export class MatLegacyTooltipHarness extends _MatTooltipHarnessBase {
protected _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-tooltip');
protected _hiddenClass = 'mat-tooltip-hide';
protected _disabledClass = 'mat-tooltip-disabled';
protected _showAnimationName = 'mat-tooltip-show';
protected _hideAnimationName = 'mat-tooltip-hide';
static hostSelector = '.mat-tooltip-trigger';
Expand Down
1 change: 1 addition & 0 deletions src/material/legacy-tooltip/tooltip.ts
Expand Up @@ -49,6 +49,7 @@ import {
exportAs: 'matTooltip',
host: {
'class': 'mat-tooltip-trigger',
'[class.mat-tooltip-disabled]': 'disabled',
},
})
export class MatLegacyTooltip extends _MatTooltipBase<LegacyTooltipComponent> {
Expand Down
15 changes: 12 additions & 3 deletions src/material/tooltip/testing/shared.spec.ts
Expand Up @@ -27,7 +27,7 @@ export function runHarnessTests(

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

it('should be able to show a tooltip', async () => {
Expand Down Expand Up @@ -56,12 +56,21 @@ export function runHarnessTests(
const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
expect(await tooltip.getTooltipText()).toBe('');
});

it('should get disabled state', async () => {
const enabled = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
const disabled = await loader.getHarness(tooltipHarness.with({selector: '#three'}));

expect(await enabled.isDisabled()).toBe(false);
expect(await disabled.isDisabled()).toBe(true);
});
}

@Component({
template: `
<button [matTooltip]="message" id="one">Trigger 1</button>
<button matTooltip="Static message" id="two">Trigger 2</button>
<button [matTooltip]='message' id='one'>Trigger 1</button>
<button matTooltip='Static message' id='two'>Trigger 2</button>
<button matTooltip='Disabled Tooltip' [matTooltipDisabled]='true' id='three'>Trigger 3</button>
`,
})
class TooltipHarnessTest {
Expand Down
8 changes: 8 additions & 0 deletions src/material/tooltip/testing/tooltip-harness.ts
Expand Up @@ -18,6 +18,7 @@ import {TooltipHarnessFilters} from './tooltip-harness-filters';
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;
protected abstract _hiddenClass: string;
protected abstract _disabledClass: string;
protected abstract _showAnimationName: string;
protected abstract _hideAnimationName: string;

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

/** Gets whether the tooltip is disabled */
async isDisabled(): Promise<boolean> {
const host = await this.host();
return host.hasClass(this._disabledClass);
}

/** Gets a promise for the tooltip panel's text. */
async getTooltipText(): Promise<string> {
const panel = await this._optionalPanel();
Expand All @@ -65,6 +72,7 @@ export class MatTooltipHarness extends _MatTooltipHarnessBase {
this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
static hostSelector = '.mat-mdc-tooltip-trigger';
protected _hiddenClass = 'mat-mdc-tooltip-hide';
protected _disabledClass = 'mat-mdc-tooltip-disabled';
protected _showAnimationName = 'mat-mdc-tooltip-show';
protected _hideAnimationName = 'mat-mdc-tooltip-hide';

Expand Down
2 changes: 2 additions & 0 deletions src/material/tooltip/tooltip.ts
Expand Up @@ -204,6 +204,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
get positionAtOrigin(): boolean {
return this._positionAtOrigin;
}

set positionAtOrigin(value: BooleanInput) {
this._positionAtOrigin = coerceBooleanProperty(value);
this._detach();
Expand Down Expand Up @@ -855,6 +856,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
exportAs: 'matTooltip',
host: {
'class': 'mat-mdc-tooltip-trigger',
'[class.mat-mdc-tooltip-disabled]': 'disabled',
},
})
export class MatTooltip extends _MatTooltipBase<TooltipComponent> {
Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/legacy-tooltip-testing.md
Expand Up @@ -14,6 +14,8 @@ export { LegacyTooltipHarnessFilters }

// @public @deprecated
export class MatLegacyTooltipHarness extends _MatTooltipHarnessBase {
// (undocumented)
protected _disabledClass: string;
// (undocumented)
protected _hiddenClass: string;
// (undocumented)
Expand Down
5 changes: 5 additions & 0 deletions tools/public_api_guard/material/tooltip-testing.md
Expand Up @@ -13,6 +13,8 @@ import { TestElement } from '@angular/cdk/testing';

// @public
export class MatTooltipHarness extends _MatTooltipHarnessBase {
// (undocumented)
protected _disabledClass: string;
// (undocumented)
protected _hiddenClass: string;
// (undocumented)
Expand All @@ -28,12 +30,15 @@ export class MatTooltipHarness extends _MatTooltipHarnessBase {

// @public (undocumented)
export abstract class _MatTooltipHarnessBase extends ComponentHarness {
// (undocumented)
protected abstract _disabledClass: string;
getTooltipText(): Promise<string>;
// (undocumented)
protected abstract _hiddenClass: string;
hide(): Promise<void>;
// (undocumented)
protected abstract _hideAnimationName: string;
isDisabled(): Promise<boolean>;
isOpen(): Promise<boolean>;
// (undocumented)
protected abstract _optionalPanel: AsyncFactoryFn<TestElement | null>;
Expand Down

0 comments on commit 0028c68

Please sign in to comment.