Skip to content

Commit 3c75b5d

Browse files
committed
test(date-editor): udpate tests #6271
1 parent e61d9c3 commit 3c75b5d

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.spec.ts

+41-41
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('IgxDateTimeEditor', () => {
2424
describe('Date portions spinning', () => {
2525
it('should correctly increment / decrement date portions with passed in DatePart', () => {
2626
elementRef = { nativeElement: { value: '12/10/2015' } };
27-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
27+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
2828
dateTimeEditor.inputFormat = 'dd/M/yy';
2929
dateTimeEditor.ngOnInit();
3030
dateTimeEditor.value = new Date('12/10/2015');
@@ -41,7 +41,7 @@ describe('IgxDateTimeEditor', () => {
4141

4242
it('should correctly increment / decrement date portions without passed in DatePart', () => {
4343
elementRef = { nativeElement: { value: '12/10/2015' } };
44-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
44+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
4545
dateTimeEditor.ngOnInit();
4646
dateTimeEditor.value = new Date('12/10/2015');
4747
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('12/10/2015');
@@ -56,7 +56,7 @@ describe('IgxDateTimeEditor', () => {
5656

5757
it('should not loop over to next month when incrementing date', () => {
5858
elementRef = { nativeElement: { value: '29/02/2020' } };
59-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
59+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
6060
dateTimeEditor.ngOnInit();
6161
dateTimeEditor.value = new Date(2020, 1, 29);
6262
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('29/01/2020');
@@ -68,7 +68,7 @@ describe('IgxDateTimeEditor', () => {
6868

6969
it('should not loop over to next year when incrementing month', () => {
7070
elementRef = { nativeElement: { value: '29/12/2020' } };
71-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
71+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
7272
dateTimeEditor.ngOnInit();
7373
dateTimeEditor.value = new Date(2020, 11, 29);
7474
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('29/11/2020');
@@ -80,7 +80,7 @@ describe('IgxDateTimeEditor', () => {
8080

8181
it('should update date part if next/previous month\'s max date is less than the current one\'s', () => {
8282
elementRef = { nativeElement: { value: '31/01/2020' } };
83-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
83+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
8484
dateTimeEditor.ngOnInit();
8585
dateTimeEditor.value = new Date(2020, 0, 31);
8686
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('31/01/2020');
@@ -92,7 +92,7 @@ describe('IgxDateTimeEditor', () => {
9292

9393
it('should prioritize Date for spinning, if it is set in format', () => {
9494
elementRef = { nativeElement: { value: '11/03/2020 00:00:00 AM' } };
95-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
95+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
9696
dateTimeEditor.inputFormat = 'dd/M/yy HH:mm:ss tt';
9797
dateTimeEditor.ngOnInit();
9898
dateTimeEditor.value = new Date(2020, 2, 11);
@@ -107,7 +107,7 @@ describe('IgxDateTimeEditor', () => {
107107

108108
it('should not loop over when isSpinLoop is false', () => {
109109
elementRef = { nativeElement: { value: '31/03/2020' } };
110-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
110+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
111111
dateTimeEditor.isSpinLoop = false;
112112
dateTimeEditor.ngOnInit();
113113
dateTimeEditor.value = new Date(2020, 2, 31);
@@ -123,7 +123,7 @@ describe('IgxDateTimeEditor', () => {
123123

124124
it('should loop over when isSpinLoop is true (default)', () => {
125125
elementRef = { nativeElement: { value: '31/03/2019' } };
126-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
126+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
127127
dateTimeEditor.ngOnInit();
128128
dateTimeEditor.value = new Date(2020, 2, 31);
129129
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('31/02/2019');
@@ -140,7 +140,7 @@ describe('IgxDateTimeEditor', () => {
140140
describe('Time portions spinning', () => {
141141
it('should correctly increment / decrement time portions with passed in DatePart', () => {
142142
elementRef = { nativeElement: { value: '10/10/2010 12:10:34' } };
143-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
143+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
144144
dateTimeEditor.ngOnInit();
145145
dateTimeEditor.value = new Date(2010, 11, 10, 12, 10, 34);
146146
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('10/11/2010 12:10:59');
@@ -156,7 +156,7 @@ describe('IgxDateTimeEditor', () => {
156156

157157
it('should correctly increment / decrement time portions without passed in DatePart', () => {
158158
elementRef = { nativeElement: { value: '' } };
159-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
159+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
160160
/*
161161
* format must be set because the editor will prioritize Date if Hours is not set
162162
* and no DatePart is provided to increment / decrement
@@ -176,7 +176,7 @@ describe('IgxDateTimeEditor', () => {
176176

177177
it('should not loop over to next minute when incrementing seconds', () => {
178178
elementRef = { nativeElement: { value: '20/01/2019 20:05:59' } };
179-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
179+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
180180
dateTimeEditor.ngOnInit();
181181
dateTimeEditor.value = new Date(2019, 1, 20, 20, 5, 59);
182182
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('20/01/2019 20:05:59');
@@ -188,7 +188,7 @@ describe('IgxDateTimeEditor', () => {
188188

189189
it('should not loop over to next hour when incrementing minutes', () => {
190190
elementRef = { nativeElement: { value: '20/01/2019 20:59:12' } };
191-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
191+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
192192
dateTimeEditor.ngOnInit();
193193
dateTimeEditor.value = new Date(2019, 1, 20, 20, 59, 12);
194194
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('20/1/2019 20:59:12');
@@ -200,7 +200,7 @@ describe('IgxDateTimeEditor', () => {
200200

201201
it('should not loop over to next day when incrementing hours', () => {
202202
elementRef = { nativeElement: { value: '20/01/2019 23:13:12' } };
203-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
203+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
204204
dateTimeEditor.ngOnInit();
205205
dateTimeEditor.value = new Date(2019, 1, 20, 23, 13, 12);
206206
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('20/1/2019 23:13:12');
@@ -212,7 +212,7 @@ describe('IgxDateTimeEditor', () => {
212212

213213
it('should not loop over when isSpinLoop is false', () => {
214214
elementRef = { nativeElement: { value: '20/02/2019 23:00:12' } };
215-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
215+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
216216
dateTimeEditor.isSpinLoop = false;
217217
dateTimeEditor.ngOnInit();
218218
dateTimeEditor.value = new Date(2019, 1, 20, 23, 0, 12);
@@ -227,7 +227,7 @@ describe('IgxDateTimeEditor', () => {
227227

228228
it('should loop over when isSpinLoop is true (default)', () => {
229229
elementRef = { nativeElement: { value: '20/02/2019 23:15:12' } };
230-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
230+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
231231
dateTimeEditor.ngOnInit();
232232
dateTimeEditor.value = new Date(2019, 1, 20, 23, 15, 0);
233233
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('20/1/2019 23:15:00');
@@ -240,24 +240,24 @@ describe('IgxDateTimeEditor', () => {
240240
});
241241
});
242242

243-
it('should emit valueChanged event on clear()', () => {
243+
it('should emit valueChange event on clear()', () => {
244244
elementRef = { nativeElement: { value: '' } };
245-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
245+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
246246
dateTimeEditor.ngOnInit();
247-
spyOn(dateTimeEditor.valueChanged, 'emit');
247+
spyOn(dateTimeEditor.valueChange, 'emit');
248248
const date = new Date(2000, 5, 6);
249249
dateTimeEditor.value = date;
250250
spyOnProperty((dateTimeEditor as any), 'inputValue', 'get').and.returnValue('6/5/2000');
251251

252252
dateTimeEditor.clear();
253253
expect(dateTimeEditor.value).toBeNull();
254-
expect(dateTimeEditor.valueChanged.emit).toHaveBeenCalledTimes(1);
255-
expect(dateTimeEditor.valueChanged.emit).toHaveBeenCalledWith({ oldValue: date, newValue: null });
254+
expect(dateTimeEditor.valueChange.emit).toHaveBeenCalledTimes(1);
255+
expect(dateTimeEditor.valueChange.emit).toHaveBeenCalledWith({ oldValue: date, newValue: null });
256256
});
257257

258258
it('should update mask according to the input format', () => {
259259
elementRef = { nativeElement: { value: '' } };
260-
dateTimeEditor = new IgxDateTimeEditorDirective(elementRef, maskParsingService, renderer2, DOCUMENT);
260+
dateTimeEditor = new IgxDateTimeEditorDirective(renderer2, elementRef, maskParsingService, DOCUMENT, LOCALE_ID);
261261
dateTimeEditor.inputFormat = 'd/M/yy';
262262
dateTimeEditor.ngOnInit();
263263

@@ -340,19 +340,19 @@ describe('Integration tests', () => {
340340
UIInteractions.simulateTyping('8', inputElement, 7, 7);
341341
expect(inputElement.nativeElement.value).toEqual('19/12/08');
342342
});
343-
it('should emit valueChanged event on blur', () => {
343+
it('should emit valueChange event on blur', () => {
344344
const newDate = new Date(2004, 11, 18);
345345
fixture.componentInstance.dateTimeFormat = 'dd/MM/yy';
346346
fixture.detectChanges();
347-
spyOn(dateTimeEditorDirective.valueChanged, 'emit');
347+
spyOn(dateTimeEditorDirective.valueChange, 'emit');
348348
inputElement.triggerEventHandler('focus', {});
349349
fixture.detectChanges();
350350
UIInteractions.simulateTyping('18124', inputElement);
351351
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
352352
fixture.detectChanges();
353353
expect(inputElement.nativeElement.value).toEqual('18/12/04');
354-
expect(dateTimeEditorDirective.valueChanged.emit).toHaveBeenCalledTimes(1);
355-
expect(dateTimeEditorDirective.valueChanged.emit).toHaveBeenCalledWith({ oldValue: undefined, newValue: newDate });
354+
expect(dateTimeEditorDirective.valueChange.emit).toHaveBeenCalledTimes(1);
355+
expect(dateTimeEditorDirective.valueChange.emit).toHaveBeenCalledWith({ oldValue: undefined, newValue: newDate });
356356
});
357357
it('should not accept invalid date.', () => {
358358
fixture.componentInstance.dateTimeFormat = 'dd/MM/yy';
@@ -740,12 +740,12 @@ describe('Integration tests', () => {
740740
fixture.detectChanges();
741741
expect(inputElement.nativeElement.value).toEqual('../../.... ..:..:..');
742742
});
743-
it('should fire validationFailed when input date is outside date range.', () => {
743+
it('should fire validationFail when input date is outside date range.', () => {
744744
fixture.componentInstance.dateTimeFormat = 'dd-MM-yyyy';
745745
fixture.componentInstance.minDate = new Date(2020, 1, 20);
746746
fixture.componentInstance.maxDate = new Date(2020, 1, 25);
747747
fixture.detectChanges();
748-
spyOn(dateTimeEditorDirective.validationFailed, 'emit');
748+
spyOn(dateTimeEditorDirective.validationFail, 'emit');
749749

750750
// date within the range
751751
let inputDate = '22-02-2020';
@@ -755,7 +755,7 @@ describe('Integration tests', () => {
755755
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
756756
fixture.detectChanges();
757757
expect(inputElement.nativeElement.value).toEqual(inputDate);
758-
expect(dateTimeEditorDirective.validationFailed.emit).not.toHaveBeenCalled();
758+
expect(dateTimeEditorDirective.validationFail.emit).not.toHaveBeenCalled();
759759

760760
// date > maxValue
761761
let oldDate = new Date(2020, 1, 22);
@@ -768,8 +768,8 @@ describe('Integration tests', () => {
768768
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
769769
fixture.detectChanges();
770770
expect(inputElement.nativeElement.value).toEqual(inputDate);
771-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledTimes(1);
772-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledWith(args);
771+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledTimes(1);
772+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledWith(args);
773773

774774
// date < minValue
775775
oldDate = newDate;
@@ -782,13 +782,13 @@ describe('Integration tests', () => {
782782
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
783783
fixture.detectChanges();
784784
expect(inputElement.nativeElement.value).toEqual(inputDate);
785-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledTimes(2);
786-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledWith(args);
785+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledTimes(2);
786+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledWith(args);
787787
});
788-
it('should fire validationFailed when input date is invalid.', () => {
788+
it('should fire validationFail when input date is invalid.', () => {
789789
fixture.componentInstance.dateTimeFormat = 'dd-MM-yyyy';
790790
fixture.detectChanges();
791-
spyOn(dateTimeEditorDirective.validationFailed, 'emit').and.callThrough();
791+
spyOn(dateTimeEditorDirective.validationFail, 'emit').and.callThrough();
792792

793793
// valid date
794794
let inputDate = '22-02-2020';
@@ -798,7 +798,7 @@ describe('Integration tests', () => {
798798
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
799799
fixture.detectChanges();
800800
expect(inputElement.nativeElement.value).toEqual(inputDate);
801-
expect(dateTimeEditorDirective.validationFailed.emit).not.toHaveBeenCalled();
801+
expect(dateTimeEditorDirective.validationFail.emit).not.toHaveBeenCalled();
802802

803803
// invalid date
804804
const oldDate = new Date(2020, 1, 22);
@@ -811,8 +811,8 @@ describe('Integration tests', () => {
811811
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
812812
fixture.detectChanges();
813813
expect(inputElement.nativeElement.value).toEqual('__-__-____');
814-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledTimes(1);
815-
// expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledWith(args);
814+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledTimes(1);
815+
// expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledWith(args);
816816
});
817817
});
818818

@@ -840,7 +840,7 @@ describe('Integration tests', () => {
840840
});
841841
it('should validate properly when used as form control.', () => {
842842
const form: FormGroup = fixture.componentInstance.reactiveForm;
843-
spyOn(dateTimeEditorDirective.validationFailed, 'emit');
843+
spyOn(dateTimeEditorDirective.validationFail, 'emit');
844844

845845
let inputDate = '21-03-2020';
846846
inputElement.triggerEventHandler('focus', {});
@@ -850,7 +850,7 @@ describe('Integration tests', () => {
850850
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
851851
fixture.detectChanges();
852852
expect(inputElement.nativeElement.value).toEqual(inputDate);
853-
expect(dateTimeEditorDirective.validationFailed.emit).not.toHaveBeenCalled();
853+
expect(dateTimeEditorDirective.validationFail.emit).not.toHaveBeenCalled();
854854
expect(form.valid).toBeTruthy();
855855

856856
const args = { oldValue: new Date(2020, 2, 21), newValue: new Date(2020, 1, 21) };
@@ -862,8 +862,8 @@ describe('Integration tests', () => {
862862
inputElement.triggerEventHandler('blur', { target: inputElement.nativeElement });
863863
fixture.detectChanges();
864864
expect(inputElement.nativeElement.value).toEqual(inputDate);
865-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledTimes(1);
866-
expect(dateTimeEditorDirective.validationFailed.emit).toHaveBeenCalledWith(args);
865+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledTimes(1);
866+
expect(dateTimeEditorDirective.validationFail.emit).toHaveBeenCalledWith(args);
867867
expect(form.valid).toBeFalsy();
868868
});
869869
});

projects/igniteui-angular/src/lib/test-utils/ui-interactions.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export class UIInteractions {
5757
altKey: altKey,
5858
shiftKey: shift,
5959
ctrlKey: ctrl,
60-
target: elem.nativeElement,
6160
stopPropagation: () => { },
6261
stopImmediatePropagation: () => { },
6362
preventDefault: () => { }

0 commit comments

Comments
 (0)