Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
fix: #227 Enhance entries modal fix
  • Loading branch information
DiegoTinitana committed May 15, 2020
commit 1feb3884f23a893fa190db3e3446b8519f44c6c6
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -116,15 +117,15 @@ describe('DetailsFieldsComponent', () => {

it('should emit ngOnChange with new data', () => {
const entryToEdit = {
project_id: 'id',
project_id: 'abc',
activity_id: '',
uri: 'ticketUri',
start_date: null,
end_date: null,
description: '',
};
const formValue = {
project: 'name',
project: '',
activity: '',
uri: 'ticketUri',
start_date: '',
Expand All @@ -149,7 +150,7 @@ describe('DetailsFieldsComponent', () => {
start_hour: '00:00',
end_hour: '00:00',
description: '',
technology: ''
technology: '',
};
component.entryToEdit = null;
component.ngOnChanges();
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 4 additions & 6 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
)
Expand All @@ -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));
})
)
Expand All @@ -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));
})
)
Expand Down
1 change: 0 additions & 1 deletion src/app/modules/time-clock/store/entry.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
};
Expand Down
13 changes: 1 addition & 12 deletions src/app/modules/time-entries/pages/time-entries.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
>
<i class="fa fa-trash fa-xs"></i>
</button>
Expand All @@ -73,14 +73,3 @@ <h5 class="modal-title" id="exampleModalLongTitle">{{entryId ? "Edit Entry": "Ne
</div>
</div>
</div>
<app-modal
*ngIf="showModal"
class="modal fade"
id="deleteModal"
tabindex="-1"
role="dialog"
aria-hidden="true"
[list]="entryToDelete"
(removeList)="removeEntry($event)"
>
</app-modal>
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ describe('TimeEntriesComponent', () => {
expect(component.dataByMonth.length).toEqual(0);
}));

it('should open Delete Modal', () => {
component.openModal(entry);
expect(component.entryToDelete).toBe(entry);
expect(component.showModal).toBe(true);
});

it('should set entry and entryid to null', () => {
component.newEntry();
expect(component.entry).toBe(null);
Expand Down
5 changes: 0 additions & 5 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export class TimeEntriesComponent implements OnInit {
});
}

openModal(itemToDelete: Entry) {
this.entryToDelete = itemToDelete;
this.showModal = true;
}

newEntry() {
this.entry = null;
this.entryId = null;
Expand Down