Skip to content

Commit

Permalink
fix(Tooltip): add unit tests for tooltip onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
russi-sinha committed Sep 10, 2024
1 parent 73df51e commit bcbdab9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion projects/novo-elements/src/elements/tooltip/Tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { Component } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
// App
import { TooltipDirective } from './Tooltip.directive';
import { By } from '@angular/platform-browser';

@Component({
selector: 'test-component',
template: `<div tooltip="test" tooltipPosition="right"></div>`,
template: `<div tooltip="test" tooltipPosition="right"></div>
<div tooltip="test" [tooltipCloseOnClick]="true" tooltipPosition="right"></div>`,
})
class TestComponent {}

describe('Elements: TooltipDirective', () => {
let fixture;
let component;
let tooltipHost;

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand All @@ -22,9 +25,31 @@ describe('Elements: TooltipDirective', () => {
}).compileComponents();
fixture = TestBed.createComponent(TestComponent);
component = fixture.debugElement.componentInstance;
tooltipHost = fixture.debugElement.queryAll(By.directive(TooltipDirective))
}));

it('should initialize with defaults', () => {
expect(component).toBeDefined();
});

describe('function: onclick', () => {
it('should not close tooltip on click', async() => {
tooltipHost[0].triggerEventHandler('mouseenter');
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('novo-tooltip'))).toBeTruthy();
tooltipHost[0].triggerEventHandler('click');
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('novo-tooltip'))).toBeTruthy();
});

it('should close tooltip on click', async() => {
tooltipHost[1].triggerEventHandler('mouseenter');
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('novo-tooltip'))).toBeTruthy();
tooltipHost[1].triggerEventHandler('click')
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('novo-tooltip'))).toBeFalsy();
});
});

});

0 comments on commit bcbdab9

Please sign in to comment.