Skip to content

Commit 4870b87

Browse files
committed
test(IgxMonthPicker): verify that selection isn't emitted when change year #7456
1 parent 68577aa commit 4870b87

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

projects/igniteui-angular/src/lib/calendar/month-picker/month-picker.component.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,73 @@ describe('IgxMonthPicker', () => {
275275
expect(yearBtn.nativeElement.textContent.trim()).toMatch('2021');
276276
});
277277

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+
278345
it('should open years view, navigate through and select an year via KB.', () => {
279346
const fixture = TestBed.createComponent(IgxMonthPickerSampleComponent);
280347
fixture.detectChanges();

0 commit comments

Comments
 (0)