@@ -9,7 +9,8 @@ import { CalendarService } from 'app/core/calendar/shared/service/calendar.servi
99import { CalendarEvent , CalendarEventType } from 'app/core/calendar/shared/entities/calendar-event.model' ;
1010import { CalendarDesktopMonthPresentationComponent } from './calendar-desktop-month-presentation.component' ;
1111import { CalendarDayBadgeComponent } from 'app/core/calendar/shared/calendar-day-badge/calendar-day-badge.component' ;
12- import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover/calendar-event-detail-popover.component' ;
12+ import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover-component/calendar-event-detail-popover.component' ;
13+ import { provideNoopAnimations } from '@angular/platform-browser/animations' ;
1314
1415describe ( 'CalendarDesktopMonthPresentationComponent' , ( ) => {
1516 let fixture : ComponentFixture < CalendarDesktopMonthPresentationComponent > ;
@@ -61,6 +62,7 @@ describe('CalendarDesktopMonthPresentationComponent', () => {
6162 provide : CalendarService ,
6263 useFactory : ( ) => new MockCalendarService ( mockMap ) ,
6364 } ,
65+ provideNoopAnimations ( ) ,
6466 ] ,
6567 } ) . compileComponents ( ) ;
6668
@@ -105,66 +107,47 @@ describe('CalendarDesktopMonthPresentationComponent', () => {
105107 expect ( lecture3EventCell ) . toBeFalsy ( ) ;
106108 } ) ;
107109
108- it ( 'should open popover' , ( ) => {
109- const eventCell = fixture . debugElement . query ( By . css ( '[data-testid="Exam"]' ) ) ;
110- expect ( eventCell ) . toBeTruthy ( ) ;
110+ it ( 'should open popover' , async ( ) => {
111+ const popoverDebugElement = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
112+ const popoverComponent = popoverDebugElement . componentInstance as CalendarEventDetailPopoverComponent ;
111113
114+ const eventCell = fixture . debugElement . query ( By . css ( '[data-testid="Exam"]' ) ) ;
112115 eventCell . nativeElement . click ( ) ;
113116 fixture . detectChanges ( ) ;
117+ await fixture . whenStable ( ) ;
114118
115- expect ( component . selectedEvent ( ) ?. id ) . toBe ( events [ 0 ] . id ) ;
116-
117- const popoverContent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
118- expect ( popoverContent ) . toBeTruthy ( ) ;
119+ expect ( popoverComponent . isOpen ( ) ) . toBeTrue ( ) ;
119120 } ) ;
120121
121- it ( 'should close popover only when close button used' , ( ) => {
122+ it ( 'should close popover only when close button used' , async ( ) => {
123+ const popoverDebugElement = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
124+ const popoverComponent = popoverDebugElement . componentInstance as CalendarEventDetailPopoverComponent ;
125+ const closeSpy = jest . spyOn ( popoverComponent , 'close' ) ;
126+
122127 const examEventCell = fixture . debugElement . query ( By . css ( '[data-testid="Exam"]' ) ) ;
123128 expect ( examEventCell ) . toBeTruthy ( ) ;
124-
125129 examEventCell . nativeElement . click ( ) ;
126130 fixture . detectChanges ( ) ;
127-
128- let popoverComponent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
129- expect ( component . selectedEvent ( ) ?. id ) . toBe ( events [ 0 ] . id ) ;
130- expect ( popoverComponent ) . toBeTruthy ( ) ;
131+ await fixture . whenStable ( ) ;
132+ expect ( popoverComponent . isOpen ( ) ) . toBeTrue ( ) ;
131133
132134 const emptyDayCell = fixture . debugElement . queryAll ( By . css ( '.day-cell' ) ) . find ( ( cell ) => cell . queryAll ( By . css ( '.event-cell' ) ) . length === 0 ) ;
133135 expect ( emptyDayCell ) . toBeTruthy ( ) ;
134-
135136 emptyDayCell ! . nativeElement . click ( ) ;
136137 fixture . detectChanges ( ) ;
138+ await fixture . whenStable ( ) ;
139+ expect ( popoverComponent . isOpen ( ) ) . toBeFalse ( ) ;
137140
138- expect ( component . selectedEvent ( ) ?. id ) . toBe ( events [ 0 ] . id ) ;
139- popoverComponent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
140- expect ( popoverComponent ) . toBeTruthy ( ) ;
141-
142- const closeButton = popoverComponent . query ( By . css ( '.close-button' ) ) ;
143- expect ( closeButton ) . toBeTruthy ( ) ;
144-
145- closeButton . nativeElement . click ( ) ;
146- fixture . detectChanges ( ) ;
147-
148- expect ( component . selectedEvent ( ) ) . toBeUndefined ( ) ;
149- popoverComponent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
150- expect ( popoverComponent ) . toBeFalsy ( ) ;
151- } ) ;
152-
153- it ( 'should replace popover when other event selected' , ( ) => {
154- const firstEventCell = fixture . debugElement . query ( By . css ( '[data-testid="Exam"]' ) ) ;
155- firstEventCell . nativeElement . click ( ) ;
141+ examEventCell . nativeElement . click ( ) ;
156142 fixture . detectChanges ( ) ;
143+ await fixture . whenStable ( ) ;
144+ expect ( popoverComponent . isOpen ( ) ) . toBeTrue ( ) ;
157145
158- let popoverComponent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
159- expect ( component . selectedEvent ( ) ?. id ) . toBe ( events [ 0 ] . id ) ;
160- expect ( popoverComponent ) . toBeTruthy ( ) ;
161-
162- const secondEventCell = fixture . debugElement . query ( By . css ( '[data-testid="Object Design"]' ) ) ;
163- secondEventCell . nativeElement . click ( ) ;
146+ const closeButton = document . querySelector ( '.close-button' ) as HTMLElement ;
147+ expect ( closeButton ) . toBeTruthy ( ) ;
148+ closeButton . click ( ) ;
164149 fixture . detectChanges ( ) ;
165-
166- popoverComponent = fixture . debugElement . query ( By . directive ( CalendarEventDetailPopoverComponent ) ) ;
167- expect ( popoverComponent ) . toBeTruthy ( ) ;
168- expect ( component . selectedEvent ( ) ?. id ) . toBe ( events [ 1 ] . id ) ;
150+ await fixture . whenStable ( ) ;
151+ expect ( closeSpy ) . toHaveBeenCalledOnce ( ) ;
169152 } ) ;
170153} ) ;
0 commit comments