|
3 | 3 | ComponentFixture,
|
4 | 4 | TestBed,
|
5 | 5 | fakeAsync,
|
6 |
| - flush |
| 6 | + flush, |
| 7 | + tick |
7 | 8 | } from '@angular/core/testing';
|
8 | 9 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
9 | 10 | import moment from 'moment';
|
@@ -541,6 +542,47 @@ describe('calendarMonthView component', () => {
|
541 | 542 | expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false);
|
542 | 543 | }));
|
543 | 544 |
|
| 545 | + it('should show a tooltip on mouseover of the event after a delay', fakeAsync(() => { |
| 546 | + const fixture: ComponentFixture< |
| 547 | + CalendarMonthViewComponent |
| 548 | + > = TestBed.createComponent(CalendarMonthViewComponent); |
| 549 | + eventTitle.monthTooltip = (e: CalendarEvent) => { |
| 550 | + return `title: ${e.title}`; |
| 551 | + }; |
| 552 | + fixture.componentInstance.viewDate = new Date('2016-06-27'); |
| 553 | + fixture.componentInstance.events = [ |
| 554 | + { |
| 555 | + start: new Date('2016-05-30'), |
| 556 | + end: new Date('2016-06-02'), |
| 557 | + title: 'foo <b>bar</b>' |
| 558 | + } |
| 559 | + ]; |
| 560 | + fixture.componentInstance.tooltipDelay = 2000; |
| 561 | + fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} }); |
| 562 | + fixture.detectChanges(); |
| 563 | + const event: HTMLElement = fixture.nativeElement.querySelector( |
| 564 | + '.cal-days .cal-cell-row .cal-cell:nth-child(4) .cal-events .cal-event' |
| 565 | + ); |
| 566 | + triggerDomEvent('mouseenter', event); |
| 567 | + fixture.detectChanges(); |
| 568 | + tick(fixture.componentInstance.tooltipDelay - 1); |
| 569 | + expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false); |
| 570 | + tick(1); |
| 571 | + expect(!!document.body.querySelector('.cal-tooltip')).to.equal(true); |
| 572 | + const tooltip: HTMLElement = document.body.querySelector( |
| 573 | + '.cal-tooltip' |
| 574 | + ) as HTMLElement; |
| 575 | + expect(tooltip.querySelector('.cal-tooltip-inner').innerHTML).to.equal( |
| 576 | + 'title: foo <b>bar</b>' |
| 577 | + ); |
| 578 | + expect(tooltip.classList.contains('cal-tooltip-top')).to.equal(true); |
| 579 | + expect(!!tooltip.style.top).to.equal(true); |
| 580 | + expect(!!tooltip.style.left).to.equal(true); |
| 581 | + triggerDomEvent('mouseleave', event); |
| 582 | + fixture.detectChanges(); |
| 583 | + expect(!!document.body.querySelector('.cal-tooltip')).to.equal(false); |
| 584 | + })); |
| 585 | + |
544 | 586 | it('should disable the tooltip', fakeAsync(() => {
|
545 | 587 | const fixture: ComponentFixture<
|
546 | 588 | CalendarMonthViewComponent
|
|
0 commit comments