Skip to content

Commit d2dc909

Browse files
test(date-range): update test components #5732
1 parent 84e9366 commit d2dc909

File tree

1 file changed

+81
-74
lines changed

1 file changed

+81
-74
lines changed

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

+81-74
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,33 @@
11
import { IgxDateRangeComponent } from './igx-date-range.component';
22
import { ComponentFixture, async, TestBed } from '@angular/core/testing';
3-
import { Component, OnInit, Optional } from '@angular/core';
3+
import { Component, OnInit, ViewChild, wtfStartTimeRange, NgModule } from '@angular/core';
44
import { IgxInputGroupModule } from '../input-group/index';
5-
import {
6-
IgxDateRangeModule, IgxDateRangeStartDirective, IgxDateRangeEndDirective,
7-
IgxDateRangeDirective, IgxDateRangeBaseDirective
8-
} from './index';
95
import { InteractionMode } from '../core/enums';
10-
11-
describe('IgxDateRangeComponent', () => {
12-
let component: IgxDateRangeComponent;
13-
let fixture: ComponentFixture<IgxDateRangeComponent>;
6+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
7+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
8+
import { IgxIconModule } from '../icon';
9+
import { IgxCalendarModule } from '../calendar/index';
10+
import { IgxButtonModule } from '../directives/button/button.directive';
11+
import { IgxDateRangeModule } from './igx-date-range.module';
12+
import { noop } from 'rxjs';
13+
14+
// tslint:disable: no-use-before-declare
15+
describe('IgxDateRange', () => {
16+
let singleInputRange: DateRangeTwoInputsTestComponent;
17+
let twoInputsRange: DateRangeTwoInputsTestComponent;
18+
let fixture: ComponentFixture<DateRangeTestComponent>;
1419

1520
beforeEach(async(() => {
1621
TestBed.configureTestingModule({
17-
declarations: [
18-
IgxDateRangeComponent,
19-
IgxDateRangeBaseDirective,
20-
IgxDateRangeStartDirective,
21-
IgxDateRangeEndDirective,
22-
IgxDateRangeDirective
23-
],
24-
imports: [
25-
IgxInputGroupModule,
26-
IgxDateRangeModule
27-
]
28-
})
29-
.compileComponents();
22+
imports: [DateRangeTestingModule]
23+
}).compileComponents();
3024
}));
3125

32-
beforeEach(() => {
33-
fixture = TestBed.createComponent(IgxDateRangeComponent);
34-
component = fixture.componentInstance;
35-
fixture.detectChanges();
36-
});
37-
38-
describe('IgxDateRange - Focus', () => {
26+
describe('Focus', () => {
3927
it('Should move focus to the calendar on open', () => {
4028
// TODO
4129
});
4230

43-
it('Should not change focus when the calendar is closed', () => {
44-
// TODO
45-
});
46-
4731
it('Should move the focus to start input when "Today" is clicked and there isn\'t a value in start input', () => {
4832
// TODO
4933
});
@@ -57,7 +41,7 @@ describe('IgxDateRangeComponent', () => {
5741
});
5842
});
5943

60-
describe('IgxDateRange - API', () => {
44+
describe('API', () => {
6145
it('Should select today properly', () => {
6246
// TODO
6347
});
@@ -82,7 +66,7 @@ describe('IgxDateRangeComponent', () => {
8266
});
8367
});
8468

85-
describe('IgxDateRange - Keyboard Navigation', () => {
69+
describe('Keyboard Navigation', () => {
8670
it('Should open the calendar on mouse click', () => {
8771
// TODO
8872
});
@@ -100,7 +84,7 @@ describe('IgxDateRangeComponent', () => {
10084
});
10185
});
10286

103-
describe('IgxDateRange - Two Inputs', () => {
87+
describe('Two Inputs', () => {
10488
it('Should update the start input on first date selection', () => {
10589
// TODO
10690
});
@@ -126,7 +110,7 @@ describe('IgxDateRangeComponent', () => {
126110
});
127111
});
128112

129-
describe('IgxDateRange - Single Input', () => {
113+
describe('Single Input', () => {
130114
/* The single input's text looks like this -> START_DATE - END_DATE */
131115

132116
it('Should set the first part of the input properly on first date selection', () => {
@@ -153,6 +137,24 @@ describe('IgxDateRangeComponent', () => {
153137
});
154138
});
155139

140+
@Component({
141+
selector: 'igx-date-range-test',
142+
template: ''
143+
})
144+
export class DateRangeTestComponent implements OnInit {
145+
public todayButtonText: string;
146+
public doneButtonText: string;
147+
public mode: InteractionMode;
148+
149+
@ViewChild(IgxDateRangeComponent, { read: IgxDateRangeComponent, static: true })
150+
public dateRange: IgxDateRangeComponent;
151+
152+
public ngOnInit(): void {
153+
this.todayButtonText = 'Today';
154+
this.doneButtonText = 'Done';
155+
}
156+
}
157+
156158
@Component({
157159
selector: 'igx-date-range-single-input-test',
158160
template: `
@@ -164,34 +166,24 @@ describe('IgxDateRangeComponent', () => {
164166
</igx-prefix>
165167
</igx-input-group>
166168
<igx-date-range [todayButtonText]="todayButtonText" [doneButtonText]="doneButtonText" [mode]="mode">
167-
<igx-input-group>
168-
<input #startDate igxDateRangeStart igxInput type="text">
169-
<label for="startDate" igxLabel>Check-in Date</label>
170-
<igx-prefix>
171-
<igx-icon>today</igx-icon>
172-
</igx-prefix>
173-
</igx-input-group>
174-
<igx-input-group>
175-
<input #endDate igxDateRangeEnd igxInput type="text">
176-
<label for="endDate" igxLabel>Check-out Date</label>
177-
<igx-prefix>
178-
<igx-icon>today</igx-icon>
179-
</igx-prefix>
180-
</igx-input-group>
181-
</igx-date-range>
169+
<igx-input-group>
170+
<input #startDate igxDateRangeStart igxInput type="text">
171+
<label for="startDate" igxLabel>Check-in Date</label>
172+
<igx-prefix>
173+
<igx-icon>today</igx-icon>
174+
</igx-prefix>
175+
</igx-input-group>
176+
<igx-input-group>
177+
<input #endDate igxDateRangeEnd igxInput type="text">
178+
<label for="endDate" igxLabel>Check-out Date</label>
179+
<igx-prefix>
180+
<igx-icon>today</igx-icon>
181+
</igx-prefix>
182+
</igx-input-group>
183+
</igx-date-range>
182184
`
183185
})
184-
export class DateRangeSingleInputTestComponent implements OnInit {
185-
public todayButtonText: string;
186-
public doneButtonText: string;
187-
188-
constructor(public mode?: InteractionMode) { }
189-
190-
public ngOnInit(): void {
191-
this.todayButtonText = 'Today';
192-
this.doneButtonText = 'Done';
193-
}
194-
}
186+
export class DateRangeTwoInputsTestComponent extends DateRangeTestComponent { }
195187

196188
@Component({
197189
selector: 'igx-date-range-two-inputs-test',
@@ -214,14 +206,29 @@ export class DateRangeSingleInputTestComponent implements OnInit {
214206
</igx-date-range>
215207
`
216208
})
217-
export class DateRangeTwoInputsTestComponent implements OnInit {
218-
public todayButtonText: string;
219-
public doneButtonText: string;
220-
221-
constructor(public mode?: InteractionMode) { }
222-
223-
public ngOnInit(): void {
224-
this.todayButtonText = 'Today';
225-
this.doneButtonText = 'Done';
226-
}
227-
}
209+
export class DateRangeSingleInputTestComponent extends DateRangeTestComponent { }
210+
211+
@NgModule({
212+
declarations: [
213+
DateRangeSingleInputTestComponent,
214+
DateRangeTwoInputsTestComponent,
215+
DateRangeTestComponent
216+
],
217+
imports: [
218+
IgxDateRangeModule,
219+
NoopAnimationsModule,
220+
IgxInputGroupModule,
221+
ReactiveFormsModule,
222+
IgxIconModule,
223+
IgxCalendarModule,
224+
IgxButtonModule,
225+
IgxInputGroupModule,
226+
FormsModule
227+
],
228+
exports: [
229+
DateRangeSingleInputTestComponent,
230+
DateRangeTwoInputsTestComponent,
231+
DateRangeTestComponent
232+
]
233+
})
234+
export class DateRangeTestingModule { }

0 commit comments

Comments
 (0)