Skip to content
Snippets Groups Projects
Commit b5e79faf authored by Bernhard Fürst's avatar Bernhard Fürst
Browse files

OZG-7367 OZG-7420 Don't show tooltip if text is empty

parent ae5cf1bc
No related branches found
No related tags found
1 merge request!2OZG-7367 Extend tooltip directive
......@@ -21,9 +21,11 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { EMPTY_STRING } from '@alfa-client/tech-shared';
import { InteractivityChecker } from '@angular/cdk/a11y';
import { ComponentRef, ElementRef, Renderer2, ViewContainerRef } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { faker } from '@faker-js/faker/.';
import { TooltipComponent } from './tooltip.component';
import { TooltipDirective, TooltipPosition } from './tooltip.directive';
......@@ -89,6 +91,7 @@ describe('TooltipDirective', () => {
directive.setInitialTooltipProperties = jest.fn();
directive.getParentElement = jest.fn().mockReturnValue({ appendChild: jest.fn() });
directive.interactivityChecker.isFocusable = jest.fn();
directive.tooltip = faker.lorem.sentence();
});
it('should create tooltip component', () => {
......@@ -120,6 +123,14 @@ describe('TooltipDirective', () => {
expect(directive.setAriaAttribute).toHaveBeenCalled();
});
it('should not create tooltip', () => {
directive.tooltip = EMPTY_STRING;
directive.createTooltip();
expect(directive.getParentElement).not.toHaveBeenCalled();
});
});
describe('showTooltip', () => {
......
......@@ -35,7 +35,7 @@ import {
Renderer2,
ViewContainerRef,
} from '@angular/core';
import { isNull, uniqueId } from 'lodash-es';
import { isEmpty, isNull, uniqueId } from 'lodash-es';
import { TooltipComponent } from './tooltip.component';
export enum TooltipPosition {
......@@ -98,6 +98,10 @@ export class TooltipDirective implements AfterViewInit, OnDestroy {
}
createTooltip(): void {
if (isEmpty(this.tooltip)) {
return;
}
const nativeElement: HTMLElement = this.elementRef.nativeElement;
this.componentRef = this.viewContainerRef.createComponent(TooltipComponent);
this.parentElement = this.getParentElement(nativeElement);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment