|
| 1 | +import {FormsModule} from '@angular/forms'; |
1 | 2 | import {DatePickerComponent} from './date-picker.component';
|
| 3 | +import {DayTimeCalendarComponent} from '../day-time-calendar/day-time-calendar.component'; |
| 4 | +import {DayTimeCalendarService} from '../day-time-calendar/day-time-calendar.service'; |
| 5 | +import {DomHelper} from '../common/services/dom-appender/dom-appender.service'; |
| 6 | +import {CalendarMode} from '../common/types/calendar-mode'; |
| 7 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 8 | +import {DayCalendarComponent} from '../day-calendar/day-calendar.component'; |
| 9 | +import {TimeSelectComponent} from '../time-select/time-select.component'; |
| 10 | +import {CalendarNavComponent} from '../calendar-nav/calendar-nav.component'; |
| 11 | +import {MonthCalendarComponent} from '../month-calendar/month-calendar.component'; |
| 12 | +import {DayCalendarService} from '../day-calendar/day-calendar.service'; |
| 13 | +import {TimeSelectService} from '../time-select/time-select.service'; |
| 14 | +import {UtilsService} from '../common/services/utils/utils.service'; |
2 | 15 |
|
3 |
| -describe('Component: DpDayPicker', () => { |
4 |
| - const component = new DatePickerComponent(null, null, null, null, null, null); |
| 16 | +describe('Component: DatePickerComponent', () => { |
| 17 | + let component: DatePickerComponent; |
| 18 | + let fixture: ComponentFixture<DatePickerComponent>; |
5 | 19 |
|
6 |
| - it('should create an instance', () => { |
| 20 | + const setComponentMode = function(mode: CalendarMode) { |
| 21 | + component.mode = mode; |
| 22 | + component.init(); |
| 23 | + fixture.detectChanges(); |
| 24 | + }; |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + TestBed.configureTestingModule({ |
| 28 | + imports: [ FormsModule ], |
| 29 | + declarations: [ |
| 30 | + DatePickerComponent, |
| 31 | + DayTimeCalendarComponent, |
| 32 | + DayCalendarComponent, |
| 33 | + TimeSelectComponent, |
| 34 | + CalendarNavComponent, |
| 35 | + MonthCalendarComponent |
| 36 | + ], |
| 37 | + providers: [ |
| 38 | + DayTimeCalendarService, |
| 39 | + DayCalendarService, |
| 40 | + TimeSelectService, |
| 41 | + UtilsService, |
| 42 | + DomHelper |
| 43 | + ] |
| 44 | + }).compileComponents(); |
| 45 | + }); |
| 46 | + |
| 47 | + beforeEach(() => { |
| 48 | + fixture = TestBed.createComponent(DatePickerComponent); |
| 49 | + component = fixture.componentInstance; |
| 50 | + fixture.detectChanges(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should create', () => { |
7 | 54 | expect(component).toBeTruthy();
|
8 | 55 | });
|
| 56 | + |
| 57 | + it('should emit event goToCurrent when day calendar emit', () => { |
| 58 | + setComponentMode('day'); |
| 59 | + |
| 60 | + spyOn(component.onGoToCurrent, 'emit'); |
| 61 | + component.dayCalendarRef.onGoToCurrent.emit(); |
| 62 | + expect(component.onGoToCurrent.emit).toHaveBeenCalledWith(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should emit event goToCurrent when month calendar emit', () => { |
| 66 | + setComponentMode('month'); |
| 67 | + |
| 68 | + spyOn(component.onGoToCurrent, 'emit'); |
| 69 | + component.monthCalendarRef.onGoToCurrent.emit(); |
| 70 | + expect(component.onGoToCurrent.emit).toHaveBeenCalledWith(); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should emit event goToCurrent when daytime calendar emit', () => { |
| 74 | + setComponentMode('daytime'); |
| 75 | + |
| 76 | + spyOn(component.onGoToCurrent, 'emit'); |
| 77 | + component.dayTimeCalendarRef.onGoToCurrent.emit(); |
| 78 | + expect(component.onGoToCurrent.emit).toHaveBeenCalledWith(); |
| 79 | + }); |
9 | 80 | });
|
0 commit comments