Skip to content

Commit e8ee50f

Browse files
feat: TT-208 show active activities in entry & details fields
1 parent f0275f8 commit e8ee50f

File tree

7 files changed

+122
-107
lines changed

7 files changed

+122
-107
lines changed

src/app/modules/activities-management/store/activity-management.reducers.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ describe('activityManagementReducer', () => {
127127
const currentState: ActivityState = { data: [activity], isLoading: false, message: '', activityIdToEdit: '1' };
128128
const activityEdited: Status = { id: '1', status: 'active' };
129129
const expectedActivity: Activity = { id: '1', name: 'Training', description: 'It is good for learning', status: 'active' };
130-
131130
const action = new actions.UnarchiveActivitySuccess(activityEdited);
132-
133131
const state = activityManagementReducer(currentState, action);
134-
console.log(state.data);
135132

136133
expect(state.data).toEqual([expectedActivity]);
137134
expect(state.isLoading).toBeFalse();

src/app/modules/activities-management/store/activity-management.selectors.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,30 @@ describe('ActivityManagement Selectors', () => {
1010

1111
it('returns the activity with id that matches from the list', () => {
1212
const activityId = 'id';
13-
const activities = [{id: 'id', name: 'abc', description: 'xxx'},
14-
{id: '2', name: 'xyz', description: 'yyy'}];
13+
const activities = [{ id: 'id', name: 'abc', description: 'xxx' },
14+
{ id: '2', name: 'xyz', description: 'yyy' }];
1515
const activityFound = selectors.getActivityById.projector(activities, activityId);
1616
expect(activityFound).toEqual(activities[0]);
1717
});
1818

1919
it('should return all the data in the state when the selector allActivities is called', () => {
20-
const activities = [{id: 'id', name: 'abc', description: 'xxx'},
21-
{id: '2', name: 'xyz', description: 'yyy'}];
22-
const activityState = {data: activities};
20+
const activities = [{ id: 'id', name: 'abc', description: 'xxx' },
21+
{ id: '2', name: 'xyz', description: 'yyy' }];
22+
const activityState = { data: activities };
2323

2424
expect(selectors.allActivities.projector(activityState)).toBe(activities);
2525
});
2626

27+
fit('should return all active data in the state when the selector allActiveActivities is called', () => {
28+
const activities = [{ id: 'id', name: 'abc', description: 'xxx', status: 'active' },
29+
{ id: '2', name: 'xyz', description: 'yyy', status: 'inactive' },
30+
{ id: '3', name: 'xyzw', description: 'www', status: 'active' }];
31+
const activityState = { data: activities };
32+
const filteredActivities = activities.filter((item) => item.status === 'active');
33+
34+
expect(selectors.allActiveActivities.projector(activityState)).toEqual(filteredActivities);
35+
});
36+
2737
it('should select isLoading when the selector getIsLoading is called', () => {
2838
const isLoadingValue = true;
2939
const activityState = { isLoading: isLoadingValue };

src/app/modules/activities-management/store/activity-management.selectors.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ const getActivityState = createFeatureSelector<ActivityState>('activities');
55

66
export const allActivities = createSelector(getActivityState, (state: ActivityState) => state?.data);
77

8+
export const allActiveActivities = createSelector(getActivityState, (state: ActivityState) => {
9+
return state?.data.filter((item) => item.status !== 'inactive');
10+
});
11+
812
export const activityIdToEdit = createSelector(getActivityState, (state: ActivityState) => state?.activityIdToEdit);
913

1014
export const getActivityById = createSelector(allActivities, activityIdToEdit, (activities, activityId) => {
1115
if (activities && activityId) {
12-
return activities.find((activity) => {
13-
return activity.id === activityId;
14-
});
16+
return activities.find((activity) => activity.id === activityId);
1517
}
1618
});
1719

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('DetailsFieldsComponent', () => {
5353
isLoading: false,
5454
},
5555
activities: {
56-
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'abc' }],
56+
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'abc', status: 'active' }],
5757
isLoading: false,
5858
message: 'Data fetch successfully!',
5959
activityIdToEdit: '',
@@ -138,9 +138,9 @@ describe('DetailsFieldsComponent', () => {
138138
it('onSelectedProject project id and name are set using event data', () => {
139139
spyOn(component.entryForm, 'patchValue');
140140

141-
component.onSelectedProject( {id: 'id', search_field: 'foo'} );
141+
component.onSelectedProject({ id: 'id', search_field: 'foo' });
142142

143-
expect(component.entryForm.patchValue).toHaveBeenCalledWith( { project_id: 'id', project_name: 'foo', } );
143+
expect(component.entryForm.patchValue).toHaveBeenCalledWith({ project_id: 'id', project_name: 'foo', });
144144
});
145145

146146
it('if form is invalid then saveEntry is not emited', () => {
@@ -296,7 +296,7 @@ describe('DetailsFieldsComponent', () => {
296296

297297
component.onGoingToWorkOnThisChange({ currentTarget: { checked: false } });
298298

299-
expect(component.entryForm.patchValue).toHaveBeenCalledWith( { end_date: '2020-12-30', end_hour: '09:45', } );
299+
expect(component.entryForm.patchValue).toHaveBeenCalledWith({ end_date: '2020-12-30', end_hour: '09:45', });
300300
});
301301

302302
it('when creating a new entry, then the new entry should be marked as not run', () => {
@@ -367,7 +367,7 @@ describe('DetailsFieldsComponent', () => {
367367
const startHour = moment().subtract(3, 'hours').format('HH:mm:ss');
368368
const expectedStartDate = new Date(`${currentDate}T${startHour.trim()}`);
369369

370-
component.entryToEdit = {...entryToEdit, start_date: expectedStartDate };
370+
component.entryToEdit = { ...entryToEdit, start_date: expectedStartDate };
371371
fixture.componentInstance.ngOnChanges();
372372

373373
component.entryForm.patchValue({ description: 'test' });
@@ -378,23 +378,23 @@ describe('DetailsFieldsComponent', () => {
378378
it('should modify the start_date when start_hour has been modified', () => {
379379
const startDate = new Date(mockCurrentDate);
380380

381-
component.entryToEdit = {...entryToEdit, start_date: startDate };
381+
component.entryToEdit = { ...entryToEdit, start_date: startDate };
382382
fixture.componentInstance.ngOnChanges();
383383

384384
const updatedStartDate = moment(startDate).subtract(1, 'hours');
385-
const updatedStartHour = updatedStartDate.format('HH:mm');
386-
component.entryForm.patchValue({start_hour: updatedStartHour});
385+
const updatedStartHour = updatedStartDate.format('HH:mm');
386+
component.entryForm.patchValue({ start_hour: updatedStartHour });
387387

388388
const expectedStartDate = moment(updatedStartDate).seconds(0).millisecond(0).toISOString();
389389
expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate);
390-
});
390+
});
391391

392392
it('should not modify the end_date when end_hour has not been modified', () => {
393393
const currentDate = moment().format('YYYY-MM-DD');
394394
const endHour = moment().subtract(3, 'hours').format('HH:mm:ss');
395395
const expectedEndDate = new Date(`${currentDate}T${endHour.trim()}`);
396396

397-
component.entryToEdit = {...entryToEdit, end_date: expectedEndDate };
397+
component.entryToEdit = { ...entryToEdit, end_date: expectedEndDate };
398398
fixture.componentInstance.ngOnChanges();
399399

400400
component.entryForm.patchValue({ description: 'test' });
@@ -405,16 +405,16 @@ describe('DetailsFieldsComponent', () => {
405405
it('should modify the end_date when end_hour has been modified', () => {
406406
const endDate = new Date(mockCurrentDate);
407407

408-
component.entryToEdit = {...entryToEdit, end_date: endDate };
408+
component.entryToEdit = { ...entryToEdit, end_date: endDate };
409409
fixture.componentInstance.ngOnChanges();
410410

411411
const updatedEndDate = moment(endDate).subtract(1, 'hours');
412-
const updatedEndHour = updatedEndDate.format('HH:mm');
413-
component.entryForm.patchValue({end_hour: updatedEndHour});
412+
const updatedEndHour = updatedEndDate.format('HH:mm');
413+
component.entryForm.patchValue({ end_hour: updatedEndHour });
414414

415415
const expectedEndDate = moment(updatedEndDate).seconds(0).millisecond(0).toISOString();
416416
expect(component.dateToSubmit('end_date', 'end_hour')).toEqual(expectedEndDate);
417-
});
417+
});
418418

419419
it('displays error message when the date selected is in the future', () => {
420420
spyOn(toastrServiceStub, 'error');
@@ -451,8 +451,8 @@ describe('DetailsFieldsComponent', () => {
451451
it('should emit projectSelected event', () => {
452452
spyOn(component.projectSelected, 'emit');
453453
const item = {
454-
id : 'id',
455-
search_field : 'TimeTracker'
454+
id: 'id',
455+
search_field: 'TimeTracker'
456456
};
457457
component.onSelectedProject(item);
458458

@@ -495,13 +495,13 @@ describe('DetailsFieldsComponent', () => {
495495
});
496496

497497
it('on the input with id #start_date we could get the id and max value', () => {
498-
fixture.detectChanges();
499-
const expectedDate = new Date().toISOString().split('T')[0];
500-
const startDateInput: HTMLInputElement = fixture.debugElement.
501-
nativeElement.querySelector(`input[id="start_date"],input[max="${component.getCurrentDate()}"]`);
498+
fixture.detectChanges();
499+
const expectedDate = new Date().toISOString().split('T')[0];
500+
const startDateInput: HTMLInputElement = fixture.debugElement.
501+
nativeElement.querySelector(`input[id="start_date"],input[max="${component.getCurrentDate()}"]`);
502502

503-
expect(startDateInput.id).toEqual('start_date');
504-
expect(startDateInput.max).toEqual(expectedDate);
503+
expect(startDateInput.id).toEqual('start_date');
504+
expect(startDateInput.max).toEqual(expectedDate);
505505
});
506506

507507
it('on the input with id #end_date we could get the current Date ', () => {

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as moment from 'moment';
66
import { ToastrService } from 'ngx-toastr';
77
import { filter } from 'rxjs/operators';
88
import { getCreateError, getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors';
9-
import { ActivityState, allActivities, LoadActivities } from '../../../activities-management/store';
9+
import { ActivityState, allActiveActivities, LoadActivities } from '../../../activities-management/store';
1010
import * as projectActions from '../../../customer-management/components/projects/components/store/project.actions';
1111
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
1212
import { getProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
@@ -78,7 +78,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
7878
});
7979

8080
this.store.dispatch(new LoadActivities());
81-
const activities$ = this.store.pipe(select(allActivities));
81+
const activities$ = this.store.pipe(select(allActiveActivities));
8282
activities$.subscribe((response) => {
8383
this.activities = response;
8484
});
@@ -149,7 +149,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
149149
technology: '',
150150
});
151151
} else {
152-
this.cleanForm();
152+
this.cleanForm();
153153
}
154154
}
155155

@@ -263,8 +263,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
263263
this.saveEntry.emit({ entry, shouldRestartEntry: this.shouldRestartEntry });
264264
}
265265

266-
onclickFormAction(isProjectSelected: boolean){
267-
if (isProjectSelected){
266+
onclickFormAction(isProjectSelected: boolean) {
267+
if (isProjectSelected) {
268268
this.toastrService.warning('Please, first select a project');
269269
}
270270
}

0 commit comments

Comments
 (0)