Skip to content

Commit 9cbe283

Browse files
Samir Hassan Ayoubrafaellygruber
authored andcommitted
fix(datepicker): corrige disparo do p-change
O evento p-change só emitia valor quando saísse do campo (blur). Foi redefinido para que dispare ao selecionar nova data. Fixes DTHFUI-904
1 parent fc8e742 commit 9cbe283

File tree

3 files changed

+4
-52
lines changed

3 files changed

+4
-52
lines changed

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
[readonly]="readonly"
1616
[required]="required"
1717
(blur)="eventOnBlur($event)"
18-
(change)="eventOnChange($event)"
1918
(click)="eventOnClick($event)">
2019

2120
<div class="po-field-icon-container-right">

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.spec.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,6 @@ describe('PoDatepickerComponent:', () => {
412412
expect(component.callOnChange).toHaveBeenCalled();
413413
});
414414

415-
it('should emit onchange when it is not mobile', () => {
416-
const input = fixture.debugElement.nativeElement.querySelector('input');
417-
input.value = '01/01/2000';
418-
419-
spyOn(component.onchange, 'emit');
420-
421-
component.eventOnChange({});
422-
423-
expect(component.onchange.emit).toHaveBeenCalled();
424-
});
425-
426415
it('simulate click out behavior the datepicker field read-only', () => {
427416
component.dialogPicker = undefined;
428417
fixture.detectChanges();
@@ -436,18 +425,6 @@ describe('PoDatepickerComponent:', () => {
436425

437426
// Testes de mobile
438427

439-
it('should emit onchange when it is mobile', () => {
440-
spyOn(component, 'verifyMobile').and.returnValue(['Android']);
441-
442-
spyOn(component, 'callOnChange');
443-
spyOn(component, 'controlModel');
444-
445-
component.eventOnChange({});
446-
447-
expect(component.callOnChange).toHaveBeenCalled();
448-
expect(component.controlModel).toHaveBeenCalled();
449-
});
450-
451428
it('should call eventOnClick when have mobile', () => {
452429
spyOn(component, 'verifyMobile').and.returnValue(['Android']);
453430

@@ -745,13 +722,15 @@ describe('PoDatepickerComponent:', () => {
745722
expect(component['closeCalendar']).toHaveBeenCalled();
746723
});
747724

748-
it('dateSelected: should call `controlModel`', () => {
725+
it('dateSelected: should call `controlModel` and `controlChangeEmitter`', () => {
749726

750727
spyOn(component, 'controlModel');
728+
spyOn(component, <any>'controlChangeEmitter');
751729

752730
component.dateSelected();
753731

754732
expect(component.controlModel).toHaveBeenCalled();
733+
expect(component['controlChangeEmitter']).toHaveBeenCalled();
755734
});
756735

757736
it('formatToDate: should call `formatYear` with date year', () => {
@@ -970,24 +949,6 @@ describe('PoDatepickerComponent:', () => {
970949
expect(fakeThis.onchange.emit).not.toHaveBeenCalled();
971950
});
972951

973-
it('eventOnChange: should emit value', () => {
974-
const value = '30/08/2018' ;
975-
const fakeThis = {
976-
verifyMobile: () => false,
977-
inputEl: {
978-
nativeElement: {
979-
value: value
980-
}
981-
},
982-
onchange: { emit: () => {} }
983-
};
984-
985-
spyOn(fakeThis.onchange, 'emit');
986-
component['eventOnChange'].call(fakeThis);
987-
988-
expect(fakeThis.onchange.emit).toHaveBeenCalledWith(value);
989-
});
990-
991952
it('isValidDateIso: should return `true` if value format is `yyyy-mm-dd`.', () => {
992953
const expectedValue = true;
993954
const isoDate = '2018-09-29';

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class PoDatepickerComponent extends PoDatepickerBaseComponent implements
124124
this.inputEl.nativeElement.focus();
125125
this.inputEl.nativeElement.value = this.formatToDate(this.date);
126126
this.controlModel(this.date);
127+
this.controlChangeEmitter();
127128
this.closeCalendar();
128129
}
129130

@@ -212,15 +213,6 @@ export class PoDatepickerComponent extends PoDatepickerBaseComponent implements
212213

213214
}
214215

215-
eventOnChange($event) {
216-
const elementValue = this.inputEl.nativeElement.value;
217-
if (this.verifyMobile()) {
218-
this.controlModel(elementValue);
219-
this.callOnChange(elementValue);
220-
}
221-
this.onchange.emit(elementValue);
222-
}
223-
224216
eventOnClick($event) {
225217
if (this.verifyMobile()) {
226218
$event.target.blur();

0 commit comments

Comments
 (0)