From 1feb3884f23a893fa190db3e3446b8519f44c6c6 Mon Sep 17 00:00:00 2001 From: Diego Tinitana Date: Thu, 14 May 2020 16:31:38 -0500 Subject: [PATCH] fix: #227 Enhance entries modal fix --- .../details-fields.component.spec.ts | 21 ++++++++++++++++--- .../modules/time-clock/store/entry.effects.ts | 10 ++++----- .../modules/time-clock/store/entry.reducer.ts | 1 - .../pages/time-entries.component.html | 13 +----------- .../pages/time-entries.component.spec.ts | 6 ------ .../pages/time-entries.component.ts | 5 ----- 6 files changed, 23 insertions(+), 33 deletions(-) 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 1c99667bc..cd260e8b8 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 @@ -10,6 +10,7 @@ import * as actions from '../../store/technology.actions'; import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer'; import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors'; import { EntryState } from '../../../time-clock/store/entry.reducer'; +import * as entryActions from '../../../time-clock/store/entry.actions'; import { getUpdateError, getCreateError } from 'src/app/modules/time-clock/store/entry.selectors'; describe('DetailsFieldsComponent', () => { @@ -116,7 +117,7 @@ describe('DetailsFieldsComponent', () => { it('should emit ngOnChange with new data', () => { const entryToEdit = { - project_id: 'id', + project_id: 'abc', activity_id: '', uri: 'ticketUri', start_date: null, @@ -124,7 +125,7 @@ describe('DetailsFieldsComponent', () => { description: '', }; const formValue = { - project: 'name', + project: '', activity: '', uri: 'ticketUri', start_date: '', @@ -149,7 +150,7 @@ describe('DetailsFieldsComponent', () => { start_hour: '00:00', end_hour: '00:00', description: '', - technology: '' + technology: '', }; component.entryToEdit = null; component.ngOnChanges(); @@ -220,6 +221,20 @@ describe('DetailsFieldsComponent', () => { expect(component.selectedTechnology.length).toBe(1); }); + it('should call createError ', () => { + mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false); + spyOn(store, 'dispatch'); + component.ngOnInit(); + expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryCreateError(null)); + }); + + it('should call updateError ', () => { + mockEntriesUpdateErrorSelector = store.overrideSelector(getUpdateError, false); + spyOn(store, 'dispatch'); + component.ngOnInit(); + expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryUpdateError(null)); + }); + it('should emit saveEntry event', () => { spyOn(component.saveEntry, 'emit'); component.onSubmit(); diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index c08b2edbd..0cd82e565 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -62,8 +62,7 @@ export class EntryEffects { return new actions.CreateEntrySuccess(entryData); }), catchError((error) => { - console.error(error); - this.toastrService.success(UNEXPECTED_ERROR); + this.toastrService.error(UNEXPECTED_ERROR); return of(new actions.CreateEntryFail(error.error.message)); }) ) @@ -81,8 +80,7 @@ export class EntryEffects { return new actions.DeleteEntrySuccess(entryId); }), catchError((error) => { - console.log(error); - this.toastrService.success(UNEXPECTED_ERROR); + this.toastrService.error(UNEXPECTED_ERROR); return of(new actions.DeleteEntryFail(error)); }) ) @@ -96,11 +94,11 @@ export class EntryEffects { mergeMap((project) => this.entryService.updateActiveEntry(project).pipe( map((projectData) => { + this.toastrService.success(INFO_DELETE_SUCCESSFULLY); return new actions.UpdateActiveEntrySuccess(projectData); }), catchError((error) => { - console.log(error); - this.toastrService.success(UNEXPECTED_ERROR); + this.toastrService.error(UNEXPECTED_ERROR); return of(new actions.UpdateActiveEntryFail(error)); }) ) diff --git a/src/app/modules/time-clock/store/entry.reducer.ts b/src/app/modules/time-clock/store/entry.reducer.ts index b17ab89f7..46a4224d5 100644 --- a/src/app/modules/time-clock/store/entry.reducer.ts +++ b/src/app/modules/time-clock/store/entry.reducer.ts @@ -133,7 +133,6 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi case EntryActionTypes.DELETE_ENTRY_FAIL: { return { ...state, - entryList: [], isLoading: false, message: 'Something went wrong deleting entry!', }; diff --git a/src/app/modules/time-entries/pages/time-entries.component.html b/src/app/modules/time-entries/pages/time-entries.component.html index e36952444..8997d5581 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.html +++ b/src/app/modules/time-entries/pages/time-entries.component.html @@ -46,7 +46,7 @@ class="btn btn-sm btn-secondary ml-2" data-toggle="modal" data-target="#deleteModal" - (click)="openModal(entry)" + (click)="removeEntry(entry.id)" > @@ -73,14 +73,3 @@