Skip to content

Commit

Permalink
add test for showing after hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewseguin committed Oct 31, 2016
1 parent 827b434 commit b0cb8ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {MdTooltipModule} from './tooltip';

const initialTooltipMessage = 'initial tooltip message';

describe('MdTooltip', () => {
fdescribe('MdTooltip', () => {
let overlayContainerElement: HTMLElement;


Expand Down Expand Up @@ -49,14 +49,29 @@ describe('MdTooltip', () => {
fixture.detectChanges();
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);

// After hide called, a timeout delay is created that will to hide the tooltip.
tooltipDirective.hide();
expect(tooltipDirective._isTooltipVisible()).toBe(true);

// After hidden, expect that the tooltip is not visible.
// After the tooltip delay elapses, expect that the tooltip is not visible.
tick(TOOLTIP_HIDE_DELAY);
expect(tooltipDirective._isTooltipVisible()).toBe(false);
}));

fit('should not follow through with hide if show is called after', fakeAsync(() => {
tooltipDirective.show();
expect(tooltipDirective._isTooltipVisible()).toBe(true);

// After hide called, a timeout delay is created that will to hide the tooltip.
tooltipDirective.hide();
expect(tooltipDirective._isTooltipVisible()).toBe(true);

// Before delay time has passed, call show which should cancel intent to hide tooltip.
tooltipDirective.show();
tick(TOOLTIP_HIDE_DELAY);
expect(tooltipDirective._isTooltipVisible()).toBe(true);
}));

it('should remove the tooltip when changing position', () => {
const initialPosition: TooltipPosition = 'below';
const changedPosition: TooltipPosition = 'above';
Expand Down
5 changes: 5 additions & 0 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ export class TooltipComponent {
}
}

/**
* Interactions on the HTML body should close the tooltip immediately as defined in the
* material design spec.
* https://material.google.com/components/tooltips.html#tooltips-interaction
*/
_handleBodyInteraction(): void {
if (this._closeOnInteraction) {
this.hide(0);
Expand Down

0 comments on commit b0cb8ed

Please sign in to comment.