Skip to content

Commit 9a39eae

Browse files
authored
test(time-picker, date-picker): add time and date picker tests (#9425)
1 parent 2054b92 commit 9a39eae

File tree

3 files changed

+294
-33
lines changed

3 files changed

+294
-33
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentFixture, fakeAsync, flush, TestBed, tick, waitForAsync } from '@angular/core/testing';
1+
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
22
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { UIInteractions } from '../test-utils/ui-interactions.spec';
@@ -132,10 +132,6 @@ describe('IgxDatePicker', () => {
132132
calendar = fixture.componentInstance.datePicker.calendar;
133133
}));
134134

135-
afterAll(() => {
136-
TestBed.resetTestingModule();
137-
});
138-
139135
it('should toggle the calendar with ALT + DOWN/UP ARROW key', fakeAsync(() => {
140136
spyOn(datePicker.opening, 'emit').and.callThrough();
141137
spyOn(datePicker.opened, 'emit').and.callThrough();
@@ -155,12 +151,27 @@ describe('IgxDatePicker', () => {
155151

156152
calendar = document.getElementsByClassName(CSS_CLASS_CALENDAR)[0];
157153
UIInteractions.triggerKeyDownEvtUponElem('ArrowUp', calendar, true, true);
158-
tick();
154+
tick(350);
159155
fixture.detectChanges();
160156
expect(datePicker.collapsed).toBeTruthy();
161157
expect(datePicker.closing.emit).toHaveBeenCalledTimes(1);
162158
expect(datePicker.closed.emit).toHaveBeenCalledTimes(1);
163-
flush();
159+
}));
160+
161+
it('should open the calendar with SPACE key', fakeAsync(() => {
162+
spyOn(datePicker.opening, 'emit').and.callThrough();
163+
spyOn(datePicker.opened, 'emit').and.callThrough();
164+
expect(datePicker.collapsed).toBeTruthy();
165+
166+
const picker = fixture.debugElement.query(By.css(CSS_CLASS_DATE_PICKER));
167+
UIInteractions.triggerEventHandlerKeyDown(' ', picker);
168+
169+
tick(350);
170+
fixture.detectChanges();
171+
172+
expect(datePicker.collapsed).toBeFalsy();
173+
expect(datePicker.opening.emit).toHaveBeenCalledTimes(1);
174+
expect(datePicker.opened.emit).toHaveBeenCalledTimes(1);
164175
}));
165176

166177
it('should close the calendar with ESC', fakeAsync(() => {
@@ -175,12 +186,11 @@ describe('IgxDatePicker', () => {
175186

176187
calendar = document.getElementsByClassName(CSS_CLASS_CALENDAR)[0];
177188
UIInteractions.triggerKeyDownEvtUponElem('Escape', calendar, true);
178-
tick();
189+
tick(350);
179190
fixture.detectChanges();
180191
expect(datePicker.collapsed).toBeTruthy();
181192
expect(datePicker.closing.emit).toHaveBeenCalledTimes(1);
182193
expect(datePicker.closed.emit).toHaveBeenCalledTimes(1);
183-
flush();
184194
}));
185195
});
186196

0 commit comments

Comments
 (0)