@@ -275,6 +275,73 @@ describe('IgxMonthPicker', () => {
275
275
expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2021' ) ;
276
276
} ) ;
277
277
278
+ it ( 'should not emit onSelection when navigating to the next year' , ( ) => {
279
+ const fixture = TestBed . createComponent ( IgxMonthPickerSampleComponent ) ;
280
+ fixture . detectChanges ( ) ;
281
+
282
+ const dom = fixture . debugElement ;
283
+ const monthPicker = fixture . componentInstance . monthPicker ;
284
+ spyOn ( monthPicker . onSelection , 'emit' ) . and . callThrough ( ) ;
285
+
286
+ const next = dom . query ( By . css ( '.igx-calendar-picker__next' ) ) ;
287
+ let yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
288
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2019' ) ;
289
+
290
+ UIInteractions . simulateClickEvent ( next . nativeElement ) ;
291
+ fixture . detectChanges ( ) ;
292
+ UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , next . nativeElement ) ;
293
+ fixture . detectChanges ( ) ;
294
+
295
+ expect ( monthPicker . onSelection . emit ) . toHaveBeenCalledTimes ( 0 ) ;
296
+ yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
297
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2021' ) ;
298
+ } ) ;
299
+
300
+ it ( 'should not emit onSelection when navigating to the previous year' , ( ) => {
301
+ const fixture = TestBed . createComponent ( IgxMonthPickerSampleComponent ) ;
302
+ fixture . detectChanges ( ) ;
303
+
304
+ const dom = fixture . debugElement ;
305
+ const monthPicker = fixture . componentInstance . monthPicker ;
306
+ spyOn ( monthPicker . onSelection , 'emit' ) . and . callThrough ( ) ;
307
+
308
+ const prev = dom . query ( By . css ( '.igx-calendar-picker__prev' ) ) ;
309
+ let yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
310
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2019' ) ;
311
+
312
+ UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , prev . nativeElement ) ;
313
+ fixture . detectChanges ( ) ;
314
+ UIInteractions . simulateClickEvent ( prev . nativeElement ) ;
315
+ fixture . detectChanges ( ) ;
316
+
317
+ expect ( monthPicker . onSelection . emit ) . toHaveBeenCalledTimes ( 0 ) ;
318
+ yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
319
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2017' ) ;
320
+ } ) ;
321
+
322
+ it ( 'should not emit onSelection when changing the year' , ( ) => {
323
+ const fixture = TestBed . createComponent ( IgxMonthPickerSampleComponent ) ;
324
+ fixture . detectChanges ( ) ;
325
+
326
+ const dom = fixture . debugElement ;
327
+ const monthPicker = fixture . componentInstance . monthPicker ;
328
+ spyOn ( monthPicker . onSelection , 'emit' ) . and . callThrough ( ) ;
329
+
330
+ let yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
331
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2019' ) ;
332
+
333
+ UIInteractions . simulateClickEvent ( yearBtn . nativeElement ) ;
334
+ fixture . detectChanges ( ) ;
335
+
336
+ const year = dom . nativeElement . querySelector ( '.igx-calendar__year' ) ;
337
+ UIInteractions . simulateClickEvent ( year ) ;
338
+ fixture . detectChanges ( ) ;
339
+
340
+ expect ( monthPicker . onSelection . emit ) . toHaveBeenCalledTimes ( 0 ) ;
341
+ yearBtn = dom . query ( By . css ( '.igx-calendar-picker__date' ) ) ;
342
+ expect ( yearBtn . nativeElement . textContent . trim ( ) ) . toMatch ( '2016' ) ;
343
+ } ) ;
344
+
278
345
it ( 'should open years view, navigate through and select an year via KB.' , ( ) => {
279
346
const fixture = TestBed . createComponent ( IgxMonthPickerSampleComponent ) ;
280
347
fixture . detectChanges ( ) ;
0 commit comments