Skip to content

Commit 4864f34

Browse files
committed
fix: TT-282 added conditions in method onSubmit and added array of activities in component project-list-hover
1 parent cf6e893 commit 4864f34

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
formControlName="activity_id"
88
[class.is-invalid]="activity_id.invalid && activity_id.touched"
99
required>
10+
<option value="" selected="selected"></option>
1011
<option *ngFor="let activity of activities" value="{{ activity.id }}">{{ activity.name }}</option>
1112
</select>
1213
</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,12 @@ describe('EntryFieldsComponent', () => {
323323
});
324324

325325
it('dispatches an action when onSubmit is called', () => {
326+
const isMemberOf = spyOn(component, 'entryFormIsValidate').and.returnValue(true);
326327
spyOn(store, 'dispatch');
327328

328329
component.onSubmit();
329330

331+
expect(isMemberOf).toHaveBeenCalled();
330332
expect(store.dispatch).toHaveBeenCalled();
331333
});
332334

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { AzureAdB2CService } from './../../../login/services/azure.ad.b2c.service';
21
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
32
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
43
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry, UpdateEntryRunning } from './../../store/entry.actions';
5-
import { filter, map } from 'rxjs/operators';
4+
import { filter} from 'rxjs/operators';
65
import { Component, OnDestroy, OnInit } from '@angular/core';
76
import { FormBuilder, FormGroup } from '@angular/forms';
87
import { Store, ActionsSubject, select } from '@ngrx/store';
@@ -17,8 +16,7 @@ import { ToastrService } from 'ngx-toastr';
1716
import { formatDate } from '@angular/common';
1817
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
1918
import { DATE_FORMAT } from 'src/environments/environment';
20-
import { Subscription, Observable } from 'rxjs';
21-
import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
19+
import { Subscription, } from 'rxjs';
2220
import { FeatureToggle } from './../../../../../environments/enum';
2321
import { CookieService } from 'ngx-cookie-service';
2422

@@ -42,7 +40,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
4240
actionSetDateSubscription: Subscription;
4341
isCookieFeatureToggleActive: boolean;
4442
isFeatureToggleActive: boolean;
45-
4643
constructor(
4744
private formBuilder: FormBuilder,
4845
private store: Store<Merged>,
@@ -81,7 +78,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
8178
this.isFeatureToggleActive = flag;
8279
});
8380
}
84-
8581
this.loadActiveEntrySubscription = this.actionsSubject$
8682
.pipe(
8783
filter(
@@ -143,7 +139,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
143139
}
144140

145141
onSubmit() {
146-
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
142+
if (this.entryFormIsValidate()){
143+
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
144+
}
147145
}
148146

149147
onUpdateStartHour() {

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ describe('ProjectListHoverComponent', () => {
3939
isLoading: false,
4040
message: '',
4141
},
42-
};
4342

43+
};
4444
beforeEach(
4545
waitForAsync(() => {
4646
TestBed.configureTestingModule({
@@ -69,6 +69,12 @@ describe('ProjectListHoverComponent', () => {
6969

7070
it('dispatchs a CreateEntry action on clockIn', () => {
7171
component.activeEntry = null;
72+
const activitiesMock = [{
73+
id: 'xyz',
74+
name: 'test',
75+
description : 'test1'
76+
}];
77+
component.activities = activitiesMock;
7278
spyOn(store, 'dispatch');
7379

7480
component.clockIn(1, 'customer', 'project');

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
} from './../../../customer-management/components/projects/components/store/project.selectors';
1515
import { EntryActionTypes } from './../../store/entry.actions';
1616
import { getActiveTimeEntry } from './../../store/entry.selectors';
17+
import { Activity, } from '../../../shared/models';
18+
import { LoadActivities } from './../../../activities-management/store/activity-management.actions';
19+
import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors';
20+
1721
@Component({
1822
selector: 'app-project-list-hover',
1923
templateUrl: './project-list-hover.component.html',
@@ -22,13 +26,15 @@ import { getActiveTimeEntry } from './../../store/entry.selectors';
2226
export class ProjectListHoverComponent implements OnInit, OnDestroy {
2327
keyword = 'search_field';
2428
listProjects: Project[] = [];
29+
activities: Activity[] = [];
2530
activeEntry;
2631
projectsForm: FormGroup;
2732
showClockIn: boolean;
2833
updateEntrySubscription: Subscription;
2934
isLoading$: Observable<boolean>;
3035
projectsSubscription: Subscription;
3136
activeEntrySubscription: Subscription;
37+
loadActivitiesSubscription: Subscription;
3238

3339
constructor(
3440
private formBuilder: FormBuilder,
@@ -52,6 +58,11 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
5258
});
5359
this.loadActiveTimeEntry();
5460
});
61+
this.store.dispatch(new LoadActivities());
62+
const activities$ = this.store.pipe(select(allActivities));
63+
activities$.subscribe((response) => {
64+
this.activities = response;
65+
});
5566
this.updateEntrySubscription = this.actionsSubject$
5667
.pipe(filter((action: any) => action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS))
5768
.subscribe((action) => {
@@ -88,6 +99,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
8899
start_date: new Date().toISOString(),
89100
timezone_offset: new Date().getTimezoneOffset(),
90101
technologies: [],
102+
activity_id: this.activities[0].id,
91103
};
92104
this.store.dispatch(new entryActions.ClockIn(entry));
93105
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });

0 commit comments

Comments
 (0)