Skip to content

Commit c3701ff

Browse files
committed
fix: TT-25 Empty selection in Activity drop-down(Time Clock page)
1 parent f239ab1 commit c3701ff

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(change)="onSubmit()"
66
class="form-control"
77
formControlName="activity_id"
8-
[class.is-invalid]="activity_id.invalid && activity_id.touched"
8+
[class.is-invalid]="activity_id.invalid && activity_id.touched || activity_id.value == '-1'"
99
required>
1010
<option value="-1"></option>
1111
<option *ngFor="let activity of activities" value="{{ activity.id }}">{{ activity.name }}</option>

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { DATE_FORMAT_YEAR } from 'src/environments/environment';
1818
import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
1919
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
2020
import { FeatureToggle } from 'src/environments/enum';
21+
import { By } from '@angular/platform-browser';
2122

2223

2324
describe('EntryFieldsComponent', () => {
@@ -466,6 +467,15 @@ describe('EntryFieldsComponent', () => {
466467
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
467468
});
468469
});
470+
471+
it('toastrService should be called when the activity field is empty', () => {
472+
fixture.detectChanges();
473+
const select: HTMLSelectElement = fixture.debugElement.query(By.css('select')).nativeElement;
474+
spyOn(toastrServiceStub, 'error');
475+
select.value = select.options[0].value;
476+
select.dispatchEvent(new Event('change'));
477+
expect(toastrServiceStub.error).toHaveBeenCalled();
478+
});
469479
});
470480

471481

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
133133
}
134134

135135
onSubmit() {
136+
if (this.entryForm.value.activity_id === '-1') {
137+
this.toastrService.error('Please enter a valid activity');
138+
return;
139+
}
136140
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
137141
}
138142

0 commit comments

Comments
 (0)