Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
217fbb8
feat: TT-208 add new column in activity-list
thegreatyamori Apr 19, 2021
6c1c06f
feat: TT-208 add switch status button in column
thegreatyamori Apr 19, 2021
dc10fcf
feat: TT-208 remove delete button & assign openmodal to switch
thegreatyamori Apr 20, 2021
fb37b3b
feat: TT-208 connect switch btn with ngrx flux
thegreatyamori Apr 20, 2021
f0275f8
feat: TT-208 update ngrx delete flux
thegreatyamori Apr 20, 2021
e8ee50f
feat: TT-208 show active activities in entry & details fields
thegreatyamori Apr 21, 2021
a62c980
feat: TT-208 change ui-switch to button
thegreatyamori Apr 22, 2021
5c19c86
fix: TT-208 display the required activities when clicking on time en…
thegreatyamori Apr 26, 2021
a76051c
Merge branch 'master' into TT-208-don't-allow-deleting-activities
thegreatyamori Apr 26, 2021
aa698ee
feat: TT-208 add new column in activity-list
thegreatyamori Apr 26, 2021
5ca9a8f
feat: TT-208 add switch status button in column
thegreatyamori Apr 26, 2021
17d5acd
feat: TT-208 remove delete button & assign openmodal to switch
thegreatyamori Apr 26, 2021
90742ad
feat: TT-208 connect switch btn with ngrx flux
thegreatyamori Apr 26, 2021
4977dff
feat: TT-208 update ngrx delete flux
thegreatyamori Apr 26, 2021
1d0107d
feat: TT-208 show active activities in entry & details fields
thegreatyamori Apr 21, 2021
5808250
feat: TT-208 change ui-switch to button
thegreatyamori Apr 22, 2021
286033c
fix: TT-208 display the required activities when clicking on time en…
thegreatyamori Apr 26, 2021
3a5e107
feat: TT-208 rebase on latest master commit
thegreatyamori Apr 26, 2021
1c9ee96
fix: TT-208 merging conflicts
thegreatyamori Apr 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: TT-208 update ngrx delete flux
  • Loading branch information
thegreatyamori committed Apr 26, 2021
commit 4977dff37924ce335dab54fdedc1b44c9693f3d0
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { allActivities } from './../../store/activity-management.selectors';
import { ActivityState } from './../../store/activity-management.reducers';
import { DeleteActivity, SetActivityToEdit } from './../../store/activity-management.actions';
import { ArchiveActivity, SetActivityToEdit } from './../../store/activity-management.actions';
import { ActivityListComponent } from './activity-list.component';

