diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.html b/src/app/modules/shared/components/details-fields/details-fields.component.html index c1114e007..48388e267 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.html +++ b/src/app/modules/shared/components/details-fields/details-fields.component.html @@ -91,6 +91,8 @@ [class.is-invalid]="start_date.invalid && start_date.touched" required (ngModelChange)="onStartDateChange($event)" + [max]="getCurrentDate()" + onkeydown="return false" /> @@ -118,6 +120,8 @@ aria-describedby="inputGroup-sizing-sm" [class.is-invalid]="end_date.invalid && end_date.touched" required + [max]="getCurrentDate()" + onkeydown="return false" /> diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts index a29ed6e06..39cb76bdc 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts @@ -468,6 +468,31 @@ describe('DetailsFieldsComponent', () => { expect(endDateInput.value).not.toEqual(startDateInput.value); expect(startDateInput.value).toEqual(expectedStartDate); }); + + it('on get current date should return expected date', () => { + const expectedDate = new Date().toISOString().split('T')[0]; + + expect(component.getCurrentDate()).toEqual(expectedDate); + }); + + it('on the input with id #start_date we could get the id and max value', () => { + fixture.detectChanges(); + const expectedDate = new Date().toISOString().split('T')[0]; + const startDateInput: HTMLInputElement = fixture.debugElement. + nativeElement.querySelector(`input[id="start_date"],input[max="${component.getCurrentDate()}"]`); + + expect(startDateInput.id).toEqual('start_date'); + expect(startDateInput.max).toEqual(expectedDate); + }); + + it('on the input with id #end_date we could get the current Date ', () => { + fixture.detectChanges(); + const expectedDate = new Date().toISOString().split('T')[0]; + const endDateInput = fixture.debugElement.nativeElement.querySelector('[id=end_date]'); + + expect(endDateInput.id).toEqual('end_date'); + expect(endDateInput.max).toEqual(expectedDate); + }); /* TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component, and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here: diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index be8c13d9a..9bc9e4815 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -171,6 +171,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { this.selectedTechnologies = $event; } + getCurrentDate(): string { + return new Date().toISOString().split('T')[0]; + } + get project_id() { return this.entryForm.get('project_id'); }