Skip to content

Commit

Permalink
Merge branch 'main' into 835-add-left-button-to-ion-header
Browse files Browse the repository at this point in the history
  • Loading branch information
allan-chagas-brisa authored Sep 28, 2023
2 parents 64c9047 + 88d3bd9 commit a194a34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions projects/ion/src/lib/tooltip/tooltip.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TooltipTrigger,
} from '../core/types';
import { IonTooltipModule } from './tooltip.module';
import { IonTooltipDirective } from './tooltip.directive';

@Component({
template: `
Expand Down Expand Up @@ -130,6 +131,17 @@ describe('Directive: Tooltip', () => {
);
});

it('should close the tooltip when scrolling the page', async () => {
await sut();
const directive = IonTooltipDirective.prototype;
jest.spyOn(directive, 'onScroll');

fireEvent.mouseEnter(screen.getByTestId('hostTooltip'));
fireEvent.scroll(window);
expect(directive.onScroll).toBeCalled();
expect(screen.queryByTestId('ion-tooltip')).not.toBeInTheDocument();
});

describe('trigger: click', () => {
afterEach(async () => {
fireEvent.click(screen.getByTestId('hostTooltip'));
Expand Down
4 changes: 4 additions & 0 deletions projects/ion/src/lib/tooltip/tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export class IonTooltipDirective implements OnDestroy, OnInit {
}
}

@HostListener('window:scroll') onScroll(): void {
this.destroyComponent();
}

ngOnDestroy(): void {
this.destroyComponent();
this.subscription$.unsubscribe();
Expand Down

0 comments on commit a194a34

Please sign in to comment.