fdescribe('ActivityListComponent', () => {
Expand Down Expand Up @@ -53,7 +53,7 @@ fdescribe('ActivityListComponent', () => {
component.idToDelete = 'id';
component.deleteActivity();

expect(store.dispatch).toHaveBeenCalledWith(new DeleteActivity('id'));
expect(store.dispatch).toHaveBeenCalledWith(new ArchiveActivity('id'));
});

it('updateActivity, dispatchs SetActivityToEdit action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { delay } from 'rxjs/operators';
import { getIsLoading } from 'src/app/modules/activities-management/store/activity-management.selectors';
import { Activity } from '../../../shared/models';
import { allActivities } from '../../store';
import { DeleteActivity, LoadActivities, SetActivityToEdit, UnarchiveActivity } from './../../store/activity-management.actions';
import { ArchiveActivity, LoadActivities, SetActivityToEdit, UnarchiveActivity } from './../../store/activity-management.actions';
import { ActivityState } from './../../store/activity-management.reducers';

@Component({
Expand Down Expand Up @@ -34,7 +34,7 @@ export class ActivityListComponent implements OnInit {
}

deleteActivity() {
this.store.dispatch(new DeleteActivity(this.idToDelete));
this.store.dispatch(new ArchiveActivity(this.idToDelete));
this.showModal = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ describe('LoadActivitiesSuccess', () => {
expect(createActivityFail.type).toEqual(actions.ActivityManagementActionTypes.CREATE_ACTIVITY_FAIL);
});

fit('ArchiveActivity type is ActivityManagementActionTypes.ARCHIVE_ACTIVITY', () => {
const archiveActivity = new actions.ArchiveActivity('id_test');
expect(archiveActivity.type).toEqual(actions.ActivityManagementActionTypes.ARCHIVE_ACTIVITY);
});

fit('ArchiveActivitySuccess type is ActivityManagementActionTypes.ARCHIVE_ACTIVITY_SUCCESS', () => {
const archiveActivitySuccess = new actions.ArchiveActivitySuccess({
id: 'id_test',
status: 'inactive'
});
expect(archiveActivitySuccess.type).toEqual(actions.ActivityManagementActionTypes.ARCHIVE_ACTIVITY_SUCCESS);
});

fit('ArchiveActivityFail type is ActivityManagementActionTypes.ARCHIVE_ACTIVITY_FAIL', () => {
const archiveActivityFail = new actions.ArchiveActivityFail('error');
expect(archiveActivityFail.type).toEqual(actions.ActivityManagementActionTypes.ARCHIVE_ACTIVITY_FAIL);
});

it('UpdateActivitySuccess type is ActivityManagementActionTypes.UPDATE_ACTIVITY_SUCCESS', () => {
const updateActivitySuccess = new actions.UpdateActivitySuccess({
id: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export enum ActivityManagementActionTypes {
CREATE_ACTIVITY = '[ActivityManagement] CREATE_ACTIVITY',
CREATE_ACTIVITY_SUCCESS = '[ActivityManagement] CREATE_ACTIVITY_SUCCESS',
CREATE_ACTIVITY_FAIL = '[ActivityManagement] CREATE_ACTIVITY_FAIL',
DELETE_ACTIVITY = '[ActivityManagement] DELETE_ACTIVITY',
DELETE_ACTIVITY_SUCCESS = '[ActivityManagement] DELETE_ACTIVITY_SUCESS',
DELETE_ACTIVITY_FAIL = '[ActivityManagement] DELETE_ACTIVITY_FAIL',
ARCHIVE_ACTIVITY = '[ActivityManagement] ARCHIVE_ACTIVITY',
ARCHIVE_ACTIVITY_SUCCESS = '[ActivityManagement] ARCHIVE_ACTIVITY_SUCCESS',
ARCHIVE_ACTIVITY_FAIL = '[ActivityManagement] ARCHIVE_ACTIVITY_FAIL',
UPDATE_ACTIVITY = '[ActivityManagement] UPDATE_ACTIVITY',
UPDATE_ACTIVITY_SUCCESS = '[ActivityManagement] UPDATE_ACTIVITY_SUCCESS',
UPDATE_ACTIVITY_FAIL = '[ActivityManagement] UPDATE_ACTIVITY_FAIL',
Expand Down Expand Up @@ -56,23 +56,24 @@ export class CreateActivityFail implements Action {
constructor(public error: string) { }
}

export class DeleteActivity implements Action {
public readonly type = ActivityManagementActionTypes.DELETE_ACTIVITY;
export class ArchiveActivity implements Action {
public readonly type = ActivityManagementActionTypes.ARCHIVE_ACTIVITY;

constructor(public activityId: string) { }
}

export class DeleteActivitySuccess implements Action {
public readonly type = ActivityManagementActionTypes.DELETE_ACTIVITY_SUCCESS;
export class ArchiveActivitySuccess implements Action {
public readonly type = ActivityManagementActionTypes.ARCHIVE_ACTIVITY_SUCCESS;

constructor(public activityId: string) { }
constructor(public payload: Status) { }
}

export class DeleteActivityFail implements Action {
public readonly type = ActivityManagementActionTypes.DELETE_ACTIVITY_FAIL;
export class ArchiveActivityFail implements Action {
public readonly type = ActivityManagementActionTypes.ARCHIVE_ACTIVITY_FAIL;

constructor(public error: string) { }
}

export class UpdateActivity implements Action {
public readonly type = ActivityManagementActionTypes.UPDATE_ACTIVITY;

Expand Down Expand Up @@ -124,9 +125,9 @@ export type ActivityManagementActions =
| CreateActivity
| CreateActivitySuccess
| CreateActivityFail
| DeleteActivity
| DeleteActivitySuccess
| DeleteActivityFail
| ArchiveActivity
| ArchiveActivitySuccess
| ArchiveActivityFail
| UpdateActivity
| UpdateActivitySuccess
| UpdateActivityFail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe('ActivityEffects', () => {
});

fit('action type is UNARCHIVE_ACTIVITY_SUCCESS when service is executed sucessfully', async () => {
actions$ = of({ type: ActivityManagementActionTypes.UNARCHIVE_ACTIVITY, activity });
const activityId = 'activityId';
actions$ = of({ type: ActivityManagementActionTypes.UNARCHIVE_ACTIVITY, activityId });
spyOn(service, 'updateActivity').and.returnValue(of(activity));
spyOn(toastrService, 'success');

Expand Down Expand Up @@ -121,27 +122,27 @@ describe('ActivityEffects', () => {
});
});

it('action type is DELETE_ACTIVITY_SUCCESS when service is executed sucessfully', async () => {
fit('action type is ARCHIVE_ACTIVITY_SUCCESS when service is executed sucessfully', async () => {
const activityId = 'activityId';
actions$ = of({ type: ActivityManagementActionTypes.DELETE_ACTIVITY, activityId });
actions$ = of({ type: ActivityManagementActionTypes.ARCHIVE_ACTIVITY, activityId });
spyOn(service, 'deleteActivity').and.returnValue(of({}));
spyOn(toastrService, 'success');

effects.deleteActivity$.subscribe((action) => {
effects.archiveActivity$.subscribe((action) => {
expect(toastrService.success).toHaveBeenCalledWith(INFO_DELETE_SUCCESSFULLY);
expect(action.type).toEqual(ActivityManagementActionTypes.DELETE_ACTIVITY_SUCCESS);
expect(action.type).toEqual(ActivityManagementActionTypes.ARCHIVE_ACTIVITY_SUCCESS);
});
});

it('action type is DELETE_ACTIVITY_FAIL when service fail in execution', async () => {
it('action type is ARCHIVE_ACTIVITY_FAIL when service fail in execution', async () => {
const activityId = 'activityId';
actions$ = of({ type: ActivityManagementActionTypes.DELETE_ACTIVITY, activityId });
actions$ = of({ type: ActivityManagementActionTypes.ARCHIVE_ACTIVITY, activityId });
spyOn(service, 'deleteActivity').and.returnValue(throwError({ error: { message: 'fail!' } }));
spyOn(toastrService, 'error');

effects.deleteActivity$.subscribe((action) => {
effects.archiveActivity$.subscribe((action) => {
expect(toastrService.error).toHaveBeenCalled();
expect(action.type).toEqual(ActivityManagementActionTypes.DELETE_ACTIVITY_FAIL);
expect(action.type).toEqual(ActivityManagementActionTypes.ARCHIVE_ACTIVITY_FAIL);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ export class ActivityEffects {
);

@Effect()
deleteActivity$: Observable<Action> = this.actions$.pipe(
ofType(actions.ActivityManagementActionTypes.DELETE_ACTIVITY),
map((action: actions.DeleteActivity) => action.activityId),
mergeMap((activityId) =>
this.activityService.deleteActivity(activityId).pipe(
archiveActivity$: Observable<Action> = this.actions$.pipe(
ofType(actions.ActivityManagementActionTypes.ARCHIVE_ACTIVITY),
map((action: actions.ArchiveActivity) => ({
id: action.activityId,
status: 'inactive'
})),
mergeMap((activity: Status) =>
this.activityService.deleteActivity(activity.id).pipe(
map(() => {
this.toastrService.success(INFO_DELETE_SUCCESSFULLY);
return new actions.DeleteActivitySuccess(activityId);
return new actions.ArchiveActivitySuccess(activity);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
return of(new actions.DeleteActivityFail(error));
return of(new actions.ArchiveActivityFail(error));
})
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,29 @@ describe('activityManagementReducer', () => {
expect(state.isLoading).toEqual(false);
});

it('on DeleteActivity, isLoading is true', () => {
fit('on ArchiveActivity, isLoading is true', () => {
const activityToDeleteId = '1';
const action = new actions.DeleteActivity(activityToDeleteId);
const action = new actions.ArchiveActivity(activityToDeleteId);

const state = activityManagementReducer(initialState, action);
expect(state.isLoading).toEqual(true);
expect(state.isLoading).toBeTrue();
});

it('on DeleteActivitySuccess, message equal to Activity removed successfully!', () => {
const currentState: ActivityState = { data: [activity], isLoading: false, message: '', activityIdToEdit: '' };
const activityToDeleteId = '1';
const action = new actions.DeleteActivitySuccess(activityToDeleteId);

fit('on ArchiveActivitySuccess, message equal to Activity archived successfully!', () => {
const currentActivity = { ...activity };
currentActivity.status = 'active';
const currentState: ActivityState = { data: [currentActivity], isLoading: false, message: '', activityIdToEdit: '' };
const activityArchived: Status = { id: '1', status: 'inactive' };
const action = new actions.ArchiveActivitySuccess(activityArchived);
const state = activityManagementReducer(currentState, action);
expect(state.data).toEqual([]);
expect(state.message).toEqual('Activity removed successfully!');

expect(state.data).toEqual([activity]);
expect(state.message).toEqual('Activity archived successfully!');
});

it('on DeleteActivityFail, message equal to Something went wrong deleting activity!', () => {
it('on ArchiveActivityFail, message equal to Something went wrong deleting activity!', () => {
const activityToDeleteId = '1';
const action = new actions.DeleteActivityFail(activityToDeleteId);
const action = new actions.ArchiveActivityFail(activityToDeleteId);

const state = activityManagementReducer(initialState, action);
expect(state.isLoading).toEqual(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,28 @@ export function activityManagementReducer(state: ActivityState = initialState, a
};
}

case ActivityManagementActionTypes.DELETE_ACTIVITY: {
case ActivityManagementActionTypes.ARCHIVE_ACTIVITY: {
return {
...state,
isLoading: true,
message: 'Set activityIdToArchive property',
activityIdToEdit: action.activityId,
};
}

case ActivityManagementActionTypes.DELETE_ACTIVITY_SUCCESS: {
const activities = state.data.filter((activity) => activity.id !== action.activityId);
case ActivityManagementActionTypes.ARCHIVE_ACTIVITY_SUCCESS: {
const index = activityList.findIndex((activity) => activity.id === action.payload.id);
activityList[index] = { ...activityList[index], ...action.payload };

return {
...state,
data: activities,
data: activityList,
isLoading: false,
message: 'Activity removed successfully!',
message: 'Activity archived successfully!',
};
}

case ActivityManagementActionTypes.DELETE_ACTIVITY_FAIL: {
case ActivityManagementActionTypes.ARCHIVE_ACTIVITY_FAIL: {
return {
data: [],
isLoading: false,
Expand Down