|
1 | 1 | import { Component, ViewChild } from '@angular/core'; |
2 | | -import { TestBed } from '@angular/core/testing'; |
| 2 | +import { TestBed, fakeAsync, tick, flush } from '@angular/core/testing'; |
3 | 3 | import { FormsModule } from '@angular/forms'; |
4 | 4 | import { By } from '@angular/platform-browser'; |
5 | 5 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
@@ -259,21 +259,35 @@ describe('IgxMonthPicker', () => { |
259 | 259 |
|
260 | 260 | expect(monthPicker.viewDate.getFullYear()).toEqual(2021); |
261 | 261 | expect(yearBtn.nativeElement.textContent.trim()).toMatch('2021'); |
| 262 | + }); |
262 | 263 |
|
| 264 | + it('should navigate to the previous/next year via arrowLeft and arrowRight', fakeAsync(() => { |
| 265 | + const fixture = TestBed.createComponent(IgxMonthPickerSampleComponent); |
| 266 | + fixture.detectChanges(); |
| 267 | + tick(); |
| 268 | + flush(); |
| 269 | + |
| 270 | + const monthPicker = fixture.componentInstance.monthPicker; |
| 271 | + const yearBtn = fixture.debugElement.query(By.css('.igx-calendar-picker__date')); |
| 272 | + |
| 273 | + expect(yearBtn.nativeElement.textContent.trim()).toMatch('2019'); |
263 | 274 | yearBtn.nativeElement.focus(); |
264 | 275 |
|
265 | | - UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', yearBtn.nativeElement); |
| 276 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', yearBtn.nativeElement); |
266 | 277 | fixture.detectChanges(); |
| 278 | + tick(50); |
| 279 | + flush(); |
267 | 280 |
|
268 | | - expect(monthPicker.viewDate.getFullYear()).toEqual(2022); |
269 | | - expect(yearBtn.nativeElement.textContent.trim()).toMatch('2022'); |
| 281 | + expect(monthPicker.viewDate.getFullYear()).toEqual(2018); |
| 282 | + expect(yearBtn.nativeElement.textContent.trim()).toMatch('2018'); |
270 | 283 |
|
271 | | - UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', yearBtn.nativeElement); |
| 284 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', yearBtn.nativeElement); |
272 | 285 | fixture.detectChanges(); |
| 286 | + flush(); |
273 | 287 |
|
274 | | - expect(monthPicker.viewDate.getFullYear()).toEqual(2021); |
275 | | - expect(yearBtn.nativeElement.textContent.trim()).toMatch('2021'); |
276 | | - }); |
| 288 | + expect(monthPicker.viewDate.getFullYear()).toEqual(2019); |
| 289 | + expect(yearBtn.nativeElement.textContent.trim()).toMatch('2019'); |
| 290 | + })); |
277 | 291 |
|
278 | 292 | it('should not emit onSelection when navigating to the next year', () => { |
279 | 293 | const fixture = TestBed.createComponent(IgxMonthPickerSampleComponent); |
|
0 commit comments