Skip to content

Commit 2da1679

Browse files
committed
test(datepicker): add unit tests for the date range input (#18874)
Sets up unit tests for the `mat-date-range-input` component.
1 parent 819f83f commit 2da1679

File tree

4 files changed

+498
-0
lines changed

4 files changed

+498
-0
lines changed

src/material/datepicker/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ ng_test_library(
8686
),
8787
deps = [
8888
":datepicker",
89+
"//src/cdk/a11y",
8990
"//src/cdk/bidi",
9091
"//src/cdk/keycodes",
9192
"//src/cdk/overlay",

src/material/datepicker/date-range-input-parts.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ export class MatStartDate<D> extends _MatDateRangeInputBase<D> implements CanUpd
198198
null : {'matStartDateInvalid': {'end': end, 'actual': start}};
199199
}
200200

201+
constructor(
202+
@Inject(MAT_DATE_RANGE_INPUT_PARENT) rangeInput: MatDateRangeInputParent<D>,
203+
elementRef: ElementRef<HTMLInputElement>,
204+
defaultErrorStateMatcher: ErrorStateMatcher,
205+
injector: Injector,
206+
@Optional() parentForm: NgForm,
207+
@Optional() parentFormGroup: FormGroupDirective,
208+
@Optional() dateAdapter: DateAdapter<D>,
209+
@Optional() @Inject(MAT_DATE_FORMATS) dateFormats: MatDateFormats) {
210+
211+
// TODO(crisbeto): this constructor shouldn't be necessary, but ViewEngine doesn't seem to
212+
// handle DI correctly when it is inherited from `MatDateRangeInputPartBase`. We can drop this
213+
// constructor once ViewEngine is removed.
214+
super(rangeInput, elementRef, defaultErrorStateMatcher, injector, parentForm, parentFormGroup,
215+
dateAdapter, dateFormats);
216+
}
217+
201218
protected _validator = Validators.compose([...super._getValidators(), this._startValidator]);
202219

203220
protected _getValueFromModel(modelValue: DateRange<D>) {
@@ -261,6 +278,23 @@ export class MatEndDate<D> extends _MatDateRangeInputBase<D> implements CanUpdat
261278
null : {'matEndDateInvalid': {'start': start, 'actual': end}};
262279
}
263280

281+
constructor(
282+
@Inject(MAT_DATE_RANGE_INPUT_PARENT) rangeInput: MatDateRangeInputParent<D>,
283+
elementRef: ElementRef<HTMLInputElement>,
284+
defaultErrorStateMatcher: ErrorStateMatcher,
285+
injector: Injector,
286+
@Optional() parentForm: NgForm,
287+
@Optional() parentFormGroup: FormGroupDirective,
288+
@Optional() dateAdapter: DateAdapter<D>,
289+
@Optional() @Inject(MAT_DATE_FORMATS) dateFormats: MatDateFormats) {
290+
291+
// TODO(crisbeto): this constructor shouldn't be necessary, but ViewEngine doesn't seem to
292+
// handle DI correctly when it is inherited from `MatDateRangeInputPartBase`. We can drop this
293+
// constructor once ViewEngine is removed.
294+
super(rangeInput, elementRef, defaultErrorStateMatcher, injector, parentForm, parentFormGroup,
295+
dateAdapter, dateFormats);
296+
}
297+
264298
protected _validator = Validators.compose([...super._getValidators(), this._endValidator]);
265299

266300
protected _getValueFromModel(modelValue: DateRange<D>) {

0 commit comments

Comments
 (0)